Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATScript - How to use Camera in Product 1

Status
Not open for further replies.

jmarkus

Mechanical
Jul 11, 2001
377
I have the following script which works in a CATPart, but not in a CATProduct. Why?

Code:
Sub CATMain()
Dim ActDoc As Document
Set ActDoc = CATIA.ActiveDocument
Dim camIsoView As Camera3D
Set camIsoView = ActDoc.Cameras.Item("* iso")
Dim objIsoViewPoint As Viewpoint3D
Set objIsoViewPoint = camIsoView.Viewpoint3D
Dim ActWin As Window
Set ActWin = CATIA.ActiveWindow
Dim ActViewer As Viewer3D
Set ActViewer = ActWin.ActiveViewer
ActViewer.Viewpoint3D = objIsoViewPoint
End Sub

Thanks,
Jeff
 
Replies continue below

Recommended for you

Hi,

For me is working, is OK. If you want something much more sophisticated here is an CATScript with a very small modification from DS documentation.

Sub CATMain()

' Parameters
Const Front = 0
Const Back = 1
Const Right = 2
Const Left = 3
Const Bottom = 4
Const Top = 5
Const Iso = 6
Const Custom = 7

Const Sight = 0
Const Up = 1

Const X = 0
Const Y = 1
Const Z = 2

Dim StdDirection(7,1,2)

StdDirection(Front , Sight, X) = 1.
StdDirection(Front , Sight, Y) = 0.
StdDirection(Front , Sight, Z) = 0.
StdDirection(Front , Up , X) = 0.
StdDirection(Front , Up , Y) = 0.
StdDirection(Front , Up , Z) = 1.

StdDirection(Back , Sight, X) = -1.
StdDirection(Back , Sight, Y) = 0.
StdDirection(Back , Sight, Z) = 0.
StdDirection(Back , Up , X) = 0.
StdDirection(Back , Up , Y) = 0.
StdDirection(Back , Up , Z) = 1.

StdDirection(Right , Sight, X) = 0.
StdDirection(Right , Sight, Y) = 1.
StdDirection(Right , Sight, Z) = 0.
StdDirection(Right , Up , X) = 0.
StdDirection(Right , Up , Y) = 0.
StdDirection(Right , Up , Z) = 1.

StdDirection(Left , Sight, X) = 0.
StdDirection(Left , Sight, Y) = -1.
StdDirection(Left , Sight, Z) = 0.
StdDirection(Left , Up , X) = 0.
StdDirection(Left , Up , Y) = 0.
StdDirection(Left , Up , Z) = 1.

StdDirection(Bottom, Sight, X) = 0.
StdDirection(Bottom, Sight, Y) = 0.
StdDirection(Bottom, Sight, Z) = 1.
StdDirection(Bottom, Up , X) = 0.
StdDirection(Bottom, Up , Y) = 1.
StdDirection(Bottom, Up , Z) = 0.

StdDirection(Top , Sight, X) = 0.
StdDirection(Top , Sight, Y) = 0.
StdDirection(Top , Sight, Z) = -1.
StdDirection(Top , Up , X) = 0.
StdDirection(Top , Up , Y) = 1.
StdDirection(Top , Up , Z) = 0.

StdDirection(Iso , Sight, X) = -1./ Sqr(3)
StdDirection(Iso , Sight, Y) = -1./ Sqr(3)
StdDirection(Iso , Sight, Z) = -1./ Sqr(3)
StdDirection(Iso , Up , X) = -1./ Sqr(6)
StdDirection(Iso , Up , Y) = -1./ Sqr(6)
StdDirection(Iso , Up , Z) = 2./ Sqr(6)

StdDirection(Custom, Sight, X) = 1./ Sqr(3)
StdDirection(Custom, Sight, Y) = 1./ Sqr(3)
StdDirection(Custom, Sight, Z) = -1./ Sqr(3)
StdDirection(Custom, Up , X) = 1./ Sqr(6)
StdDirection(Custom, Up , Y) = 1./ Sqr(6)
StdDirection(Custom, Up , Z) = 2./ Sqr(6)

' Engineering view do display
Dim iIndView As Integer
'~ iIndView = Custom ' <==== To be changed on the different macros ==== this is original line, you have to change Custom with what you want

iIndView = 6 ' <==== To be changed on the different macros ====

' Get the viewer
Dim oViewer As Viewer
Set oViewer = CATIA.ActiveWindow.ActiveViewer

' Get the viewpoint
Dim oViewpoint As Viewpoint3D
Set oViewpoint = oViewer.Viewpoint3D

' Get the current parameters
Dim Origin(2)
oViewpoint.GetOrigin Origin
Dim SightDirection(2)
oViewpoint.GetSightDirection SightDirection
Dim Focus As Double
Focus = oViewpoint.FocusDistance

' Compute the new parameters
Dim StdSightDirection(2)
Dim StdUpDirection(2)
Dim I As Integer
For I = 0 to 2
StdSightDirection(I) = StdDirection(iIndView,Sight,I)
StdUpDirection(I) = StdDirection(iIndView,Up,I)
Origin(I) = Origin(I) + Focus*(SightDirection(I) - StdSightDirection(I))
Next

' Change the viewpoint
oViewpoint.PutOrigin Origin
oViewpoint.PutSightDirection StdSightDirection
oViewpoint.PutUpDirection StdUpDirection
oViewpoint.ProjectionMode = catProjectionCylindric

' Update the viewer
oViewer.Update

Set oViewpoint = Nothing
Set oViewer = Nothing

Dim specsAndGeomWindow1 As Window
Set specsAndGeomWindow1 = CATIA.ActiveWindow

Dim viewer3D1 As Viewer
Set viewer3D1 = specsAndGeomWindow1.ActiveViewer

Dim viewpoint3D1 As Viewpoint3D
Set viewpoint3D1 = viewer3D1.Viewpoint3D

viewer3D1.Reframe
Set viewpoint3D1 = viewer3D1.Viewpoint3D
viewer3D1.ZoomIn
Set viewpoint3D1 = viewer3D1.Viewpoint3D
CATIA.StartCommand("Collapse all")

End Sub

Regards
Fernando

 
Thanks Fernando,

I went back and tried my script on some other CATProducts and it did work, but for one specific CATProduct it doesn't.

I tried your script and it worked for all of them.

Thanks again,
Jeff
 
Apparently, for some reason CATIA doesn't always like the

Code:
Cameras.Item("* iso")

So I just learned that is the same as

Code:
Cameras.Item(1)

And now mine works 'always' as well.

Thanks,
Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor