![]() |
【转帖】块属性提取问题
块属性提取问题
www.dimcax.com 块属性提取问题 第一次学vb.net,照autodesk的官方教材做的图框属性提限,可是出问题了,请各位帮我看看是什么原因。谢谢。代码如下 '以下是获得图形中属性块的值并输出到ptable的示例 <commandmethod("tzml")> _ public sub tzml() '设置过滤条件为图层tk上的所有属性块 dim fillist() as typedvalue = {new typedvalue(dxfcode.start, "insert"), new typedvalue(dxfcode.layername, "tk")} dim filter as selectionfilter = new selectionfilter(fillist) dim seloption as new promptselectionoptions() seloption.messageforadding = "请选择图框:" seloption.allowduplicates = false dim blkres as promptselectionresult = ed.getselection(seloption, filter) ed.writemessage("共选择块:" & blkres.value.count.tostring()) 'createtable() '绘制表格 if not blkres.status = promptstatus.ok then return '如果选择失败则返回nothing '将选择的值放入选择集blkss中 dim blkss as autodesk.autocad.editorinput.selectionset = blkres.value dim blkobjectid as objectid() = blkss.getobjectids() 'dim blknoid as objectid dim i as integer = 0, j as integer = 0 'for each blknoid in blkobjectid for i = 0 to ubound(blkobjectid) try dim blkrefs as blockreference = ctype(trans.getobject(blkobjectid(i), openmode.forread), blockreference) '打开当前对象,运行到这一行出错!!!!!! dim blkrefcollection as attributecollection = blkrefs.attributecollection() if blkrefcollection.count > 0 then 'for each attid in blkrefcollection for j = 0 to blkrefcollection.count dim attid as objectid = blkrefcollection(i) dim blkref as attributereference = trans.getobject(attid, openmode.forread, false) ed.writemessage(vbcrlf + blkref.textstring + vbcrlf) next end if catch ex as system.exception msgbox(ex.stacktrace) end try next ' end if 'next trans.commit() trans.dispose() end sub end class 已自己解决 经过几个小时摸索,自己解决了 朋友,能发我一份吗?我的邮箱是,非常感谢!!! 建议楼主分享. 模具相关绿色软件 皆唯网 其实也没做什么改动,就调试过了,奇怪 public sub tzml() '设置过滤条件为图层tk上的所有属性块 dim trans as transaction = db.transactionmanager.starttransaction() dim fillist() as typedvalue = {new typedvalue(dxfcode.start, "insert"), new typedvalue(dxfcode.layername, "tk")} dim filter as selectionfilter = new selectionfilter(fillist) dim seloption as new promptselectionoptions() seloption.messageforadding = "请选择图框:" seloption.allowduplicates = false dim blkres as promptselectionresult = ed.getselection(seloption, filter) if not blkres.status = promptstatus.ok then return '如果选择失败则返回nothing '将选择的值放入选择集blkss中 dim blkss as autodesk.autocad.editorinput.selectionset = blkres.value dim blkobjectid as objectid() = blkss.getobjectids() 'dim blknoid as objectid dim i as integer = 0, j as integer = 0 try for i = 0 to ubound(blkobjectid) dim blkent as entity = trans.getobject(blkobjectid(i), openmode.forwrite, true) '打开当前对象 if typeof blkent is blockreference then dim blkrefs as blockreference = ctype(blkent, blockreference) 'blkrefs为块参照 dim blkrefcollection as attributecollection = blkrefs.attributecollection() if blkrefcollection.count > 0 then for j = 0 to blkrefcollection.count - 1 dim blkref as attributereference = trans.getobject(blkrefcollection(j), openmode.forread, false) if blkref.tag.tostring = "图名" then papername = blkref.textstring.tostring elseif blkref.tag.tostring = "图号" then paperno = blkref.textstring.tostring end if next 'j end if if blkrefs.isdynamicblock = true then dim blkdyrefcollection as dynamicblockreferencepropertycollection = blkrefs.dynamicblockreferencepropertycollection() if blkdyrefcollection.count > 0 then for each blkdyrefpro as dynamicblockreferenceproperty in blkdyrefcollection if blkdyrefpro.propertyname = "查寻" then papersize = blkdyrefpro.value.tostring end if next 'j end if end if end if me.datagrid1.rows.add(new string() {papername, paperno, papersize}) next 'i catch ex as system.exception msgbox(ex.stacktrace) end try trans.commit() trans.dispose() me.show() end sub |
| 所有的时间均为北京时间。 现在的时间是 12:51 AM. |