Pycad 构建一个简易的PolylineJig
def AddPolyline(pts):polyline = Polyline()
polyline.SetDatabaseDefaults()
plane = Plane()
for index, pt in enumerate(pts):
polyline.AddVertexAt(index, pt.Convert2d(plane), 0, 0, 0)
return polyline
class PolylineJig(DrawJig):
def __init__(self, basept=None):
self.basept = basept
self.location = basept
self.pts =
def Sampler(self, prompts:JigPrompts):
opts = JigPromptPointOptions('\n请输入终点:')
opts.UserInputControls = (
UserInputControls.Accept3dCoordinates |
UserInputControls.NoZeroResponseAccepted |
UserInputControls.NoNegativeResponseAccepted)
res = prompts.AcquirePoint(opts)
if res.Value != self.location:
self.location = res.Value
else:
return SamplerStatus.NoChange
if res.Status == PromptStatus.Cancel:
return SamplerStatus.Cancel
else:
return SamplerStatus.OK
def Update(self):
self.pts[-1] = self.location
self.pline = AddPolyline(self.pts)
def GetEntity(self):
self.Update()
return self.pline
def WorldDraw(self, draw:WorldDraw):
draw.Geometry.Draw(self.GetEntity())
return True
@Command()
def ts01(doc: Document):
with dbtrans(doc) as tr:
ed = doc.Editor
btr = tr.opencurrspace()
res = getpoint()
if not res.ok:
return
basept = res.value
jig = PolylineJig(basept)
res = ed.Drag(jig)
while res.Status == PromptStatus.OK:
jig.pts.append(jig.location)
basept = jig.location
jig.basept = basept
res = ed.Drag(jig)
if res.Status != PromptStatus.OK:
if len(jig.pts) > 2:
jig.pts.pop()
pline = AddPolyline(jig.pts)
tr.addentity(btr, pline)
页:
[1]