GeometryObject.Name via Revit API

GeometryObject.Name via Revit API

AAlKallas
Explorer Explorer
443 Views
7 Replies
Message 1 of 8

GeometryObject.Name via Revit API

AAlKallas
Explorer
Explorer

Hi All,

I hope you are doing well.

 

Could someone please help me to get the name of a GeometryObject using the Revit API in C#?

Specifically, I am trying to achieve the same name as displayed in AutoCAD when the Revit file is exported as DWG.


Screenshot 01.png

 

 

For your reference, I have attached both the Revit and AutoCAD files.

Thank you in advance for your support!

0 Likes
Accepted solutions (1)
444 Views
7 Replies
Replies (7)
Message 2 of 8

Mohamed_Arshad
Advisor
Advisor

Hi @AAlKallas 

 Are you trying to create Revit Object using AutoCAD file ? I didn't understand your context


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 3 of 8

AAlKallas
Explorer
Explorer

No!
I need help retrieving the name of a GeometryObject for a DirectShape created from a STEP file using the Revit API in C#.

This name is visible in AutoCAD when the DirectShape is exported to DWG, but I want to access it directly from the Revit API without having to export it to DWG.

0 Likes
Message 4 of 8

Mohamed_Arshad
Advisor
Advisor

You need directly access the DWG file using Revit API? Still I have confusion 


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 5 of 8

AAlKallas
Explorer
Explorer

If you open the Revit file I shared earlier, you will see a DirectShape without a name.


However, the name I am looking for is embedded in the GeometryObject, as demonstrated when exporting the file to DWG (shared previously).

 

My goal is to get this specific name directly from the Revit API using C# and rename the DirectShape accordingly, without having to rely on a DWG export.

0 Likes
Message 6 of 8

Mohamed_Arshad
Advisor
Advisor
Accepted solution

Hi @AAlKallas 

 

I got your question, it is a DirectShapeType name, so you need to access the DirectShapeType to get the name. Kindly check the below code for additional reference.

And thank you for you replies 🙂

 

Reference Code Snippet

///Selection Reference
Reference selRef = uiDoc.Selection.PickObject(ObjectType.Element, "Select elements");

///Get Element
Element e = doc.GetElement(selRef);

///Get Symbol Id
Options options = new Options { ComputeReferences = true };

GeometryElement geometryElement = e.get_Geometry(options);

foreach (GeometryObject geoInst in geometryElement)
{
    if (geoInst is GeometryInstance)
    {
        GeometryInstance geoInstance = geoInst as GeometryInstance;

        SymbolGeometryId symbolId = geoInstance.GetSymbolGeometryId();
        Element symElement = doc.GetElement(symbolId.SymbolId);

        if (symElement is DirectShapeType)
        {
            TaskDialog.Show("Symbol Id", symElement.Name);
        }
    }
}

 Output

Mohamed_Arshad_0-1733147282312.png

Hope this will helps 🙂

 


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 7 of 8

AAlKallas
Explorer
Explorer
Thank you so much for solving this issue. I truly appreciate your effort and support. It made a big difference, and I’m very grateful.
Message 8 of 8

Mohamed_Arshad
Advisor
Advisor

Thank you so much @AAlKallas 🙂  Happy Coding


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes