×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

CATScript - How to use Camera in Product

CATScript - How to use Camera in Product

CATScript - How to use Camera in Product

(OP)
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

RE: CATScript - How to use Camera in Product

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

https://picasaweb.google.com/102257836106335725208

RE: CATScript - How to use Camera in Product

(OP)
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

RE: CATScript - How to use Camera in Product

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources