How to retrieve the Type of selected object in C#

How to retrieve the Type of selected object in C#

bim01
Contributor Contributor
1,483 Views
4 Replies
Message 1 of 5

How to retrieve the Type of selected object in C#

bim01
Contributor
Contributor

In VB.net , it is easy to get the ObjectTypeEnum of an selected object by oObject.Type, but in C#, only the oObject.GetType() method I can use and it returns the "System.__ComObject", how can I get more specific type like "Face"、"Edge" with ObjectTypeEnum like it does in VB.net? In the "Watch" window of vs studio, I can see the "Type" property in "dynamic view", how can I get it? I have read some posts but haven't got an solution:

 https://forums.autodesk.com/t5/inventor-customization/selected-object-type/m-p/2727059#M32743 

https://forums.autodesk.com/t5/inventor-customization/select-set-problem/m-p/9393219 

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

CattabianiI
Collaborator
Collaborator

I use the Type property in C# as well (no relation with the .NET method GetType())

Check that EmbedInteropTypes of the Inventor reference is set to False.

0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor

Hi @bim01.  I actually created a contribution post a while back that was all about showing how to identify what Type of object is selected.  It goes over three main tools/processes.  But unfortunately it was entirely designed for use in iLogic, so it uses vb.net, instead of C#, so I don't know if it will be useful to you or not.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 5

HideoYamada
Advisor
Advisor
Accepted solution

Hello,

 


@bim01 wrote:

In VB.net , it is easy to get the ObjectTypeEnum of an selected object by oObject.Type, but in C#, only the oObject.GetType() method I can use and it returns the "System.__ComObject", how can I get more specific type like "Face"、"Edge" with ObjectTypeEnum like it does in VB.net?

The following thread will help you.

How to get type of COM object 

 

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 5 of 5

bim01
Contributor
Contributor
Thanks, great help, simple and effective
0 Likes