Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Create properties in custom category

Anonymous

Create properties in custom category

Anonymous
Not applicable

Hi,

 

I'm new in autocad development.

I've create an arx with custom object (wrapped for C# use)

I would like to add properties (in custom category)  in property set, I saw the example asdkOPMNet but

it does not create custom category.

how can I implement this for C# ?

 

Thank,

Sorry for my english.

 

0 Likes
Reply
1,068 Views
4 Replies
Replies (4)

marcin.sachs
Advocate
Advocate

Hi,
What do you mean by "Custom category"? - property set?
Please see my code below. I created custom property for polyline:

internal static void CreateSteelBeamPropertySetDefinition()
        {
            string propertySetName = "SteelBeam";
            var database = Application.DocumentManager.MdiActiveDocument.Database;
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            var PolylineClassName = RXObject.GetClass(typeof(Polyline)).Name;
            //try
            //{
            var dictionaryPropertyDataFormat = new DictionaryPropertyDataFormat(database);
            var propertySetDefinition = new PropertySetDefinition();

            using (Transaction transaction1 = database.TransactionManager.StartTransaction())
            {
                propertySetDefinition.SetToStandard(database);
                propertySetDefinition.SubSetDatabaseDefaults(database);
                propertySetDefinition.Description = "Property Set Definition for Steel Beam";
                propertySetDefinition.AlternateName = propertySetName;
                propertySetDefinition.IsLocked = false;
                propertySetDefinition.IsVisible = true;
                propertySetDefinition.IsWriteable = true;
                
                var filters = new StringCollection();
                filters.Add(PolylineClassName);
                propertySetDefinition.SetAppliesToFilter(filters, false);

                //var automaticPropertyDefinition = new PropertyDefinition();

                var  propDef = new PropertyDefinition();

                propDef.SetToStandard(database);
                propDef.SubSetDatabaseDefaults(database);
                propDef.Name = "Prefix";
                propDef.Description = "Prefix of steel beam";
                propDef.IsVisible = true;
                propDef.IsReadOnly = false;
                propDef.FormatId = dictionaryPropertyDataFormat.GetAt("Standard");     
                propertySetDefinition.Definitions.Add(propDef);
                propertySetDefinition.SetDisplayOrder(propDef, 1);

                propDef = new PropertyDefinition();
                propDef.SetToStandard(database);
                propDef.SubSetDatabaseDefaults(database);
                propDef.Name = "Name";
                propDef.Description = "Name of steel beam";
                propDef.IsVisible = true;
                propDef.IsReadOnly = false;
                propDef.FormatId = dictionaryPropertyDataFormat.GetAt("Standard");
                propertySetDefinition.Definitions.Add(propDef);
                propertySetDefinition.SetDisplayOrder(propDef, 2);

                propDef = new PropertyDefinition();
                propDef.SetToStandard(database);
                propDef.SubSetDatabaseDefaults(database);
                propDef.Name = "Style";
                propDef.Description = "Style of steel beam";
                propDef.IsVisible = true;
                propDef.IsReadOnly = false;
                propDef.FormatId = dictionaryPropertyDataFormat.GetAt("Standard");
                propertySetDefinition.Definitions.Add(propDef);
                propertySetDefinition.SetDisplayOrder(propDef, 3);

                propDef = new PropertyDefinition();
                propDef.SetToStandard(database);
                propDef.SubSetDatabaseDefaults(database);
                propDef.Name = "Length2";
                propDef.Description = "Length of steel beam";
                propDef.IsVisible = false;
                propDef.IsReadOnly = true;
                propDef.FormatId = dictionaryPropertyDataFormat.GetAt("Standard");
                propDef.SetAutomaticData(PolylineClassName, "Length");
                propertySetDefinition.Definitions.Add(propDef);
                propertySetDefinition.SetDisplayOrder(propDef, 4);

                propDef = new PropertyDefinition();
                propDef.SetToStandard(database);
                propDef.SubSetDatabaseDefaults(database);
                propDef.Name = "WeightPerMetre";
                propDef.Description = "Weight per metre";
                propDef.IsVisible = true;
                propDef.IsReadOnly = false;
                propDef.FormatId = dictionaryPropertyDataFormat.GetAt("Standard");
                propertySetDefinition.Definitions.Add(propDef);
                propertySetDefinition.SetDisplayOrder(propDef, 5);

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

                dictionaryPropertySetDefinitions.AddNewRecord(propertySetName, propertySetDefinition);
                transaction1.AddNewlyCreatedDBObject(propertySetDefinition, true);
                transaction1.Commit();
            }
            using (Transaction transaction2 = database.TransactionManager.StartTransaction())
            {
                propertySetDefinition = transaction2.GetObject(propertySetDefinition.ObjectId, OpenMode.ForWrite) as PropertySetDefinition;
                var formulaPropertyDefinition = new PropertyDefinitionFormula();
                formulaPropertyDefinition.SetToStandard(database);
                formulaPropertyDefinition.SubSetDatabaseDefaults(database);
                formulaPropertyDefinition.Name = "Length";
                formulaPropertyDefinition.Description = "RESULT = [Length2]/1000";
                formulaPropertyDefinition.IsVisible = true;
                propertySetDefinition.Definitions.Add(formulaPropertyDefinition);
                propertySetDefinition.SetDisplayOrder(formulaPropertyDefinition, 6);
                formulaPropertyDefinition.SetFormulaString("RESULT = [Length2]/1000");
                formulaPropertyDefinition.DataItems[0].FormatId = dictionaryPropertyDataFormat.GetAt("2 Decimal");
                formulaPropertyDefinition.FormatId = dictionaryPropertyDataFormat.GetAt("2 Decimal");
                transaction2.Commit();
            }
        }

usage:

DictionaryPropertySetDefinitions dictPropSetDef = new DictionaryPropertySetDefinitions(db);
                if (!dictPropSetDef.Has("SteelBeam", acTrans))
                {
                    CreateSteelBeamPropertySetDefinition();

                }

Ta7a
Enthusiast
Enthusiast

Hello,

 

what is the dlls that should be refrenced to access the PropertySetDefinition 

0 Likes

norman.yuan
Mentor
Mentor

Firstly, @marcin.sachs ' reply has nothing to do with the OP's question.

 

PropertySetData APIs are from AecPropDataMgd.dll, which only available for AutoCAD's AEC verticals (Arch, MEP, C3D..), not for vanilla AutoCAD. The DLL is located in "C:\....\AutoCAD 202x]ACA" folder (again, if you use plain AutoCAD, there is no "....\ACA" folder).

 

 

Norman Yuan

Drive CAD With Code

EESignature

ActivistInvestor
Advisor
Advisor

See the docs for the IAcPiCategorizeProperties class