This page has been translated for your convenience with an automatic translation service. This is not an official translation and may contain errors and inaccurate translations. Autodesk does not warrant, either expressly or implied, the accuracy, reliability or completeness of the information translated by the machine translation service and will not be liable for damages or losses caused by the trust placed in the translation service.
Translate
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
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.
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