autolisp提取心房
我需要多次提取某些块的属性,以便比较结果。因此,非常希望有人帮助我使用autolisp例程,该例程可以从以“通配符”开头的块中请求属性,并将信息提取到具有序列名称的excel文件中提前感谢
S 如果您安装了Express Tools,则有一个从块中提取属性的ATTOUT,不确定这是否对您有用 以下代码应该可以帮助您开始
(vl load com)(defun c:ccc(/blockFound block blockRecord atts getAtts name validCollection attList i)(while(=blockFound nil)(setq block(entsel“\n选择一个attibute块的实例:”)(if(=block nil)(princ“\n未选择实体”)(progn(setq block(vlax ename->vla object(car block))(if(eq(vlax get property block’objectName)“AcDbBlockReference”)(if(=(vla get hasaattributes block):vlax true)(setq blockFound t)(princ“\n所选块不包含属性”)(princ“\n所选实体不是块引用”))(setq blockRecord(getBlockTableRecord(vlax get property block'Name))(setq atts(getAttNames blockRecord))(listtributes(vlax get property blockRecord'Name)atts)(while(=validCollection nil)(setq name(getstring“\n输入要添加到集合的属性名称或留空以继续:”)(cond((eq name“”)(if(/=getAtts nil)(setq validCollection t)(princ“\n至少必须将一个属性添加到集合列表:”)((isInList atts name)(if(=(isInList getAtts name)nil)(setq getAtts(append getAtts(list name))))(princ“\n属性已在集合列表中”))((princ“\n添加了无效的属性名称”)))(setq sset(ssget“X”(list(cons 0“INSERT”)(cons 2(vlax get property blockRecord‘name kа))(setq i-1)(while(vla object(ssname sset i))getAtts)))(princ attList))(defun getBlockTableRecord(name/bl c)(vlax for c(vla get blocks(vla get activedocument)(vlax get acad object))(if(eq(vla get name c)name)(setq bl c))(bl)(defun getAttNames(blockRecord/c name)(vlax for c blockRecord(if(eq(vlax get property c’objectName)“acdbattributefinition”)(setq names(append names(list(vlax get property c’tagString))))name)(defun getAttValues(ent atts/i return attList)(setq attList(vlax safearray->list)(vlax variant value(vla getattributes ent))(foreach c atts(setq i-1)(while(<(setq i(1+i))(length attList))(if(eq(strcase(vla get tagString(nth i attList)))(strcase c))(setq return(append return(list(vla get textring(nth i attList)k)))))return)(defun listtributes(blockName atts/c)(princ(strcat“\n block name:”blockName))(princ“\n属性:”)(foreach c atts(princ(strcat“\n”c)))(defun isInList(lst item/i return)(setq i-1)(而( Right在当天早些时候与excel进行了一场较量。
(vl load com)(defun c:ccc(/blockFound block blockRecord atts getAtts name validCollection attList i)(while(=blockFound nil)(setq block(entsel“\n选择一个attibute块的实例:”)(if(=block nil)(princ“\n未选择实体”)(progn(setq block(vlax ename->vla object(car block)))(if(eq(vlax get property block'objectName)“AcDbBlockReference”)(if(=(vla get hasaattributes block):vlax true)(setq blockFound t)(princ“\n所选块不包含属性”)(princ“\n所选实体不是块引用”))(setq blockRecord(getBlockTableRecord(vlax get property block'Name))(setq atts(getAttNames blockRecord))(listtributes(vlax get property blockRecord'Name)atts)(while(=validCollection nil)(setq name(getstring“\n输入要添加到集合的属性名称或留空以继续:”)(cond((eq name“”)(if(/=getAtts nil)(setq validCollection t)(princ“\n至少必须将一个属性添加到集合列表:”)((isInList atts name)(if(=(isInList getAtts name)nil)(setq getAtts(append getAtts(list name))))(princ“\n属性已在集合列表中”))((princ“\n添加了无效的属性名称”)))(setq sset(ssget“X”(list(cons 0“INSERT”)(cons 2(vlax get property blockRecord'name凖凖))(setq i-1)(while(vla object(ssname sset i))getAtts)))(toExcel atts attList))(defun getBlockTableRecord(name/bl c)(vlax for c(vla get blocks(vla get activedocument))(vlax get acad object))(if(eq(vla get name c)name)(setq bl c))(bl)(defun getAttNames(blockRecord/c name)(vlax for c blockRecord(if(eq(vlax get property c’objectName)“acdbattributefinition”)(setq names(append names(list(vlax get property c’tagString))))name)(defun getAttValues(ent atts/i return attList)(setq attList(vlax safearray->list)(vlax variant value(vla getattributes ent))(foreach c atts(setq i-1)(while(<(setq i(1+i))(length attList))(if(eq(strcase(vla get tagString(nth i attList)))(strcase c))(setq return(append return(list(vla get textring(nth i attList)k)))))return)(defun listtributes(blockName atts/c)(princ(strcat“\n block name:”blockName))(princ“\n属性:”)(foreach c atts(princ(strcat“\n”c)))(defun isInList(lst item/i return)(setq i-1)(而(
页:
[1]