Why IGetEntityName() method returns NULL?

Hello,

The IModelDoc2::IGetEntityName() method returns NULL when I am trying to get name of selected edge/face as shown in text.png

Is there any other API that will give me the above text?

Thanks and Regards,

Mahadev

SolidworksApi/macros
Answers 4
AT
AT 2021-04-08 Best Answer

This method only works for named entities: Select Named Entity (face, edge or vertex) using SOLIDWORKS API . The names you are referring are temp only and change depending on selection. Also take a look at this example: Reading and changing names of SOLIDWORKS objects (features, components, views) using API 

MD
MD 2021-04-08

Thank you Artem for your guidance. 

AT
AT 2021-04-08

ModelName is designed for different purpose this is to assign the tag to entity for parasolid geometry You can get the pointer to IFeature via IFace2::GetFeature where you can grab its name. If you are in assembly you can grab the name of the component from IEnitity::GetComponent to get its name to compose the remaining of the name. No, it won't be unique across the session as you might have sub components opened in another assemblies. What are you trying to do? If you want to keep the unique name across session just create a dictionary and keep the name-reference map. As I have mentioned, faces do not have names (unless named faces) so you have to implement naming yourself.

MD
MD 2021-04-08

Thank you Artem for your reply. 

Now I will use the model name property of IEntity interface to put a name to the selected entity. If so then will it be unique across Solidworks sessions?

Also how to extract the underlying feature name of that selected entity? (e.x. Boss-Extrude1 as in text.png)