Move camera to coord on drawing

Move camera to coord on drawing

CadUser46
Collaborator Collaborator
944 Views
4 Replies
Message 1 of 5

Move camera to coord on drawing

CadUser46
Collaborator
Collaborator

I'm struggling to grasp this camera object.  I want to move the camera as if the user zoomed/panned to point on a sheet.

 

I have the XY values from the balloon I'm looking for but I cant do what I want.  The CameraPosX and Y are passed into this sub.  e.g X=9.5, Y=11.0

 

    Dim oDoc    As Inventor.DrawingDocument: Set oDoc = ThisApplication.ActiveDocument
    Dim oSheet  As Sheet: Set oSheet = oDoc.Sheets(SheetName)
    
    'Actions
    oDoc.BrowserPanes("Model").Activate
    oSheet.Activate
    
    ' Get the active camera.
    Dim cam As Camera: Set cam = ThisApplication.ActiveView.Camera
    Dim tg As TransientGeometry: Set tg = ThisApplication.TransientGeometry
    
    ' Define the distance between the eye and target.
    Dim eyeDistance As Double: eyeDistance = 1
    
    ' Set the eye with a hard coded z value.
    cam.ViewOrientationType = kFrontViewOrientation
    cam.Eye = tg.CreatePoint(CameraPosX, CameraPosY, eyeDistance)
    cam.Target = tg.CreatePoint(CameraPosX, CameraPosY, 0)
    
    ' Define the up vector as positive z.
    cam.UpVector = tg.CreateUnitVector(0, 0, 0)
    
    'Dim cameraOr As ViewOrientationTypeEnum
    'cameraOr = kFrontViewOrientation
    
    'Call cam.SetExtents(CameraPosX + 10, CameraPosY + 10)
    
    ' Apply the current camera definition to the view.
    cam.ApplyWithoutTransition

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Accepted solutions (1)
945 Views
4 Replies
Replies (4)
Message 2 of 5

asiteur
Collaborator
Collaborator

Hi,

 

I do not completely understand what you want to do, but there are some things in your code that don't work I think:

 

1) You set cam,Eye.Z=1. I have had only trouble when I changed the Z. I always maintain cam.Eye.Z=point(X,Y,cam.Eye.Z)

2) You set cam.UpVector to the Null vector. If I were the program I would have a hard time to interpret that. When I did this I couldn't find my drawing back on the screen. Use the default (0,1,0) or don't change at all if you don't want to rotate your sheet (likely).

3) You send SetExtents() , Target and Eye the same X and Y (almost), while there are very different. Target and Eye are for the location, SetExtents for the Zoom (how close you are to the object). I think it is unlikely that you want to zoom the same amount as the location you are...?

4) You use cam.ApplyWIthOutTransition, while from your description I read that you want a nice smooth pan/zoom movement. That is achieved with the normal cam.Apply.

 

I hope this helps!

 



Alexander Siteur
Project Engineer at MARIN | NL
LinkedIn

0 Likes
Message 3 of 5

CadUser46
Collaborator
Collaborator

Hi.  I tried to reply earlier but it crashed.

 

I got it to work although I didn't understand why.

 

1)  I don't understand what you mean.

2)  No I don't want to rotate the sheet, you are correct and I removed this.

3)  I don't understand the purpose of the Z value if it does not define the distance from the sheet.  It seems to have no effect on the code.

4)  Sorry for the confusion.  I just meant I want to zoom in.  The transition is not important.

 

The following code works for me although I still haven't fully grasped why.

 

    ' Get the active camera.
    Dim cam As Camera: Set cam = ThisApplication.ActiveView.Camera
    Dim tg As TransientGeometry: Set tg = ThisApplication.TransientGeometry
    
    ' Set the eye with a hard coded z value.
    cam.ViewOrientationType = kFrontViewOrientation
    cam.Eye = tg.CreatePoint(CameraPosX, CameraPosY, 5)
    cam.Target = tg.CreatePoint(CameraPosX, CameraPosY, 0)
    
    Call cam.SetExtents(CameraPosX, CameraPosY)
    Call oDoc.SelectSet.Clear
    Call oDoc.SelectSet.Select(MyBalloon)
    
    ' Apply the current camera definition to the view.
    cam.ApplyWithoutTransition

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Message 4 of 5

adam.nagy
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

I think it would be useful for you to read through these couple of posts on this topic:

http://modthemachine.typepad.com/my_weblog/2013/09/working-with-cameras-part-1.html

http://modthemachine.typepad.com/my_weblog/2013/09/working-with-cameras-part-2.html

 

Because the Drawing View camera has a parallel view (and not perspective) therefore the distance between the target and eye does not change the field-of-view.

 

When calling SetExtents() you should pass in width and height of the field-of-view. You should probably check the extents of the object you want to zoom on and use the values from that.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 5 of 5

CadUser46
Collaborator
Collaborator

@adam.nagy Thanks.  Certainly explains the upvector better than the help file and explains why the distance between the target and eye makes no difference when in rectangular mode.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes