API for property set - get automatic properties?

API for property set - get automatic properties?

martin.folber
Advocate Advocate
2,874 Views
9 Replies
Message 1 of 10

API for property set - get automatic properties?

martin.folber
Advocate
Advocate

Hi,

we would like to process some automatic properties from Civil 3D properties and it seems, there is no API in .NET to get or read these data? Are we missing anything? eg. handle, index, volume etc...

 

Thanks

Martin

0 Likes
2,875 Views
9 Replies
Replies (9)
Message 2 of 10

Jeff_M
Consultant
Consultant

The PropertySet.GetAt() function returns the value of any Property. For instance:

            var entPsets = PropertyDataServices.GetPropertySets(ent);
            foreach (ObjectId entPset in entPsets)
            {
                var pSet = (PropertySet)entPset.GetObject(OpenMode.ForRead);
                foreach (var name in GetPropDefs(pSet.PropertySetDefinition))
                {
                    var data = pSet.GetAt(pSet.PropertyNameToId(name));
                    //do what you need with the value in data.
                    ....
                 }
               }

GetPropDefs is just a small helper function to get a list of the PropertyDefintion names in the PSet.

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 10

hippe013
Advisor
Advisor

To expand on what @Jeff_M has pointed out. 

 

Referencing the AecPropDataMgd.dll located at

"C:\Program Files\Autodesk\AutoCAD XXXX\ACA\AecPropDataMgd.dll" where XXXX is the year of your install. 

 

To find a list of the available automatic properties use:

PropertyDataServices.FindAutomaticSourceNames(objectName as String, db as Database)

 

Entering "ACDBLINE" as the object name yields the following properties:

Color - Text
Drawing Fingerprint Guid
Handle
Hyperlink
Color
Object ID
Documents
Linetype
Layer
Object Type
Notes
Length

 

0 Likes
Message 4 of 10

michal_hcz
Enthusiast
Enthusiast

Hi, we don't have a problem getting values but our problem is that we don't know which automatic PropertySets are applied to an entity.

 

Settings:

One group with 2 definitions.

michal_hcz_0-1725434865149.png

Applied to a Solid3D.

michal_hcz_1-1725434897791.png

But code returns only one ObjectId for Length definition.

 

ObjectIdCollection psdColl = PropertyDataServices.GetPropertySets(entity);  // count 1 but entity has 2 definitions

michal_hcz_2-1725435164479.png

 

Of course we can use propertySet.GetAt(propertySet.PropertyNameToId("Handle")); but how can we know that this automatic definition was applied to this entity?

 

 

Michal

0 Likes
Message 5 of 10

hippe013
Advisor
Advisor

Are we confusing PropertySetDefinition, PropertySet, and PropertyDefinition? 

 

Below is a quick example of getting the propertySetDefinition for a given object and then for each property definition print to the command line the property name and if it is automatic property or not. 

 

<CommandMethod("PS_DumpProperties")>
Public Sub CmdPS_DumpProperties()
   Dim doc As Document = Application.DocumentManager.MdiActiveDocument
   Dim ed As Editor = doc.Editor
   Dim db As Database = doc.Database

   Dim res As PromptEntityResult = ed.GetEntity(vbCrLf & "Select entity: ")
   If res.Status <> PromptStatus.OK Then Exit Sub

   Using tr As Transaction = db.TransactionManager.StartTransaction
      Dim dbObject As DBObject = tr.GetObject(res.ObjectId, OpenMode.ForRead)

      Dim ids As ObjectIdCollection = PropertyDataServices.GetPropertySetDefinitionsUsed(dbObject)

      For Each id As ObjectId In ids
         Dim propSetDef As PropertySetDefinition = tr.GetObject(id, OpenMode.ForRead)

         ed.WriteMessage(vbCrLf & "Property Set Defintion Name: " & propSetDef.Name)

         For Each propDef As PropertyDefinition In propSetDef.Definitions
            ed.WriteMessage(vbCrLf & "Property Name: " & propDef.Name & " | Is Automatic: " & propDef.Automatic.ToString)
         Next
      Next
      tr.Commit()
   End Using
End Sub

hippe013_0-1725459520910.png

hippe013_1-1725459542188.png

 

I hope that this helps clarify some things. 

 

 

 

Message 6 of 10

michal_hcz
Enthusiast
Enthusiast

It is definitely confusing. Because you can't get values for MyCustomProperty in your code. You can only get value for automatic props. 

propDef.Value(entity.Id, new ObjectIdCollection()); // returns only automatic values

 

In order to get value for MyCustomProperty you still need PropertySetData.

0 Likes
Message 7 of 10

hippe013
Advisor
Advisor

Okay. Well, now I am confused. You stated this: 

 

Hi, we don't have a problem getting values but our problem is that we don't know which automatic PropertySets are applied to an entity.

So, I addressed that. Now you say that you can't get the values. I am having a hard time understanding what you are having trouble with. Also, and I am just realizing this now, you aren't the original poster of the thread. If you could clarify, it would be very helpful.

 

Do you need to figure out how to get the values from the properties? Do you need to figure out how to get the property definitions from the property set definition? Do you need to figure out how to get the properties from the property set? 

0 Likes
Message 8 of 10

hippe013
Advisor
Advisor

The following code dumps each value for each property definition for each property set definition for the given object.

<CommandMethod("PS_DumpValues")>
Public Sub CmdPS_DumpValues()
   Dim doc As Document = Application.DocumentManager.MdiActiveDocument
   Dim ed As Editor = doc.Editor
   Dim db As Database = doc.Database

   Dim res As PromptEntityResult = ed.GetEntity(vbCrLf & "Select entity: ")
   If res.Status <> PromptStatus.OK Then Exit Sub

   Using tr As Transaction = db.TransactionManager.StartTransaction
      Dim dbObject As DBObject = tr.GetObject(res.ObjectId, OpenMode.ForRead)

      Dim ids As ObjectIdCollection = PropertyDataServices.GetPropertySetDefinitionsUsed(dbObject)

      For Each propSetDefId As ObjectId In ids
         Dim propSetDef As PropertySetDefinition = tr.GetObject(propSetDefId, OpenMode.ForRead)
         Dim propSetId As ObjectId = PropertyDataServices.GetPropertySet(dbObject, propSetDefId)
         Dim propSet As PropertySet = tr.GetObject(propSetId, OpenMode.ForRead)

         ed.WriteMessage(vbCrLf & "Property Set Defintion Name: " & propSetDef.Name)

         For Each propDef As PropertyDefinition In propSetDef.Definitions
            Dim val As Object = propSet.GetAt(propSet.PropertyNameToId(propDef.Name))
            If val IsNot Nothing Then
               ed.WriteMessage(vbCrLf & "Property Name: " & propDef.Name & " | Value: " & val.ToString)
            Else
               ed.WriteMessage(vbCrLf & "Property Name: " & propDef.Name & " | Value: NULL")
            End If
         Next
      Next
      tr.Commit()
   End Using
End Sub

 

Message 9 of 10

Jeff_M
Consultant
Consultant

@michal_hcz wrote:

Hi, we don't have a problem getting values but our problem is that we don't know which automatic PropertySets are applied to an entity.

 

ObjectIdCollection psdColl = PropertyDataServices.GetPropertySets(entity);  // count 1 but entity has 2 definitions

michal_hcz_2-1725435164479.png

 

Of course we can use propertySet.GetAt(propertySet.PropertyNameToId("Handle")); but how can we know that this automatic definition was applied to this entity?

 

Michal


To clarify your confusion here...there is ONE PropertySet assigned to the entity. That PropertySet has TWO PropertyDefinitions. By using the GetAt function you are getting that PropertyDefinition value assigned to the entity from which you obtained the PropertySet.

Jeff_M, also a frequent Swamper
EESignature
Message 10 of 10

martin.folber
Advocate
Advocate
Thanks Jeff and Ben. Michal finally found the way how to do it and we have currently utility, which is able to search drawing entites by their automatic handle or objectID using special GUI.
0 Likes