Problem when changing the settings of the active views camera
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to change the setting of the camera of the active view. However my settings will be applied only when setting them a second time on the camera. After the first time, the view is different from what i have set on the camera. See the attached script in order to reproduce the problem. The first call to SetCamera will not align the block correctly. Only after calling it a second time (comment in the second SetCamera call) the block is displayed correctly. Can somebody please explain to me what i am doing wrong?
Public Sub Main()
CreateBlock ("d:/block.ipt")
ThisApplication.Documents.Open ("d:/block.ipt")
' This does not set the camera as expected
SetCamera
' The second call finally sets the camera as expected
'SetCamera
End Sub
Public Sub SetCamera()
' Get the active camera.
Dim cam As Camera
Set cam = ThisApplication.ActiveView.Camera
Dim tg As TransientGeometry
Set tg = ThisApplication.TransientGeometry
Dim v As UnitVector
Set v = cam.UpVector
cam.UpVector = tg.CreateUnitVector(1, 0, 0)
cam.Eye = tg.CreatePoint(0, 0, 1)
cam.Target = tg.CreatePoint(0, 0, 0)
cam.ApplyWithoutTransition
End Sub
Public Sub CreateBlock(argStrFilename As String)
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oPartDoc As PartDocument
Set oPartDoc = oApp.Documents.Add(kPartDocumentObject, _
oApp.GetTemplateFile(kPartDocumentObject))
Dim oCompDef As PartComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition
Dim oTrans As TransientGeometry
Set oTrans = oApp.TransientGeometry
Dim oWorkPlanes As WorkPlanes
Set oWorkPlanes = oCompDef.WorkPlanes
Dim oMyWorkplane As WorkPlane
Set oMyWorkplane = oWorkPlanes.AddByPlaneAndOffset(oWorkPlanes(3), 10, True)
' Create sketch
Dim oMySketch As PlanarSketch
Set oMySketch = oCompDef.Sketches.Add(oMyWorkplane)
Dim firstRectPoint As Point2d
Set firstRectPoint = oTrans.CreatePoint2d(0, 0)
Dim secondRectPoint As Point2d
Set secondRectPoint = oTrans.CreatePoint2d(1, 1)
oMySketch.SketchLines.AddAsTwoPointRectangle firstRectPoint, secondRectPoint
Dim oMyProfile As Profile
Set oMyProfile = oMySketch.Profiles.AddForSolid
' Create the block
Dim oExtrudeDef As ExtrudeDefinition
Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oMyProfile, kJoinOperation)
Dim oExtrude As ExtrudeFeature
Set oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
oPartDoc.SaveAs argStrFilename, True
End Sub