FindUsingRay in C#

FindUsingRay in C#

Anonymous
Not applicable
768 Views
5 Replies
Message 1 of 6

FindUsingRay in C#

Anonymous
Not applicable

In FindUsingRay method, how can I access m_FoundEnts items types? My goal is to find the type of each item in the collection so I can't manually cast them (I don't know what they are yet) . please look at the same code in VBA which works.

 

Call oface.SurfaceBody.FindUsingRay(oVertex.Point, normalVector.AsUnitVector, 0, m_FoundEnts, m_LocPoints, False)
    If m_FoundEnts.Count <> 2 Then
       'do something
    End If
    If Not ((TypeOf m_FoundEnts.Item(2) Is Vertex)) Then
        'do something else
    End If

 

//these don't work
m_FoundEnts[2].Type(); //Type() does not exist for items.

//returns null for objectOfIntrest
ObjectsEnumerator objectOfIntrest = (ObjectsEnumerator)m_FoundEnts[2];
if (objectOfIntrest.Type == ObjectTypeEnum.kVertexObject) {}

 

Accepted solutions (1)
769 Views
5 Replies
Replies (5)
Message 2 of 6

JaneFan
Autodesk
Autodesk

Hello @Anonymous, 

 

Please try using var to define the type unknown objects.

var test1 = m_FoundEnts[2];

if(test1.Type == Inventor.ObjectTypeEnum.kVertexObject)
{
}




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 3 of 6

Anonymous
Not applicable

@JaneFan

 findUsingRay.jpg

as you can see I don't have Type() property for item numbers. In debug mode I can see that there is a public Type() property for this object but I cant use it! see below

 

findUsingRay2.jpg

0 Likes
Message 4 of 6

JaneFan
Autodesk
Autodesk

Yes, so please put the object to a var type variant and then get type of the variant. 

var test1 = m_FoundEnts[2];

if(test1.Type == Inventor.ObjectTypeEnum.kVertexObject)

{}




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 5 of 6

Anonymous
Not applicable

thats what ive done in the first photo I'd sent. does not work. there is no Type() methods in intellisense.

0 Likes
Message 6 of 6

JaneFan
Autodesk
Autodesk
Accepted solution

I see. Type property here is run time property. 

I can't find a better way but using try cast and do something in such case:

try
{
Vertex testss = (Vertex)m_FoundEnts[2];
}
catch(Exception e)
{
//do something else
}




Jane Fan
Inventor/Fusion QA Engineer
0 Likes