使用SortedDictionary操作PropertySet的AutoIncrementDataType的基本示例。
在windows窗体对话框中:
帮助器方法:
- public static class GhAecPropertySetHelper
- {
- public static List GetPropertySetDefinitionNamesWithAutoIncrementDataType(Database db)
- {
- List lst = new List();
- ObjectId psdId = ObjectId.Null;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- DictionaryPropertySetDefinitions psdDict = new DictionaryPropertySetDefinitions(db);
- ObjectIdCollection psdIds = psdDict.Records;
- foreach (ObjectId id in psdIds)
- {
- PropertySetDefinition psdf = (PropertySetDefinition)tr.GetObject(id, OpenMode.ForRead, false, false);
- PropertyDefinitionCollection pdc = psdf.Definitions;
- foreach (PropertyDefinition pd in pdc)
- if (pd.DataType == Autodesk.Aec.PropertyData.DataType.AutoIncrement)
- {
- lst.Add(psdf.Name);
- break;
- }
- }
- tr.Commit();
- }
- return lst;
- }
- public static List GetAutoIncrementPropertyDefinitionNames(string propSetDefName, Database db)
- {
- List lst = new List();
- ObjectId psdId = ObjectId.Null;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- DictionaryPropertySetDefinitions psdDict = new DictionaryPropertySetDefinitions(db);
- if (psdDict.Has(propSetDefName, tr))
- {
- // Assign the return variable the ObjectId of the property set
- psdId = psdDict.GetAt(propSetDefName);
- PropertySetDefinition psdf = (PropertySetDefinition)tr.GetObject(psdId, OpenMode.ForRead, false, false);
- PropertyDefinitionCollection pdc = psdf.Definitions;
- foreach (PropertyDefinition pd in pdc)
- if (pd.DataType == Autodesk.Aec.PropertyData.DataType.AutoIncrement)
- lst.Add(pd.Name);
- }
- tr.Commit();
- }
- return lst;
- }
- public static bool SetValueFromPropertySetId(string propName, ObjectId propSetId, Object value, Database db)
- {
- bool findAny = false;
- int propSetDefId = 0;
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- try
- {
- PropertySet propSet = (PropertySet)trans.GetObject(propSetId, OpenMode.ForWrite, false, false);
- propSetDefId = propSet.PropertyNameToId(propName);
- if ((propSet.IsWriteEnabled))
- {
- propSet.SetAt(propSetDefId, value);
- findAny = true;
- }
- }
- catch (AcException)
- {
- // most likely eKeyNotFound.
- }
- trans.Commit();
- }
- return findAny;
- }
- public static ObjectId GetPropertySetDefinitionIdByName(string propSetDefName, Database db)
- {
- // Create objectId to hold the property set objectId and
- // set the default value equal to null.
- ObjectId psdId = ObjectId.Null;
- AcDb.TransactionManager tm = db.TransactionManager;
- using (Transaction trans = tm.StartTransaction())
- {
- // Create a Property Set Dictionary
- AecPropDb.DictionaryPropertySetDefinitions psdDict = new AecPropDb.DictionaryPropertySetDefinitions(db);
-
- // Check to see if the dictionary contains the name of the property set we are looking for
- if (psdDict.Has(propSetDefName, trans))
- {
- // Assign the return variable the ObjectId of the property set
- psdId = psdDict.GetAt(propSetDefName);
- } // End If Block
-
- trans.Commit();
- } // End Using Statement
-
- return psdId;
- }
- }
|