How to determine that the selected CAD entity is text? How to get the content?

How to determine that the selected CAD entity is text? How to get the content?

lvxumang
Contributor Contributor
1,572 Views
9 Replies
Message 1 of 10

How to determine that the selected CAD entity is text? How to get the content?

lvxumang
Contributor
Contributor

I want to pick up text and get the content in the linked CAD.

 

var reference = sel.PickObject(ObjectType.PointOnElement, "sel obj");
Element element = activeDoc.GetElement(reference);

if (element is ImportInstance)
{

/// Can I use the reference to determine this entity is the text?

/// How to determine that the selected CAD entity is text?

/// How to get the text content?
var geoObj = element.GetGeometryObjectFromReference(reference); 

}

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

jeremytammik
Autodesk
Autodesk

Have you installed RevitLookup?

 

That will tell you all you need.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 10

lvxumang
Contributor
Contributor

Dear Jeremy, 

Sorry, in RevitLookup, from the ImportInstance, I can found Line or Arc or Polyline from the Geometry property, but I can't found the Text object.

From which property or fun can I find the text?

 

Thanks,
lvxumang

0 Likes
Message 4 of 10

jeremytammik
Autodesk
Autodesk

Dear Lvxumang,

 

If you cannot see it in RevitLookup, it is probably not easy to access at all.

 

Can you select the individual text object in the user interface?

 

Or are you just picking the entire import instance?

 

Please be aware that the Revit API hardly ever supports any functionality that is not also available in the user interface.

Therefore, if the UI does not support this, the API will probably not do so either.

There may be ways to access the internals of imported CAD instances.

 

What kind of CAD instance is it?

 

Best regards,

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 10

lvxumang
Contributor
Contributor

Dear Jeremy, 

 

 

I use  ObjectType.PointOnElement , so I can select the individual line/arc/text object in the linked CAD ImportInstance.

I can get geometric information from the Line/Arc in the linked CAD ImportInstance, and I also want to get the text information.

 

I use the code:

 

var reference = sel.PickObject(ObjectType.PointOnElement, "sel obj");
Element element = activeDoc.GetElement(reference);

if (element is ImportInstance)
{
var geoObj = element.GetGeometryObjectFromReference(reference); 

/// geoObj may be Line/Arc/PolyLine/Mesh/Solid, if my selection is text, the type is GeometryObject

/// How to determine that the selected geoObj is text? and how to get the text content?

}

 

Thanks,
lvxumang

0 Likes
Message 6 of 10

jeremytammik
Autodesk
Autodesk

Dear Lvxumang,

 

RevitLookup shows most of the API accessible data.

 

According to your findings, there is probably not easy to access at all.

 

What kind of CAD instance is it? DWG? RVT? IFC?

 

Best regards,

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 10

lvxumang
Contributor
Contributor

Hi,  Jeremy, 

 

It‘s DWG.

 

Best regards,

lvxumang

0 Likes
Message 8 of 10

jeremytammik
Autodesk
Autodesk

If you have AutoCAD installed, you can access and use the AutoCAD.NET API from within your Revit add-in:

 

http://thebuildingcoder.typepad.com/blog/2013/04/launching-autocad-within-a-revit-add-in.html

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 10

Anonymous
Not applicable

 

 if (element is GeometryInstance) 
 {
                    GeometryInstance dwgInstance = element as GeometryInstance;
                   Transform transf = dwgInstance.Transform;

               foreach (GeometryObject gObject in dwgInstance.SymbolGeometry)
                    {
                               if (gObject is TextElement) // This could be a block
                        {
                           //do whatever you want to do here
                        }
                    }


}

Thanks & Regards

Sanjay Pandey

0 Likes
Message 10 of 10

lvxumang
Contributor
Contributor

Thank you very much for your reply!

 

 foreach (GeometryObject gObject in dwgInstance.SymbolGeometry)
 {
     if (gObject is TextElement) // This could be a block
     {
         //do whatever you want to do here
     }
 }

 GeometryObject is base APIObject, TextElement is base Element, so the line "if (gObject is TextElement)" is wrong. 

 if my selected is cad text, the GetGeometryObjectFromReference() return value is base class GeometryObject, not the class GeometryInstance.

 

Best regards,
lvxumang

0 Likes