几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » ObjectARX(VB.NET/C#)
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-04-20, 09:39 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】块属性提取问题

块属性提取问题
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
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 11:42 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多