Getting PropertySetDefinition Value of an object

Getting PropertySetDefinition Value of an object

lumoric
Contributor Contributor
925 Views
6 Replies
Message 1 of 7

Getting PropertySetDefinition Value of an object

lumoric
Contributor
Contributor

Hi,

How to get an actual Value of a object's PropertySetDefinition?

I thought it is this method:

GetValue(int propertyId, Autodesk.AutoCAD.DatabaseServices.ObjectId id, Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection blockRefPath)

but it is causing Civil3d to crash with fatal error "unhandled access violation reading 0x0000 exception at autocad"

 

Here is my code so far:

        [CommandMethod("PropSets")]
        public void PropSets()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            CivilDocument doc = CivilApplication.ActiveDocument;


            // select a  TIN surface
            PromptEntityOptions opSelSurface = new PromptEntityOptions("\nSelect a TIN Surface: ");
            opSelSurface.SetRejectMessage("\nOnly TIN Surface is allowed");
            opSelSurface.AddAllowedClass(typeof(TinSurface), true);
            opSelSurface.AppendKeywordsToMessage = true;
            PromptEntityResult resSelSurface = ed.GetEntity(opSelSurface);
            ObjectId surfaceId = resSelSurface.ObjectId;
            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            using (Transaction transsrc=db.TransactionManager.StartTransaction())
            {
                TinSurface surface = transSrc.GetObject(surfaceId, OpenMode.ForWrite) as TinSurface;
                ObjectIdCollection plinePropSetDefs = PropertyDataServices.GetPropertySetDefinitionsUsed(surface);
                foreach (ObjectId plinePropSetDef in plinePropSetDefs)
                {
                    var prop = transSrc.GetObject(plinePropSetDef, OpenMode.ForWrite) as PropertySetDefinition;
                    foreach(PropertyDefinition propDef in prop.Definitions)
                    {
                        ObjectIdCollection idsDummy = new ObjectIdCollection();
                        string val = propDef.Description;
                        try
                        {
                            string propsetdef = prop.GetValue(propDef.Id, surfaceId, plinePropSetDefs).ToString();
                            Application.ShowAlertDialog("Surface property set def: " + propDef.Name.ToString() + propsetdef);

                        }
                        catch (Exception ex)
                        {
                            Application.ShowAlertDialog(ex.Message);
                        }
                    }
                }
            }
        }
0 Likes
Accepted solutions (1)
926 Views
6 Replies
Replies (6)
Message 2 of 7

hosneyalaa
Advisor
Advisor

HI @lumoric 

 

Because he gives a  NULL  when he REEGING OBJECTID

 as in Image

 

TRY :

 [CommandMethod("TESTPropSets")]
        public void PropSets()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            CivilDocument doc = CivilApplication.ActiveDocument;


            // select a  TIN surface
            PromptEntityOptions opSelSurface = new PromptEntityOptions("\nSelect a TIN Surface: ");
            opSelSurface.SetRejectMessage("\nOnly TIN Surface is allowed");
            opSelSurface.AddAllowedClass(typeof(TinSurface), true);
            opSelSurface.AppendKeywordsToMessage = true;
            PromptEntityResult resSelSurface = ed.GetEntity(opSelSurface);
            ObjectId surfaceId = resSelSurface.ObjectId;
            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            using (Transaction transsrc=db.TransactionManager.StartTransaction())
            {
                TinSurface surface = transsrc.GetObject(surfaceId, OpenMode.ForWrite) as TinSurface;
                ObjectIdCollection plinePropSetDefs = PropertyDataServices.GetPropertySetDefinitionsUsed(surface);
                foreach (ObjectId plinePropSetDef in plinePropSetDefs)
                {
                    var prop = transsrc.GetObject(plinePropSetDef, OpenMode.ForWrite) as PropertySetDefinition;
                    foreach (PropertyDefinition propDef in prop.Definitions)
                    {
                        ObjectIdCollection idsDummy = new ObjectIdCollection();
                        string val = propDef.Description;
                        try
                        {
                            var propsetdef = prop.GetValue(propDef.Id, surfaceId, plinePropSetDefs);
                          
                            //Application.ShowAlertDialog("Surface property set def: " + propDef.Name.ToString());

                        }
                        catch (System.Exception ex)
                        {
                            Application.ShowAlertDialog(ex.Message);
                        }
                    }
                }
            }
        }

 

Annotation 2022-10-05 151622.png

0 Likes
Message 3 of 7

hippe013
Advisor
Advisor
Accepted solution

The following is an example as to how to get the value of the PropertySet

Dim propSetId As ObjectId = PropertyDataServices.GetPropertySet(dbObject, _propertySetDefinitionId)
Dim propSet As PropertySet = tr.GetObject(propSetId, OpenMode.ForRead)
Dim val As Object = propSet.GetAt(propSet.PropertyNameToId(propertyName))

  

I hope that this helps!

Message 4 of 7

james_fisher1
Enthusiast
Enthusiast

Just verifying that this can only be done by python?

0 Likes
Message 5 of 7

hippe013
Advisor
Advisor

The OP is writing in C# on the .NET framework. In Hosneyalaa's post they are using Dynamo. And in my example I am writing in VB on the .NET framework. Are you referring to using Python in Dynamo? 

Message 6 of 7

james_fisher1
Enthusiast
Enthusiast
Sorry, I meant to ask if it requires code to be written, or if it can be done with modules?
0 Likes
Message 7 of 7

hippe013
Advisor
Advisor

I guess I am not sure what you mean when you say modules. In terms of VB a module is a Static Class, as in a module cannot create instances on an object. I am assuming you are referring to using Python? The code posted in this thread is for creating a DLL file that can be imported through the use of the NETLOAD command. Feel free to start a new thread with your question about Modules and the use of Python. That will help engage others in answering your question.