Zoom to Occurrence in Assembly without SelectSet

Zoom to Occurrence in Assembly without SelectSet

julian_sol
Contributor Contributor
1,072 Views
2 Replies
Message 1 of 3

Zoom to Occurrence in Assembly without SelectSet

julian_sol
Contributor
Contributor

Hi!


Could anyone help me with the method below. I would like to zoom to a (non-selected) occurrence, which behaves exactly like the 'Find in Window' command on BrowserNodes.

 

How do I setup the camera correctly so it zooms to the occurrence without changing viewing direction of the camera? I can't figure it out. Thanks in advance!

 

        private void ZoomToOccurrence(ComponentOccurrence occurrence)
        {
            var camera = InventorApplication.ActiveView.Camera;
            var minPoint = occurrence.RangeBox.MinPoint;
            var maxPoint = occurrence.RangeBox.MaxPoint;
            
            var centerPoint = InventorApplication.TransientGeometry.CreatePoint((maxPoint.X - minPoint.X), (maxPoint.Y - minPoint.Y), (maxPoint.Z- minPoint.Z));
            var target = centerPoint;
            var eye = ???

            camera.Target = target;
            camera.Eye = ???

            camera.SetExtents(40, 40);
            camera.Apply();
        }

 

0 Likes
Accepted solutions (1)
1,073 Views
2 Replies
  • zoom
Replies (2)
Message 2 of 3

nmunro
Collaborator
Collaborator
Accepted solution

There are probably a few ways to do this. The following is one method. It is a vba macro but easy enough to translate to C#.

 

Public Sub ZoomOccur()

    'NOTE: Aseembly document open with one occurrence selected
    ' before running this macro, no error checking
    
    Dim doc As AssemblyDocument
    Set doc = ThisDocument
    
    Dim cam As Camera
    Set cam = ThisApplication.ActiveView.Camera
    
    Dim occur As ComponentOccurrence
    Set occur = doc.SelectSet.Item(1)
    
    Dim min, max As Point
    Set min = occur.RangeBox.MinPoint
    Set max = occur.RangeBox.MaxPoint
    
    
    ' current camera target point
    Dim curTarget As Point
    Set curTarget = cam.Target
    
    'current camera eye point
    Dim curEye As Point
    Set curEye = cam.Eye
    
    ' get vector from current target to current eye
    Dim toEyeVector As Vector
    Set toEyeVector = ThisApplication.TransientGeometry.CreateVector(curEye.X - curTarget.X, curEye.Y - curTarget.Y, curEye.Z - curTarget.Z)
    
    
    ' get new target point for camera
    Dim targetPt As Point
    Set targetPt = ThisApplication.TransientGeometry.CreatePoint((max.X + min.X) / 2#, (max.Y + min.Y) / 2#, (max.Z + min.Z) / 2#)
    
    'create new eye point by starting at new target point
    'and then translating point using the targetToEye vector
    Dim newEye As Point
    Set newEye = ThisApplication.TransientGeometry.CreatePoint(targetPt.X, targetPt.Y, targetPt.Z)
    Call newEye.TranslateBy(toEyeVector)
    
    ' set new camera data
    cam.Eye = newEye
    cam.Target = targetPt
    Call cam.SetExtents(40#, 40#)
    
    ' apply new camera
    cam.Apply
    
End Sub

        


https://c3mcad.com

Message 3 of 3

julian_sol
Contributor
Contributor

Works like a charm, thank you very much!

0 Likes