乐筑天下

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

[编程交流] 检索PropertyDe中的值

[复制链接]

5

主题

11

帖子

6

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-6 22:41:40 | 显示全部楼层 |阅读模式
你好
 
我正在使用扩展特性集定义从DWG中提取信息。
 
我已经在我的门对象上添加了位置属性,并希望在我的应用程序中检索它。
 
定义如AutoCAD>管理>样式管理器>特性集定义中所示
DoorObjects属性集
名称:AtSpaceID
描述:Space-SpaceObjects-SpaceID
类型:位置(在.NET API代码内自动变为)
来源:Space-SpaceObjects-SpaceID
 
空间对象特性集
名称:SpaceID
描述:SpaceID
类型:整数
 
我已经试过了。NET API。请参阅下面的代码。我被困在PropertyDefinitionLocation。我不太确定在哪里可以在我的DoorObjects上检索我的AtSpaceID的值。
 
有人有这样做的经验吗?请给出建议。谢谢
 
我尝试了下面的代码,它抛出了错误,例如eInvalidInput或eNotApplicable。
 
我代码的一部分
  1. Door doorEntity = trans.GetObject(doorObjID, OpenMode.ForRead) as Door;
  2. ObjectIdCollection idsPropSet = PropertyDataServices.GetPropertySets(doorEntity);
  3. foreach (ObjectId idPropSet in idsPropSet)
  4. {
  5.    PropertySet propSet = trans.GetObject(idPropSet, OpenMode.ForRead) as PropertySet;
  6.    PropertySetDefinition propSetDef = trans.GetObject(propSet.PropertySetDefinition, OpenMode.ForRead) as PropertySetDefinition;
  7.    PropertyDefinitionCollcetion propDefs = propSetDef.Definitions;
  8.    foreach (PropertyDefinition propDef in propDefs)
  9.    {
  10.        if(propDef.Automatic)   //the Space
  11.        {
  12.            ObjectIdCollection idsDummy = new ObjectIdCollection();
  13.            if     (propDef.GetType().ToString().Equals("Autodesk.Aec.PropertyData.DatabaseServices.PropertyDefinitionLocation"))
  14.            {
  15.                PropertyDefinitionLocation propDefLoc = propDef as PropertyDefinitionLocation;
  16.                //this give me eInvalidInput error
  17.                MessageBox.Show(propSetDef.GetValue(propDefLoc.Id, doorObjId, idsDummy).ToString());
  18.                //give me Automatic Property -- not applicable in this context
  19.                MessageBox.Show(propDefLoc.FormatId, idsDummy).ToString());
  20.            }
  21.        }
  22.    }
  23. }
回复

使用道具 举报

0

主题

101

帖子

103

银币

限制会员

铜币
-2
发表于 2022-7-6 23:00:19 | 显示全部楼层
零钱
 
  1.                        Door doorEntity = tr.GetObject(id, OpenMode.ForRead) as Door;
  2.                        ObjectIdCollection idsPropSet = PropertyDataServices.GetPropertySets(doorEntity);
  3.                        foreach (ObjectId idPropSet in idsPropSet)
  4.                        {
  5.                            PropertySet propSet = tr.GetObject(idPropSet, OpenMode.ForRead) as PropertySet;
  6.                            PropertySetDefinition propSetDef = tr.GetObject(propSet.PropertySetDefinition, OpenMode.ForRead) as PropertySetDefinition;
  7.                            PropertyDefinitionCollection propDefs = propSetDef.Definitions;
  8.                            foreach (PropertyDefinition propDef in propDefs)
  9.                            {
  10.                                if (propDef is PropertyDefinitionLocation)   //the Space
  11.                                {
  12.                                    ObjectIdCollection idsDummy = new ObjectIdCollection();
  13.                                    {
  14.                                        //this does NOT give me eInvalidInput error
  15.                                        MessageBox.Show(propSetDef.GetValue(propDef.Id, id, idsDummy).ToString());
  16.                                    }
  17.                                }
  18.                            }
  19.                        }
回复

使用道具 举报

5

主题

11

帖子

6

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-6 23:12:53 | 显示全部楼层
嗨,杰夫,
谢谢你的回复。想与您确认一下您使用的是哪个版本的AutoCAD?
您是否下载了AutoCAD并为其添加了更新?
回复

使用道具 举报

0

主题

101

帖子

103

银币

限制会员

铜币
-2
发表于 2022-7-6 23:22:13 | 显示全部楼层
 
我不太确定我是否理解你的问题,但我确实知道我使用的是什么版本。
回复

使用道具 举报

5

主题

11

帖子

6

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-6 23:33:38 | 显示全部楼层
也许我应该重新表述我的问题。
 
从您的配置文件中可以看出,您正在使用AutoCAD MEP 2011?
您是否使用AutoCAD网站上的补丁更新了AutoCAD?
 
我已经试过了你写的代码,但我仍然面临同样的eInvalidInput问题。
我完全不知道为什么我无法检索位置属性值。
回复

使用道具 举报

0

主题

101

帖子

103

银币

限制会员

铜币
-2
发表于 2022-7-6 23:49:25 | 显示全部楼层
使用Architecture 2012进行了测试,没有出现任何错误
 
  1. [CommandMethod("NoError")]
  2.       static public void NoError()
  3.       {
  4.           Database db = HostApplicationServices.WorkingDatabase;
  5.           Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
  6.           using (Transaction trx = db.TransactionManager.StartTransaction())
  7.           {
  8.          
  9.               BlockTable bt = trx.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  10.               BlockTableRecord btr = trx.GetObject(bt[blockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;
  11.               foreach (ObjectId id in btr)
  12.               {
  13.                   if (!(id.ObjectClass.Name == "AecDbDoor"))
  14.                   {
  15.                       continue;
  16.                   }
  17.                   Door doorEntity = trx.GetObject(id, OpenMode.ForRead) as Door;
  18.                   ObjectIdCollection idsPropSet = PropertyDataServices.GetPropertySets(doorEntity);
  19.                   foreach (ObjectId idPropSet in idsPropSet)
  20.                   {
  21.                       PropertySet propSet = trx.GetObject(idPropSet, OpenMode.ForRead) as PropertySet;
  22.                       PropertySetDefinition propSetDef = trx.GetObject(propSet.PropertySetDefinition, OpenMode.ForRead) as PropertySetDefinition;
  23.                       PropertyDefinitionCollection propDefs = propSetDef.Definitions;
  24.                       foreach (PropertyDefinition propDef in propDefs)
  25.                       {
  26.                           if (propDef is PropertyDefinitionLocation)   //the Space
  27.                           {
  28.                               ObjectIdCollection idsDummy = new ObjectIdCollection();
  29.                               {
  30.                                   //this does NOT give me eInvalidInput error
  31.                                   ed.WriteMessage("\n" + propSetDef.GetValue(propDef.Id, id, idsDummy).ToString());
  32.                               }
  33.                           }
  34.                       }
  35.                   }
  36.               }
  37.               trx.Commit();
  38.           }
  39.       }
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 11:40 , Processed in 0.489701 second(s), 64 queries .

© 2020-2025 乐筑天下

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