PYCAD j直线JIG绘制,还请各位大神多多指教
# -*- coding: utf-8 -*from System import *
from pycad.runtime import *
from pycad.system import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
from Autodesk.AutoCAD.ApplicationServices import *
from pycad.runtime.edx import *
from Autodesk.AutoCAD.EditorInput import *
class LineJig(DrawJig):
def __init__(self, basept = Point3d):
self.line = Line(basept, basept)
self.location = basept
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 aced.SamplerStatus.NoChange
if res.Status == aced.PromptStatus.Cancel:
return aced.SamplerStatus.Cancel
else:
return aced.SamplerStatus.OK
def WorldDraw(self, doc):
doc.Geometry.Draw(self.GetEntity())
return True
def Update(self):
self.line.EndPoint = self.location
def GetEntity(self):
self.Update()
return self.line
@command()
def TLineJig(doc):
with dbtrans(doc) as tr:
btr=tr.opencurrspace()
res = edx.getpoint("\n请输入起点:")
if not res.ok(): return
BasePt = res.value
jig = LineJig(BasePt)
res = doc.Editor.Drag(jig)
while (res.Status==PromptStatus().OK):
line=jig.GetEntity()
tr.addentity(btr,line)
tr.flush(line)
BasePt=jig.location
jig=LineJig(BasePt)
res = doc.Editor.Drag(jig)
if res.Status!=PromptStatus().OK:
break
好帖~python代码就是简洁清楚明白 可以看看ifox的,封装一个通用的 本帖最后由 landsat99 于 2023-2-2 11:39 编辑
基于ironpython的应用不多见。必须大赞 刚看了下ironpython官网已兼容到cpy3.4的std。十年来的重大改进进,很香! 虽不是ironpy的技术栈,友情点赞必须[] 关羽封装接口设计, 楼主可参考acad官方的com,它是官方标准封装实例,最简洁。除非有特殊理由,和详尽说明文档,否则不要自设接口写法。应用成本高 关羽接口标准 楼主有意要做一套的话,这个进程内的.net库OK。也可同时封装成com格式的dll,方便进程外的标准调用 学习学习,谢谢 大神分享 学习学习,谢谢
页:
[1]