- 积分
- 1905
- 明经币
- 个
- 注册时间
- 2022-4-4
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 枫叶棋语 于 2023-10-27 21:33 编辑
- from pycad.system import *
- from pycad.runtime import *
- class PyAtt:
- def __init__(self, blockref: BlockReference):
- self.blockref = blockref
- self.Position = self.blockref.Position
- self.InitAtt()
- def InitAtt(self):
- attids = self.blockref.AttributeCollection
- for attid in attids:
- attblockref: AttributeReference = attid.GetObject(OpenMode.ForWrite)
- setattr(self, attblockref.Tag, attblockref)
- def SetAtt(self, name, value):
- getattr(self, name).TextString = value
- def GetAtt(self, name):
- return getattr(self, name).TextString
- @Command()
- def tspyatt(doc: Document):
- '''对块进行X排序,并修改属性'''
- res = ssget(":A", TV(0, "Insert"))
- if not res.ok:
- return
- ids = tuple(res)
- i = 1
- with dbtrans(doc) as tr:
- pyatts: List[PyAtt] = [PyAtt(objid.GetObject(OpenMode.ForRead)) for objid in ids]
- pyatts.sort(key=lambda x: x.Position.X, reverse=False)
- for pyatt in pyatts:
- prinf(pyatt.GetAtt("编号"))
- pyatt.SetAtt("编号", f"num{i}")
- i += 1
复制代码
|
|