FabienF
New member
- Jul 5, 2017
- 19
Hello,
Can someone help me with this code please? I am trying to get 2 images (captures) of the same product in two different positions (camera 1 and camera 2). I have created manually two cameras in the positions I wanted to take the captures and after some researches on the net (+ macro recording) I came out with this code working well only for the first position(ie camera 1).The image is indeed saved for camera 1 but not for camera 2. Here is the code:
--------------------------------------------------------------------------------------------------------
Sub CATMain()
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
Dim cameras1 As Cameras
Set cameras1 = productDocument1.Cameras
Dim camera3D1 As Camera
Set camera3D1 = cameras1.Item("Camera 1")
Dim viewpoint3D1 As Viewpoint3D
Set viewpoint3D1 = camera3D1.Viewpoint3D
Dim specsAndGeomWindow1 As Window
Set specsAndGeomWindow1 = CATIA.ActiveWindow
Dim viewer3D1 As Viewer
Set viewer3D1 = specsAndGeomWindow1.ActiveViewer
viewer3D1.Viewpoint3D = viewpoint3D1
Set viewpoint3D1 = camera3D1.Viewpoint3D
viewer3D1.Viewpoint3D = viewpoint3D1
Dim filelocation As String
filelocation = "S:\"
Dim extension As String
extension = ".jpg"
Dim Name as string
Name= filelocation & "right" & extension
viewer3D1.Viewpoint3D =camera3D1.Viewpoint3D
CATIA.ActiveDocument.Selection.Clear()
viewer3D1.Capturetofile 4,Name
Dim camera3D2 As Camera
Set camera3D2 = cameras1.Item("Camera 2")
Dim viewpoint3D2 As Viewpoint3D
Set viewpoint3D2 = camera3D2.Viewpoint3D
viewer3D1.Viewpoint3D = viewpoint3D2
Set viewpoint3D2 = camera3D2.Viewpoint3D
viewer3D1.Viewpoint3D = viewpoint3D2
Name = filelocation & "left" & extension
viewer3D1.Viewpoint3D =camera3D2.Viewpoint3D
CATIA.ActiveDocument.Selection.Clear()
viewer3D1.Capturetofile 4,Name
End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------
Does anyone have an idea of why it is not working for camera 2 ?
Thanking you in advance for your help
Can someone help me with this code please? I am trying to get 2 images (captures) of the same product in two different positions (camera 1 and camera 2). I have created manually two cameras in the positions I wanted to take the captures and after some researches on the net (+ macro recording) I came out with this code working well only for the first position(ie camera 1).The image is indeed saved for camera 1 but not for camera 2. Here is the code:
--------------------------------------------------------------------------------------------------------
Sub CATMain()
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
Dim cameras1 As Cameras
Set cameras1 = productDocument1.Cameras
Dim camera3D1 As Camera
Set camera3D1 = cameras1.Item("Camera 1")
Dim viewpoint3D1 As Viewpoint3D
Set viewpoint3D1 = camera3D1.Viewpoint3D
Dim specsAndGeomWindow1 As Window
Set specsAndGeomWindow1 = CATIA.ActiveWindow
Dim viewer3D1 As Viewer
Set viewer3D1 = specsAndGeomWindow1.ActiveViewer
viewer3D1.Viewpoint3D = viewpoint3D1
Set viewpoint3D1 = camera3D1.Viewpoint3D
viewer3D1.Viewpoint3D = viewpoint3D1
Dim filelocation As String
filelocation = "S:\"
Dim extension As String
extension = ".jpg"
Dim Name as string
Name= filelocation & "right" & extension
viewer3D1.Viewpoint3D =camera3D1.Viewpoint3D
CATIA.ActiveDocument.Selection.Clear()
viewer3D1.Capturetofile 4,Name
Dim camera3D2 As Camera
Set camera3D2 = cameras1.Item("Camera 2")
Dim viewpoint3D2 As Viewpoint3D
Set viewpoint3D2 = camera3D2.Viewpoint3D
viewer3D1.Viewpoint3D = viewpoint3D2
Set viewpoint3D2 = camera3D2.Viewpoint3D
viewer3D1.Viewpoint3D = viewpoint3D2
Name = filelocation & "left" & extension
viewer3D1.Viewpoint3D =camera3D2.Viewpoint3D
CATIA.ActiveDocument.Selection.Clear()
viewer3D1.Capturetofile 4,Name
End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------
Does anyone have an idea of why it is not working for camera 2 ?
Thanking you in advance for your help