Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Problem with capture macro

Status
Not open for further replies.

FabienF

New member
Jul 5, 2017
19
0
0
FR
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
 
Replies continue below

Recommended for you

Hi,

Your macro is working with small corrections

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.[COLOR=#EF2929]Item(1)[/color]
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 = [COLOR=#EF2929]"c:\Temporary\"[/color]
Dim extension As String
extension = ".jpg"
Dim Name as string
Name= filelocation & "right" & extension
viewer3D1.Viewpoint3D =camera3D1.Viewpoint3D
CATIA.ActiveDocument.Selection.Clear()
viewer3D1.Capturetofile [COLOR=#EF2929]5,Name[/color]

Dim camera3D2 As Camera
Set camera3D2 = cameras1.[COLOR=#EF2929]Item(2)[/color]
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 [COLOR=#EF2929]5,Name[/color]
End Sub

Regards
Fernando

- Romania
- EU
 
for whatever reason :
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:
For Each mycamera In cameras1
    If mycamera.Name() = "Camera 2" Then
        Set camera3D2 = mycamera
        Exit For
    End If
Next

not sure if this works for CATScript but I know it's OK for CATVBA

Eric N.
indocti discant et ament meminisse periti
 
@ Fabien:

you should open a SR (bug report) to DS about the method Cameras.Item not working properly, see if they fix it.

Eric N.
indocti discant et ament meminisse periti
 
However, using the command objviewer3D.Capturetofile 4,strname gives a poorer image quality than rendering would do. Is there any way to access the Photo Easy Tools of CATIA V5 with a macro?
Thanking you in advance for your help.
 
The problem is that using capturetofile is like doing a screen shot, whether it be of good quality in tiff bmp, etc or not, it does not have textures for example or render, just like Photo Easy Tools would do.
Am i wrong?
thank you
 
Status
Not open for further replies.
Back
Top