cyfdean
发表于 2019-12-17 08:45:27
牛逼,非常牛逼。
594826903
发表于 2019-12-18 09:44:53
支持感谢!
mycad
发表于 2019-12-21 15:52:25
雪山飞狐_lzh
发表于 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)
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()\
.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)#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))
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.GetClosestPointTo(curves)
line = acdb.Line(pocs.Point, pocs.Point)
tr.addentity(tr.opencurrspace(), line)
pw_design
发表于 2019-12-22 22:34:18
这就厉害了,顶起来
雪山飞狐_lzh
发表于 2019-12-30 23:08:56
修正版本0.9.279.6d
短时间不会大版本更新了
等过年把调试器做完,准备升1.0:)
8142556
发表于 2020-1-5 13:35:04
怎么加载了NFox.Pycad.Acad.dll没有PYE命令,,
雪山飞狐_lzh
发表于 2020-1-6 00:37:05
cad版本多少?
pycad的两个版本都试过吗
Aries
发表于 2020-1-8 17:07:12
厉害了
jack093
发表于 2020-1-9 16:04:12
顶顶顶;
lisp调试太麻烦,不知道错误虫子在哪?
如果能用py代替lsp,真是大快人心,这样每周都可节省不少时间了!
谢谢版主
页:
1
2
3
4
5
[6]
7
8
9
10
11
12
13
14
15