Read Property Data from an entity

Read Property Data from an entity

damir_vidakovic
Enthusiast Enthusiast
8,570 Views
16 Replies
Message 1 of 17

Read Property Data from an entity

damir_vidakovic
Enthusiast
Enthusiast

Hello

I'm trying to make a code that uses property set data written in the drawing objects. 

 

So I have a dwg with one property set definition, and I defined it like this:

2016-06-20.png

 

 

And I made it so it applies to pipes. Then I attached it to a pipe in the drawing, and in the properties panel, I can see and edit these values:

 

2016-06-20 (4).png

 

So, I have a code that finds all property set definitions in the dwg:

Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;

DictionaryPropertySetDefinitions dpsd = new DictionaryPropertySetDefinitions(acCurDb); foreach (ObjectId id in dpsd.Records) { try { PropertySetDefinition pds = transaction.GetObject(id, OpenMode.ForRead) as PropertySetDefinition; if (pds != null) { foreach (PropertyDefinition pdd in pds.Definitions) { //this is property definition that can be used } } } catch (Exception ex) {
}
}

 

But, how can I read values from specific entity, if I have Pipe object for instance.

 

I tried to use using PropertyDataServices.GetPropertyValueExt, but I always get exception, but I did not find any documentation about parameters that go in, so it was shot in the dark.

 

Thank you

---------------------
Damir Vidakovic
www.studioars.com
Accepted solutions (1)
8,571 Views
16 Replies
Replies (16)
Message 2 of 17

augusto.goncalves
Alumni
Alumni
Have you tried the PropertySetDefinition.GetValue() method?
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 3 of 17

damir_vidakovic
Enthusiast
Enthusiast

Hi Augusto

 

Thank you for your help.

 

I tried to use it like this:

 

//oPipe is already opened for read (Pipe object)

Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;

ObjectIdCollection allPSSets = PropertyDataServices.GetPropertySets(oPipe);

DictionaryPropertySetDefinitions dpsd = new DictionaryPropertySetDefinitions(acCurDb);

int propertyId=0;
ObjectIdCollection brp = new ObjectIdCollection();

try
{
	ObjectId idDef = dpsd.GetAt("TestPS");

	PropertySetDefinition psd = transaction.GetObject(idDef, OpenMode.ForRead) as PropertySetDefinition;

	foreach (PropertyDefinition pd in psd.Definitions)
	{
           res = pd.Value(oPipe, brp);//always null
	}
	
	res = psd.GetValue(propertyId, oPipe, brp);//always null

}
catch (Exception exx)
{
}

 

I tried 2 things: 

 

1. I tried to read with 

res = pds.GetValue(propertyId, oPipe, brp);

I put 0 as property Id, I assumed it is index of the property in the definition, but I always get null as a result. The same with 1. 

 

Then I tried to go over all PropertyDefintions in the PropertySetDefinition:

foreach (PropertyDefinition pd in psd.Definitions)
{
    res = pd.Value(oPipe, brp);//always null
}

There is BlockReferencePath argument that is required, and I'm passing in empty ObjectIdCollection in all cases.

 

But the opened pipe should definitely have these properties set. 

 

 

---------------------
Damir Vidakovic
www.studioars.com
0 Likes
Message 4 of 17

damir_vidakovic
Enthusiast
Enthusiast

Any ideas?

---------------------
Damir Vidakovic
www.studioars.com
0 Likes
Message 5 of 17

Jeff_M
Consultant
Consultant
In my quick tests, I'm seeing the same null results. I'm also getting 0 for the number of propertysets here:
ObjectIdCollection allPSSets = PropertyDataServices.GetPropertySets(oPipe);
Which explains why the others are returning null. The Pipe object most definitely has a PropertySet and Definition attached/defined.
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 6 of 17

Anonymous
Not applicable

 Hello Damir Vidakovic,

 

Can you paste a bit more source code for this subject?

 

for using "DictionaryPropertySetDefinitions" and "PropertySetDefinition" class ,what dll I shoud add to Visual studio?

 

waiting for reply! 

 

0 Likes
Message 7 of 17

Anonymous
Not applicable

Hello Damir Vidakovic,

 

What Application this plug-in run inside? Civil 3D or Architecture?

0 Likes
Message 8 of 17

damir_vidakovic
Enthusiast
Enthusiast
Accepted solution

This case was resolved by Autodesk technician through the different channel a long time ago, but I forgot to post the solution here also afterwards.

 

The solution is this:

>>>>
using (Autodesk.AutoCAD.ApplicationServices.DocumentLock loc = acDoc.LockDocument())
            {
                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    // Request for objects to be selected in the drawing area
 
                    PromptSelectionResult acSSPrompt = acDoc.Editor.GetSelection();
 
                    // If the prompt status is OK, objects were selected
                    if (acSSPrompt.Status == PromptStatus.OK)
                    {
                        SelectionSet acSSet = acSSPrompt.Value;
 
                        // Step through the objects in the selection set
                        foreach (SelectedObject acSSObj in acSSet)
                        {
                            Autodesk.AutoCAD.DatabaseServices.DBObject dbObj = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead);
                            ObjectIdCollection setIds = PropertyDataServices.GetPropertySets(dbObj);
 
                            foreach (ObjectId psId in setIds)
                            {
                                PropertySet pset = acTrans.GetObject(psId, OpenMode.ForRead, false, false) as PropertySet;
                                PropertySetDataCollection psetDataColl = pset.PropertySetData;
                                PropertySetData pTempData;
                                for (int c = 0; c < psetDataColl.Count; c++)
                                {
                                    pPropData = psetDataColl[c];
                                    object data = pPropData.GetData();
                                }
                            }
 
                            return;
                        }
                    }
                }
            }
<<<<

 

 

---------------------
Damir Vidakovic
www.studioars.com
Message 9 of 17

damir_vidakovic
Enthusiast
Enthusiast

To use these classes you have to use AecPropDataMgd.dll

---------------------
Damir Vidakovic
www.studioars.com
Message 10 of 17

Anonymous
Not applicable

Dear Damir Vidakovic,

 

Thanks you very much for sharing your solution.

 

I have try another solution  which is a little different with yours follows:

 

CivilDocument doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
Document acDoc = acDocMgr.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (System.IO.StreamWriter sw = new StreamWriter(@"d:\output.txt", true))
using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
{
    ObjectIdCollection pipeNetworkIds = doc.GetPipeNetworkIds();
    foreach (ObjectId pipeNetworkId in pipeNetworkIds)
    {
        Network oNetwork = ts.GetObject(pipeNetworkId, OpenMode.ForWrite) as Network;
        ObjectIdCollection pipeIds = oNetwork.GetPipeIds();
        foreach (ObjectId pipeId in pipeIds)
        {
            Pipe oPipe = ts.GetObject(pipeId, OpenMode.ForWrite) as Pipe;
            ObjectIdCollection setIds = PropertyDataServices.GetPropertySets(oPipe);
            foreach (ObjectId psId in setIds)
            {
                PropertySet pset = ts.GetObject(psId, OpenMode.ForRead, false, false) as PropertySet;
                PropertySetDefinition psd = ts.GetObject(pset.PropertySetDefinition, OpenMode.ForRead) as PropertySetDefinition;
                foreach (PropertyDefinition pd in psd.Definitions)
                {
                    int propertyId=pset.PropertyNameToId(pd.Name);
                    object value = pset.GetAt(propertyId);
                    sw.WriteLine("Handler: " + oPipe.Handle.ToString() + "; " + pd.Name + ": " + value.ToString().Trim());
                 }  
                 //PropertySetDataCollection psetDataColl = pset.PropertySetData;
                 //PropertySetData pPropData;
                //for (int c = 0; c < psetDataColl.Count; c++)
                //{
                    // pPropData = psetDataColl[c];
                    // object data = pPropData.GetData();
                    //}
                }
                sw.WriteLine(System.Environment.NewLine);

            }
        }
}

 

and it works well ,thank you again.

Message 11 of 17

rebeccas85JUR
Explorer
Explorer

Hi All,

 

I tried all above code but not able to get PropertyDataSet from Pipe as image below:-


 

rebeccas85JUR_0-1606548752558.png

 

While i select in Civil 3D i can see property dataset in property design panel but with code it is always 0. 

 





0 Likes
Message 12 of 17

gleeuwdrent
Advocate
Advocate

This works well for me:

 

 

ObjectId objectPropSet = PropertyDataServices.GetPropertySet(entity, oidPropSetDef);
PropertySet ps = objectPropSet.GetObject(AcDb.OpenMode.ForWrite) as PropertySet;
PropertySetDefinition def = t.GetObject(ps.PropertySetDefinition, AcDb.OpenMode.ForRead) as PropertySetDefinition;
foreach (PropertyDefinition propDef in def.Definitions)
{
     string data = ps.GetAt(ps.PropertyNameToId(propDef.Name));
}

 

 

0 Likes
Message 13 of 17

rebeccas85JUR
Explorer
Explorer

Hi gleeuwdrent,

How you are getting oidPropSetDef.

while i am doing property set always zero.

 

Same question i posted with file & code please check once if you have time 

 

https://forums.autodesk.com/t5/civil-3d-forum/extracting-property-set-properties/m-p/9902649#M439262



Thanks,

Manish Singh

0 Likes
Message 14 of 17

gleeuwdrent
Advocate
Advocate

I forgot two lines of code:

DictionaryPropertySetDefinitions dictPropSetDefs = new DictionaryPropertySetDefinitions(db); // lists all property set definitions in drawing
ObjectId oidPropSetDef = dictPropSetDefs.GetAt("YourPropertySetName");
0 Likes
Message 15 of 17

Norman_Yuan
Mentor
Mentor

@rebeccas85JUR ,

 

I read your post in the other forum and downloaded your drawing. A couple of things confuses me that need more explanation:

 

1. The picture you attached to this thread and attached to the post in other forum CLEARLY showed that you are using plain AutoCAD, or running C3D as AutoCAD (with C3D object enabler, I assume), not C3D. in the 2 pictures, the Properties window only has 3 tabs (Design, Display, Object Class), as AutoCAD; while with C3D, there is 4th tab Extended Data where the PropertySet Data shows.

 

2. The drawing I downloaded from your other post DOES NOT HAVE ANY propertyset defined.

 

However, after reading the other thread again and again, I think you may want to explain what you want to achieve more accurately. If you just want to extract PIPE's data, you do not need to deal with PropertyDataSet. PropertyData is meant to attach extra set of data to entities, which are usually custom data that are not from the entity itself. So, more clarification is needed.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 16 of 17

mehsan
Advocate
Advocate

Can i get vlisp code for this also.

Message 17 of 17

TourajM
Enthusiast
Enthusiast
Hi, I have no clue how to use VB to get DLL. Can anyone help me?
0 Likes