Screen Shot Macro
How to take a screen shot picture using a CATScript macro
After learning how to setup your macros you can begin to write useful code. One helpful code to create that is easy to make but looks impressive to others is to take a screen shot of whatever is shown on your CATIA window and export it to an image format using a CATScript macro. I’ll highlight each line of code and explain what it does, step-by-step.
Our CATScript begins with:
Sub CatMAIN()
Next, we set the active window as the active viewer.
Dim ObjViewer3D As Viewer3D
Set objViewer3D = CATIA.ActiveWindow.ActiveViewer
Now we need to access one of the “Camera” objects from the current document. A camera object in CATIA is a static version of the window viewer object.
Dim objCamera3D As Camera3D
Set objCamera3D = CATIA.ActiveDocument.Cameras.Item(1)
Let’s create an Input box to name the screen capture image file. Then we’ll need and If Then statement to abort the operation if no name is entered.
Dim partname As String
partName = Inputbox (“Please name the image.”)
If partName=”" Then
MsgBox “No name entered”, vbExclamation, “Cancel Pressed”
Else
We need to specify a location to save the image file. Here I’ve chosen “C:\Macro Files\”
‘file location to save image
Dim fileloc As String
fileloc = “C:\Macro Files\”
I want my image to be exported as a .png file so I will create a variable specifying the extension name of the image.
Dim exten As String
exten = “.png”
My image file will be saved as the input box name plus the file extension and will be saved in the folder I specified earlier.
Dim strName as string
strname = fileloc & partName & exten
Set the 3Dviewer viewpoint to the camera viewpoint.
objViewer3D.Viewpoint3D = objCamera3D.Viewpoint3D
Clear the selection for picture.
CATIA.ActiveDocument.Selection.Clear()
I will also increase CATIA to full screen mode in order to obtain maximum resolution.
objViewer3D.FullScreen = True
Finally, using the viewer we can now export the 3D window into a picture format (BMP, TIFF, CGM, EMF, or TIFFGreyScale).
objviewer3D.Capturetofile 4,strname
We need to close our If Then statement from before and end the program as usual.
End If
End Sub
Embedded below is a Catia video tutorial of the end result. If you’re following along you should get the same result.
Now you know how to take a screen shot in CATIA using a CATScript macro. To make your picture even better you can automate other processes such as: turning the compass off, hiding the specification tree, turning the background to white, automatically reframe, zoom in or out, and more. You can even export your image capture directly to Power Point. This is helpful for car design in Catia. Purchase VB Scripting for CATIA V5 to get the complete example code and learn how to do all of these processes.





I would like to use the exact steps of this macro but with the export tool.
What i had in mind are the following:
-read the file name
-read the number of sheets (excluding detail sheet)
-”save as” each page with name_(number of page).jpg in a folder of my choosing
Any hints would be appreciated. Thanks.
Hi Mark. What do you mean by export tool and number of sheets? Like with a drawing file? Reading the file name and saving as are easy enough and there are examples of how to do that within this website.
-Emmett
I wasnt able to find the exact examples but this is what i meant:
- when you “Save as” in the Drafting module as a Jpg file it saves the current selected sheet as a picture.
- what i want to do is to find a macro that takes all the sheets from a drafting file and saves them with the same name and a certain identification _1 _2 _etc.
hello,
This CATScript macros works but it can make a screen shot only from one point of view and the background is not white. How can I set up the point of view or to make screen shots using the actual view?
Thank you
Hi Aleksandar,
The complete code for the screen capture macro is included in my book and macro pack download. To change the background to white:
Dim DBLBackArray(2)
objViewer3D.GetBackgroundColor(dblBackArray)
Dim dblWhiteArray(2)
dblWhiteArray(0)=1
dblWhiteArray(1)=1
dblWhiteArray(2)=1
objViewer3D.PutBackgroundColor(dblWhiteArray)
To reframe:
objViewer3D.Reframe()
Iso view:
objViewer3D.Viewpoint3D=objCamera3D.Viewpoint3D