乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 52|回复: 2

从块中获取属性的简单方法

[复制链接]

8

主题

15

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
51
发表于 2012-8-23 06:02:25 | 显示全部楼层 |阅读模式
我正在做我的第一个成年VB.net项目,它是一个vba脚本的重写,该脚本从块中收集某些属性值并将它们作为BOM制成表格。
我正在努力从块引用中获取属性值——我被一个问题弄得更复杂,虽然大多数属性是恒定的,但在某些情况下它们不是,所以我真的需要收集所有属性并按标签排序。
我的VBA方法使用了
BlockRef.Getattributes

BlockRef.GetConstantAttributes
方法,它将我需要的一切都放在数据结构中。
我的VB获取属性的方法因是否满足要求而异:对于非恒定属性,我使用
blockref.AttributeCollection
语句,然后给我一个包含属性的结构,非常像VBA
但是对于常量属性,我目前必须转到块定义,并遍历内容,隔离属性定义并检查常量属性是否为真
这是两种非常不同的方法,并且有点让我的编程魔力感到不安-有一种技术可以用于两种类型的属性吗?
任何想法、提示或代码片段都将不胜感激...
G

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

24

主题

204

帖子

6

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
300
发表于 2012-8-23 07:54:46 | 显示全部楼层
blockref。AttributeCollection将返回与BlockReference关联的所有AttributeReferences,包括任何标记为常量的。
回复

使用道具 举报

116

主题

996

帖子

9

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1466
发表于 2012-8-23 08:06:52 | 显示全部楼层
对不起,我不会说VB     。
使用系统;。
使用系统,集合,泛型;。
使用系统,Linq。
使用系统,文本;。
使用Autodesk,AutoCAD . Runtime。

命名空间Autodesk,AutoCAD.DatabaseServices。
{。
公共静态类AcDbExtensionMethods。
{。
静态RXClass attDefClass = RXClass,GetClass(type of(attribute definition));。

//要求调用时事务(不是OpenCloseTransaction)处于活动状态:。
//返回常量属性为的所有AttributeDefinitions的枚举。
// true,以及附着到块引用的所有AttributeReferences。。

公共静态IEnumerable  get attributes(this block reference block ref)。
{。
事务tr = blockRef,get transaction();。
block table record btr =(block table record)block ref,DynamicBlockTableRecord . GetObject(OpenMode,for read);。
if( btr,HasAttributeDefinitions )。
{。
foreach(block ref中的ObjectId id,AttributeCollection )。
{。
收益率(AttributeReference) tr,GetObject( id,OpenMode。for read);。
}。
foreach(btr中的ObjectId id)。
{。
如果(id,ObjectClass == attDefClass )。
{。
attribute definition attdef =(attribute definition)trGetObject( id,OpenMode。for read);。
if( attdef,常数)。
yield返回attdef。
}。
}。
}。
}。

//需要活动事务(不是OpenCloseTransaction)。
//返回一个字典,其值为常量AttributeDefinitions。
//或AttributeReferences,键入它们的标记:。

公共静态字典 GetAttributeDictionary(this block reference block ref)。
{。
返回blockref,GetAttributes(),ToDictionary( a => GetTag( a),StringComparer。普通案件);。
}。

公共静态事务GetTransaction(此DBObject obj )。
{。
if( obj,Database == null )。
抛出新的ArgumentException("无数据库");。
事务tr = obj,database . transaction manager . top transaction;。
if( tr == null )。
抛出新的InvalidOperationException("无活动事务");。
返回tr;。
}。

静态字符串GetTag( DBText dbtext )。
{。
attribute definition attdef = db text as attribute definition;。
if( attdef!= null )。
返回属性,标签;。
attribute reference attref = db text as attribute reference;。
if( attref!= null )。
返回attref,标签;。
throw new ArgumentException("需要AttributeDefintion或attribute reference ");。
}。
}。
}。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-5 10:52 , Processed in 0.147207 second(s), 58 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表