Problem with capture macro
Problem with capture macro
(OP)
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





RE: Problem with capture macro
Your macro is working with small corrections
CODE --> CATScript
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: Problem with capture macro
CODE -->
Set camera3D2 = cameras1.Item("Camera 2")is not working
you can go the hard way by doing for each mycamera in cameras1 and check mycamera.name
CODE --> this
For Each mycamera In cameras1 If mycamera.Name() = "Camera 2" Then Set camera3D2 = mycamera Exit For End If Nextnot sure if this works for CATScript but I know it's OK for CATVBA
indocti discant et ament meminisse periti
RE: Problem with capture macro
indocti discant et ament meminisse periti
RE: Problem with capture macro
you should open a SR (bug report) to DS about the method Cameras.Item not working properly, see if they fix it.
indocti discant et ament meminisse periti
RE: Problem with capture macro
Don't load from phone, 20 Mb video file.
https://res.cloudinary.com/engineering-com/video/upload/v1502300449/tips/Camera_zs0dic.mp4
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: Problem with capture macro
RE: Problem with capture macro
Thanking you in advance for your help.
RE: Problem with capture macro
CaptureToFile 4 is jpg
You can search in documentation for tiff or other format.
Capturing is done according to what settings you have in Photo Capturing Tools as I remember.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: Problem with capture macro
Am i wrong?
thank you
RE: Problem with capture macro
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: Problem with capture macro
RE: Problem with capture macro
EasyRenderOff
EasyRenderOn
Change rendering style per object
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: Problem with capture macro
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU