检索PropertyDe中的值
你好我正在使用扩展特性集定义从DWG中提取信息。
我已经在我的门对象上添加了位置属性,并希望在我的应用程序中检索它。
定义如AutoCAD>管理>样式管理器>特性集定义中所示
DoorObjects属性集
名称:AtSpaceID
描述:Space-SpaceObjects-SpaceID
类型:位置(在.NET API代码内自动变为)
来源:Space-SpaceObjects-SpaceID
空间对象特性集
名称:SpaceID
描述:SpaceID
类型:整数
我已经试过了。NET API。请参阅下面的代码。我被困在PropertyDefinitionLocation。我不太确定在哪里可以在我的DoorObjects上检索我的AtSpaceID的值。
有人有这样做的经验吗?请给出建议。谢谢
我尝试了下面的代码,它抛出了错误,例如eInvalidInput或eNotApplicable。
我代码的一部分
Door doorEntity = trans.GetObject(doorObjID, OpenMode.ForRead) as Door;
ObjectIdCollection idsPropSet = PropertyDataServices.GetPropertySets(doorEntity);
foreach (ObjectId idPropSet in idsPropSet)
{
PropertySet propSet = trans.GetObject(idPropSet, OpenMode.ForRead) as PropertySet;
PropertySetDefinition propSetDef = trans.GetObject(propSet.PropertySetDefinition, OpenMode.ForRead) as PropertySetDefinition;
PropertyDefinitionCollcetion propDefs = propSetDef.Definitions;
foreach (PropertyDefinition propDef in propDefs)
{
if(propDef.Automatic) //the Space
{
ObjectIdCollection idsDummy = new ObjectIdCollection();
if (propDef.GetType().ToString().Equals("Autodesk.Aec.PropertyData.DatabaseServices.PropertyDefinitionLocation"))
{
PropertyDefinitionLocation propDefLoc = propDef as PropertyDefinitionLocation;
//this give me eInvalidInput error
MessageBox.Show(propSetDef.GetValue(propDefLoc.Id, doorObjId, idsDummy).ToString());
//give me Automatic Property -- not applicable in this context
MessageBox.Show(propDefLoc.FormatId, idsDummy).ToString());
}
}
}
} 零钱
Door doorEntity = tr.GetObject(id, OpenMode.ForRead) as Door;
ObjectIdCollection idsPropSet = PropertyDataServices.GetPropertySets(doorEntity);
foreach (ObjectId idPropSet in idsPropSet)
{
PropertySet propSet = tr.GetObject(idPropSet, OpenMode.ForRead) as PropertySet;
PropertySetDefinition propSetDef = tr.GetObject(propSet.PropertySetDefinition, OpenMode.ForRead) as PropertySetDefinition;
PropertyDefinitionCollection propDefs = propSetDef.Definitions;
foreach (PropertyDefinition propDef in propDefs)
{
if (propDef is PropertyDefinitionLocation) //the Space
{
ObjectIdCollection idsDummy = new ObjectIdCollection();
{
//this does NOT give me eInvalidInput error
MessageBox.Show(propSetDef.GetValue(propDef.Id, id, idsDummy).ToString());
}
}
}
}
嗨,杰夫,
谢谢你的回复。想与您确认一下您使用的是哪个版本的AutoCAD?
您是否下载了AutoCAD并为其添加了更新?
我不太确定我是否理解你的问题,但我确实知道我使用的是什么版本。 也许我应该重新表述我的问题。
从您的配置文件中可以看出,您正在使用AutoCAD MEP 2011?
您是否使用AutoCAD网站上的补丁更新了AutoCAD?
我已经试过了你写的代码,但我仍然面临同样的eInvalidInput问题。
我完全不知道为什么我无法检索位置属性值。 使用Architecture 2012进行了测试,没有出现任何错误
static public void NoError()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
using (Transaction trx = db.TransactionManager.StartTransaction())
{
BlockTable bt = trx.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = trx.GetObject(bt, OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId id in btr)
{
if (!(id.ObjectClass.Name == "AecDbDoor"))
{
continue;
}
Door doorEntity = trx.GetObject(id, OpenMode.ForRead) as Door;
ObjectIdCollection idsPropSet = PropertyDataServices.GetPropertySets(doorEntity);
foreach (ObjectId idPropSet in idsPropSet)
{
PropertySet propSet = trx.GetObject(idPropSet, OpenMode.ForRead) as PropertySet;
PropertySetDefinition propSetDef = trx.GetObject(propSet.PropertySetDefinition, OpenMode.ForRead) as PropertySetDefinition;
PropertyDefinitionCollection propDefs = propSetDef.Definitions;
foreach (PropertyDefinition propDef in propDefs)
{
if (propDef is PropertyDefinitionLocation) //the Space
{
ObjectIdCollection idsDummy = new ObjectIdCollection();
{
//this does NOT give me eInvalidInput error
ed.WriteMessage("\n" + propSetDef.GetValue(propDef.Id, id, idsDummy).ToString());
}
}
}
}
}
trx.Commit();
}
}
页:
[1]