FindUsingVector or Ray

FindUsingVector or Ray

HermJan.Otterman
Advisor Advisor
634 Views
3 Replies
Message 1 of 4

FindUsingVector or Ray

HermJan.Otterman
Advisor
Advisor

Hello,

 

I have an Assembly with multiple levels. I try to find if a part is in front of an other part with the FindByUsingVector methode. This seems to work on the first and second level, but when I shoot the vector from a part in a sub-sub assembly (third level) it does not see the other parts that are in a higher assembly...?? is there some limitation?

I use the ComponentDefinition of the main assembly

 

also I tried changing the option filter but that did not help. I use kPartFaceFilter and kAssemblyOccurrenceFilter.

 

should I maybe use the FindByUsingRay methode? what is the difference between the two?

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Accepted solutions (1)
635 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor
Accepted solution

I think that if you use "kAssemblyOccurrenceFilter" it will only find occurrences of the main assembly. (there for it would also only find sub assembly's but never occurrences in a sub-assembly) But if you would use "kAssemblyLeafOccurrenceFilter" it would find all parts in any (sub)assembly.

I created the following iLogic rule. it will select what ever part is in the middle of your screen using "FindUsingVector()". (Also if the part/occurrences are 3 sub-assemblies deep)

Dim doc As AssemblyDocument = ThisDoc.Document

Dim eye As Point = ThisApplication.ActiveView.Camera.Eye
Dim target As Point = ThisApplication.ActiveView.Camera.Target
Dim direction As Vector = eye.VectorTo(target)

Dim def As AssemblyComponentDefinition = doc.ComponentDefinition
Dim objs As ObjectsEnumerator = doc.ComponentDefinition.FindUsingVector(
	eye, direction.AsUnitVector, {SelectionFilterEnum.kAssemblyLeafOccurrenceFilter})

doc.SelectSet.Clear()
For Each item As Object In objs
    doc.SelectSet.Select(item)
Next
MsgBox(objs.Count()) 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 4

HermJan.Otterman
Advisor
Advisor

Thank's Jelte for your reply!

 

The kAssemblyOccurrenceFilter gives me much more back then only Subassemblies and that is why I don't understand the filter so much. For the levels 1 and 2 to works and it will find the components or surfacebodyproxy's

I tried also the AllEntityFilter and saw it did not give me back much more. I will try to so what the kAssemblyLeafOccurrenceFilter gives me back..  thanks!

My code look a little like you code, I also use the Camera eye and target but then of a Front view in a 2D drawing. In 3D then front view would be 0,-1,0 (vector) so you would look in the -Y direction. but when I get the vector between the target and the Eye, it is not 0,-1,0 as I would expect but a little bit off, like -0.01, -0.995, -0.01.  I think for now, but have to do more testing, that my search vector was missing the object in front of it because of this slight deviation of the camera direction. I Use this camera direction also for my "FindUsingRay" direction

So many strange things for me on this:

- the filters give me back things I would not expect

- the camera direction of the frontview (2D) is not what it would be in 3D

- also if I run my code with only the .dwg open, with a view of my assembly, the code won't run. I have to open the assembly also!, so I gues it has something to do with the "FindUsingVector" is using the graphics or so??

my code now works with some "but's"...

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 4 of 4

HermJan.Otterman
Advisor
Advisor

hello Jelte, because of your answer I found an error in my code.

to get the camera dircetion I use:

Dim oViewDirection As Inventor.Vector = oTg.CreateVector(oTarget.X - oEye.X, -oTarget.Y - oEye.Y, oTarget.Z - oEye.Z)  ... (this is now the corrected one!, because I made an error in this.)

 

The error I found using your, much nicer code

Dim oViewDirection As Inventor.Vector = oTarget.VectorTo(oEye)  .... !!!

 

so thanks for your help

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes