TransientGeometry.CreatePoint gives Compile error: Argument Not Optional error

TransientGeometry.CreatePoint gives Compile error: Argument Not Optional error

Anonymous
Not applicable
781 Views
2 Replies
Message 1 of 3

TransientGeometry.CreatePoint gives Compile error: Argument Not Optional error

Anonymous
Not applicable

Hi all,

 

Trying to create my 1st Inventor Macro here. This is driving me crazy. I copied what I think is the offending code right from the "Mod the Machine" blog. Inventor/VBA is telling me Compile error: Argument Not Optional. Here is the entire Macro/Sub

 

Public Sub CopyCurrentIpnView()

Dim app As Application
Set app = ThisApplication
Dim exView As PresentationExplodedView
Dim baseView As view
Dim baseCamera, otherCam As Camera
Dim eye, target As Point
Dim upvector As UnitVector
Dim tg As TransientGeometry

baseCamera = app.ActiveView.Camera
tg = app.TransientGeometry
eye = tg.CreatePoint(baseCamera.eye.X, baseCamera.eye.Y, baseCamera.eye.Z)
target = tg.CreatePoint(baseCamera.target.X, baseCamera.target.Y, baseCamera.target.Z) 
upvector = tg.CreateUnitVector(baseCamera.upvector.X, baseCamera.upvector.Y, baseCamera.upvector.Z)

If app.ActiveDocument.DocumentType <> kPresentationDocumentObject Then
     MsgBox "Not a presentation project."
     Exit Sub
End If

For Each exView In app.ActiveDocument.PresentationExplodedViews
    exView.Activate
    otherCam = app.ActiveView.Camera
    otherCam.eye.X = eye.X
    otherCam.eye.Y = eye.Y
    otherCam.eye.Z = eye.Z
    otherCam.target.X = target.X
    otherCam.target.Y = target.Y
    otherCam.target.Z = target.Z
    otherCam.upvector.X = upvector.X
    otherCam.upvector.Y = upvector.Y
    otherCam.upvector.Z = upvector.Z
    otherCam.Apply
    otherCam.Fit
Next

End Sub

 

The Public Sub CopyCurrentIpnView() line gets highlighted in yellow but the "target =" gets selected, so I assume the error is near the "target =". But I get no other help to tell me what is wrong! I've slogged through documentation. Searched Google and Stackoverflow. I've tried putting Set in front of the tg, eye, target, and upvector assignments but that did not help.

 

I'm on Inventor 2012 Ultimate x64 with SP2 and OS is Win 7 Enterprise.

 

Any help is appreciated.

0 Likes
782 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Does this work?  I just started seperating the declarations and throwing "set" in front of a couple of assignment statements.  Happy Programming!

 

'CODE START------------------

 

Public Sub CopyCurrentIpnView()

    Dim app As Application
    Set app = ThisApplication
    Dim exView As PresentationExplodedView
    Dim baseView As View
    Dim baseCamera, otherCam As Camera
    Dim eye As Point
    Dim target As Point
    Dim upvector As UnitVector
    Dim tg As TransientGeometry
    
    Set baseCamera = app.ActiveView.Camera
    Set tg = app.TransientGeometry
    Set eye = tg.CreatePoint(baseCamera.eye.X, baseCamera.eye.Y, baseCamera.eye.Z)
    Set target = tg.CreatePoint(baseCamera.target.X, baseCamera.target.Y, baseCamera.target.Z)
    Set upvector = tg.CreateUnitVector(baseCamera.upvector.X, baseCamera.upvector.Y, baseCamera.upvector.Z)
    
    If app.ActiveDocument.DocumentType <> kPresentationDocumentObject Then
         MsgBox "Not a presentation project."
         Exit Sub
    End If
    
    For Each exView In app.ActiveDocument.PresentationExplodedViews
        exView.Activate
        Set otherCam = app.ActiveView.Camera
        otherCam.eye.X = eye.X
        otherCam.eye.Y = eye.Y
        otherCam.eye.Z = eye.Z
        otherCam.target.X = target.X
        otherCam.target.Y = target.Y
        otherCam.target.Z = target.Z
        otherCam.upvector.X = upvector.X
        otherCam.upvector.Y = upvector.Y
        otherCam.upvector.Z = upvector.Z
        otherCam.Apply
        otherCam.Fit
    Next

End Sub

0 Likes
Message 3 of 3

VoteCoffee
Explorer
Explorer
Well, it's 7 years late, but vba doesn't like: Dim someVar = someInstance You need to instead do: Dim someVar as basicType someVar = someInstance OR Dim someVar = complexType Set someVar = someInstance
0 Likes