getting all XData of a selected entity

getting all XData of a selected entity

_Bilal
Advocate Advocate
747 Views
4 Replies
Message 1 of 5

getting all XData of a selected entity

_Bilal
Advocate
Advocate

Hi,

 

How to get all XData of a selected entity using .NET

 

Thank you

0 Likes
Accepted solutions (1)
748 Views
4 Replies
Replies (4)
Message 2 of 5

_gile
Consultant
Consultant

Hi,

The DBObject class (from which Entity is derived) has an XData property. 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 5

_Bilal
Advocate
Advocate

Thank you _gile,

 

Actually I am looking for .NET snippet like the one in autolisp (setq oXDlst (cdr (assoc -3 (entget (car (entsel)) '("*")))))

0 Likes
Message 4 of 5

_gile
Consultant
Consultant
Accepted solution

You should post what you've written so far so that we can adapt a snippet.

 

The C# "equivalent" to the (setq oXDlst (cdr (assoc -3 (entget (car (entsel)) '("*"))))) AutoLISP snippet, could be:

 

var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var promptEntityResult = ed.GetEntity("\nSelect object: ");
ResultBuffer oXDlst = default;
if (promptEntityResult.Status == PromptStatus.OK)
{
    using (var tr = db.TransactionManager.StartTransaction())
    {
        var entity = tr.GetObject(promptEntityResult.ObjectId, OpenMode.ForRead);
        oXDlst = entity.XData;
        tr.Commit();
    }
}

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 5

_Bilal
Advocate
Advocate

Thank you _gile,

 

I was trying (Googling and using ChatGPT) to get or develop a solution to retrieve all XData of a selected entity, but my code turned out to be quite long and convoluted. I didn't manage to find a direct and efficient way to do it, which is why I didn't post it here. I was sure that there was a more direct and straightforward solution.

0 Likes