- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2019-12-22 21:39:19
|
显示全部楼层
本帖最后由 雪山飞狐_lzh 于 2019-12-30 20:38 编辑
例程贴
1、hello world
- @command()
- def helloworld(doc):
- #显示hello world!
- print('hello world!')
- #打开事务
- with dbtrans(doc) as tr:
- #打开当前空间
- btr = tr.opencurrspace()
- #向当前空间添加直线
- tr.addentity(btr, acdb.Line(acge.Point3d(0,0,0), acge.Point3d(10,10,0)))
复制代码
2、模拟直线命令
- @command()
- def myline2(doc):
- #模拟直线命令
- with dbtrans(doc) as tr:
- btr = tr.opencurrspace()
- lines, pts = [], []
- while True:
- n = len(pts)
- if n == 0:
- #获取起点
- respt = edx.getpoint('\n指定第一个点:')
- if not respt.ok(): return
- pts.append(respt.value)
- else:
- if n > 2:
- opts = aced.PromptPointOptions(
- '\n指定下一点或[闭合(C)/放弃(U)]', 'C U')
- else:
- opts = aced.PromptPointOptions(
- '\n指定下一点或[放弃(U)]', 'U')
- #获取下一点
- opts.AllowNone = True
- opts.BasePoint = pts[-1]
- opts.UseBasePoint = True
- opts.UseDashedLine = False
- respt = edx.getpoint(opts)
- if respt.ok():
- #如果正确输入点就添加一条直线
- pt = respt.value
- if n > 0:
- line = acdb.Line(pts[-1], pt)
- tr.addentity(btr, line)
- tr.flush(line)
- lines.append(line)
- pts.append(pt)
- elif respt.keyword('C'):
- #如果输入关键字C则闭合并退出
- line = acdb.Line(pts[-1], pts[0])
- tr.addentity(btr, line)
- break
- elif respt.keyword('U'):
- #如果输入关键字U则回退
- del pts[-1]
- if n > 1:
- lines[-1].Erase()
- tr.flush(line)
- del lines[-1]
- else: break
复制代码
3、linq去重,留下同心圆中直径最小的
- @command(flags=acrx.CommandFlags.UsePickSet)
- def linqtest(doc):
- #linq去重,留下同心圆中直径最小的
- #选择圆
- ss = edx.ssget(filters=(0, "circle"))
- if not ss.ok(): return
- with dbtrans(doc) as tr:
- #流程:按圆心分组->每组排序后->跳过第一个元素
- cirs = \
- ss.Cast[acdb.ObjectId]()\
- .Select(lambda i: tr.getobject(i))\
- .GroupBy(lambda c: c.Center)\
- .SelectMany(lambda cs: cs.OrderBy(lambda c: c.Radius).Skip(1))
- tr.erase(*cirs)
复制代码
4、获取曲线自交点
- @command()
- def ccitest2(doc):
- #获取曲线自交点
- #获取曲线
- opts = aced.PromptEntityOptions('\n请选择曲线:')
- opts.SetRejectMessage('错误类型!')
- opts.AddAllowedClass(acdb.Curve, False)
- res = edx.entsel(opts)
- if not res.ok(): return
- with dbtrans(doc) as tr:
- pl = tr.getobject(res[0]) #type: acdb.Curve
- curve3d = pl.GetGeCurve()
- #用cci类判断自相交
- cci = acge.CurveCurveIntersector3d(curve3d, curve3d, acge.Vector3d.ZAxis)
- for k in range(cci.NumberOfIntersectionPoints):
- #显示自相交点
- pars = cci.GetIntersectionParameters(k)
- print(curve3d.EvaluatePoint(pars[0]))
复制代码
5、两曲线间最短距离
- @command()
- def mindict(doc):
- #两曲线间最短距离
- #获取曲线
- opts = aced.PromptEntityOptions('\n请选择曲线:')
- opts.SetRejectMessage('错误类型!')
- opts.AddAllowedClass(acdb.Curve, False)
- res = edx.entsel(opts)
- if not res.ok(): return
- res2 = edx.entsel(opts)
- if not res2.ok(): return
- with dbtrans(doc) as tr:
- curves = (tr.getobject(res.ObjectId).GetGeCurve(), tr.getobject(res2.ObjectId).GetGeCurve())
- pocs = curves[0].GetClosestPointTo(curves[1])
- line = acdb.Line(pocs[0].Point, pocs[1].Point)
- tr.addentity(tr.opencurrspace(), line)
复制代码 |
|