属性块属性读写
本帖最后由 枫叶棋语 于 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 =
pyatts.sort(key=lambda x: x.Position.X, reverse=False)
for pyatt in pyatts:
prinf(pyatt.GetAtt("编号"))
pyatt.SetAtt("编号", f"num{i}")
i += 1
我枫哥如此强大:lol 必须点赞 感谢楼主的开源精神 感谢分享,但不知道怎么用(`)**
感谢分享,但不知道怎么用(`)**
页:
[1]