明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 640|回复: 8

[【PyCAD】] PYCAD j直线JIG绘制,还请各位大神多多指教

[复制链接]
发表于 2023-2-1 21:28 | 显示全部楼层 |阅读模式
  1. # -*- coding: utf-8 -*
  2. from System import *
  3. from pycad.runtime import *
  4. from pycad.system import *
  5. from Autodesk.AutoCAD.DatabaseServices import *
  6. from Autodesk.AutoCAD.Geometry import *
  7. from Autodesk.AutoCAD.ApplicationServices import *
  8. from pycad.runtime.edx import *
  9. from Autodesk.AutoCAD.EditorInput import *

  10. class LineJig(DrawJig):
  11.     def __init__(self, basept = Point3d):
  12.         self.line = Line(basept, basept)
  13.         self.location = basept

  14.     def Sampler(self, prompts=JigPrompts):
  15.         opts = JigPromptPointOptions('\n请输入终点:')
  16.         opts.UserInputControls = (
  17.             UserInputControls().Accept3dCoordinates |
  18.             UserInputControls().NoZeroResponseAccepted |
  19.             UserInputControls().NoNegativeResponseAccepted)
  20.         res = prompts.AcquirePoint(opts)
  21.         if res.Value != self.location:
  22.             self.location = res.Value
  23.         else:
  24.             return aced.SamplerStatus.NoChange
  25.         if res.Status == aced.PromptStatus.Cancel:
  26.             return aced.SamplerStatus.Cancel
  27.         else:
  28.             return aced.SamplerStatus.OK

  29.     def WorldDraw(self, doc):
  30.         doc.Geometry.Draw(self.GetEntity())
  31.         return True

  32.     def Update(self):
  33.         self.line.EndPoint = self.location

  34.     def GetEntity(self):
  35.         self.Update()
  36.         return self.line


  37. @command()
  38. def TLineJig(doc):
  39.     with dbtrans(doc) as tr:
  40.         btr=tr.opencurrspace()
  41.         res = edx.getpoint("\n请输入起点:")
  42.         if not res.ok(): return
  43.         BasePt = res.value
  44.         jig = LineJig(BasePt)
  45.         res = doc.Editor.Drag(jig)
  46.         while (res.Status==PromptStatus().OK):
  47.             line=jig.GetEntity()
  48.             tr.addentity(btr,line)
  49.             tr.flush(line)
  50.             BasePt=jig.location
  51.             jig=LineJig(BasePt)
  52.             res = doc.Editor.Drag(jig)
  53.             if res.Status!=PromptStatus().OK:
  54.                 break
  55.         
复制代码


发表于 2023-2-1 21:59 | 显示全部楼层
好帖~python代码就是简洁清楚明白
发表于 2023-2-2 10:20 | 显示全部楼层
可以看看ifox的,封装一个通用的
发表于 2023-2-2 11:17 来自手机 | 显示全部楼层
本帖最后由 landsat99 于 2023-2-2 11:39 编辑

基于ironpython的应用不多见。必须大赞 刚看了下ironpython官网已兼容到cpy3.4的std。十年来的重大改进进,很香! 虽不是ironpy的技术栈,友情点赞必须[]
发表于 2023-2-2 12:05 来自手机 | 显示全部楼层
关羽封装接口设计, 楼主可参考acad官方的com,它是官方标准封装实例,最简洁。除非有特殊理由,和详尽说明文档,否则不要自设接口写法。应用成本高
发表于 2023-2-2 12:08 来自手机 | 显示全部楼层
关羽接口标准
发表于 2023-2-2 12:12 来自手机 | 显示全部楼层
楼主有意要做一套的话,这个进程内的.net库OK。也可同时封装成com格式的dll,方便进程外的标准调用
发表于 2023-2-2 13:35 | 显示全部楼层
学习学习,谢谢 大神分享
发表于 2023-2-2 17:24 | 显示全部楼层
学习学习,谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-1 06:48 , Processed in 4.612635 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表