AutoCAD .NET API: Can I add Automatic property definition to propertysetDefinition?

AutoCAD .NET API: Can I add Automatic property definition to propertysetDefinition?

ebi1007
Enthusiast Enthusiast
815 Views
4 Replies
Message 1 of 5

AutoCAD .NET API: Can I add Automatic property definition to propertysetDefinition?

ebi1007
Enthusiast
Enthusiast

I would like to add automatic property definitions. When I tried the code I found on the net, there is no error, but the property set definition is not created. If you have any other valid codes, please let me know.

 

...
var autoPropDef = new PropertyDefinition();
autoPropDef.SetToStandard(database);
autoPropDef.SubSetDatabaseDefaults(database);
autoPropDef.Name = "オブジェクトID";
autoPropDef.IsVisible = true;
autoPropDef.IsReadOnly = true;
autoPropDef.FormatId = dictionaryPropertyDataFormat.GetAt("Standard");
autoPropDef.SetAutomaticData(SolidClassName, "オブジェクトID");
propertySetDefinition.Definitions.Add(autoPropDef);
...
0 Likes
Accepted solutions (1)
816 Views
4 Replies
Replies (4)
Message 2 of 5

Gepaha
Collaborator
Collaborator

You didn't show the code where the PropertySetDefinition was added to the database.
Also, did you correctly assign the class name to SolidClassName?
Take a look at the links below, it shows how to create a PropertySetDefinition and add it to the database.

https://adndevblog.typepad.com/aec/2012/09/defining-a-property-set-definition-in-net-.html 

https://forums.autodesk.com/t5/net/create-properties-in-custom-category/td-p/9385059 

0 Likes
Message 3 of 5

ebi1007
Enthusiast
Enthusiast

Thank you for replay. I've already took a look  that site.

This is my code below. What is wrong?

var database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
var SolidClassName = RXObject.GetClass(typeof(Solid3d)).Name;
var TINClassName = RXObject.GetClass(typeof(TinSurface)).Name;
var AlignmentClassName = RXObject.GetClass(typeof(Alignment)).Name;

var dictionaryPropertyDataFormat = new DictionaryPropertyDataFormat(database);
      
using (Transaction transaction1 = database.TransactionManager.StartTransaction())var propertySetDefinition = new PropertySetDefinition();
 propertySetDefinition.SetToStandard(database);
 propertySetDefinition.SubSetDatabaseDefaults(database);
 propertySetDefinition.AlternateName = propertySetName;
 propertySetDefinition.IsLocked = false;
 propertySetDefinition.IsVisible = true;
 propertySetDefinition.IsWriteable = true;

 //適用タブ
 var filters = new StringCollection();
 filters.Add(SolidClassName);
 filters.Add(TINClassName);
 filters.Add(AlignmentClassName);
 propertySetDefinition.SetAppliesToFilter(filters, false);

 //定義タブ
                
 var autoPropDef = new PropertyDefinition();
 autoPropDef.SetToStandard(database);
 autoPropDef.SubSetDatabaseDefaults(database);
 autoPropDef.Name = "オブジェクトID";
 autoPropDef.Automatic = true;
 autoPropDef.IsVisible = true;
 autoPropDef.IsReadOnly = false;
 autoPropDef.FormatId = dictionaryPropertyDataFormat.GetAt("Standard");
 autoPropDef.SetAutomaticData(SolidClassName, "ObjectID");
 //autoPropDef.DataType = Autodesk.Aec.PropertyData.DataType.AutoIncrement;
 propertySetDefinition.Definitions.Add(autoPropDef);
 propertySetDefinition.SetDisplayOrder(autoPropDef, 1);

 

 

0 Likes
Message 4 of 5

Gepaha
Collaborator
Collaborator
string propertySetName = "MyTest";
var database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;

var SolidClassName = RXObject.GetClass(typeof(Solid3d)).Name;
var TINClassName = RXObject.GetClass(typeof(TinSurface)).Name;
var AlignmentClassName = RXObject.GetClass(typeof(Alignment)).Name;

var dictionaryPropertyDataFormat = new DictionaryPropertyDataFormat(database);
using (Transaction transaction1 = database.TransactionManager.StartTransaction())
{
   var propertySetDefinition = new PropertySetDefinition();
   propertySetDefinition.SetToStandard(database);
   propertySetDefinition.SubSetDatabaseDefaults(database);
   propertySetDefinition.AlternateName = propertySetName;
   propertySetDefinition.IsLocked = false;
   propertySetDefinition.IsVisible = true;
   propertySetDefinition.IsWriteable = true;

   //適用タブ
   var filters = new StringCollection();
   filters.Add(SolidClassName);
   filters.Add(TINClassName);
   filters.Add(AlignmentClassName);
   propertySetDefinition.SetAppliesToFilter(filters, false);

   //定義タブ
   var autoPropDef = new PropertyDefinition();
   autoPropDef.SetToStandard(database);
   autoPropDef.SubSetDatabaseDefaults(database);
   autoPropDef.Name = "オブジェクトID";
   autoPropDef.Automatic = true;
   autoPropDef.IsVisible = true;
   autoPropDef.IsReadOnly = false;
   autoPropDef.FormatId = dictionaryPropertyDataFormat.GetAt("Standard");
   autoPropDef.SetAutomaticData(SolidClassName, "ObjectID");
   //autoPropDef.DataType = Autodesk.Aec.PropertyData.DataType.AutoIncrement;
   propertySetDefinition.Definitions.Add(autoPropDef);
   propertySetDefinition.SetDisplayOrder(autoPropDef, 1);

   var dictionaryPropertySetDefinitions = new DictionaryPropertySetDefinitions(database);
   if (dictionaryPropertySetDefinitions.Has(propertySetName, transaction1))
   {
      return;
   }

   dictionaryPropertySetDefinitions.AddNewRecord(propertySetName, propertySetDefinition);
   transaction1.AddNewlyCreatedDBObject(propertySetDefinition, true);
   transaction1.Commit();
}
0 Likes
Message 5 of 5

ebi1007
Enthusiast
Enthusiast
Accepted solution

Thank you for your help.

However, I found that the problem was somewhere else.

0 Likes