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:
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”
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.
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).
We need to close our If Then statement from before and end the program as usual.
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.