Reputation: 115
I need to write a macro in Catia 5. My aim is to convert cgm files to png at the desired background color and at desired resolution. Manually I am doing it by Capture->image->options(setting resolution and background color)-> save as .
I need to do it by macro.
I can open the Capture window with CATIA.StartCommand "Capture" but can not proceed furthermore. How can I proceed?
Thanks in advance.
HOW WE CAN USE COMMANDS WHICH ARE GIVEN IN OBJECT BROWSER IN MACRO? I AM DIRECTLY WRITING IT BUT DOES NOT WORK.
Upvotes: 0
Views: 2094
Reputation: 19
Unfortunately, the Capture command does not seem to be available through the macro API. I've successfully used this workaround, however:
Sub CaptureViewport(strFileName As String, Optional intWidth As Integer = 1024, Optional intHeight As Integer = 1024)
Dim objWindow As SpecsAndGeomWindow
Dim objViewer As Variant ' Viewer3D
Dim objCamera As Camera3D
Dim objViewpoint As Variant ' Viewpoint3D
Dim arrOldBackgroundColor(2) As Variant
Dim intOldRenderingMode As CatRenderingMode
Dim intOldLayout As CatSpecsAndGeomWindowLayout
Set objWindow = CATIA.ActiveWindow
Set objCamera = CATIA.ActiveDocument.Cameras.Item(1)
Set objViewer = objWindow.ActiveViewer
Set objViewpoint = objViewer.Viewpoint3D
objViewer.GetBackgroundColor arrOldBackgroundColor
intOldRenderingMode = objViewer.RenderingMode
intOldLayout = objWindow.Layout
' This might be extended to record the old window dimensions as well
objViewer.FullScreen = False
objViewer.PutBackgroundColor Array(1, 1, 1) ' White
objViewer.RenderingMode = catRenderShadingWithEdges
objWindow.Layout = catWindowGeomOnly
objWindow.Width = intWidth
objWindow.Height = intHeight
objViewpoint.PutSightDirection Array(-1, -1, -1) ' Isometric
objViewpoint.PutUpDirection Array(0, 0, 1)
objViewpoint.ProjectionMode = catProjectionCylindric ' Parallel projection
objViewer.Reframe
' Without this, the picture is not always sized correctly
CATIA.RefreshDisplay = True
objViewer.Update
objViewer.CaptureToFile catCaptureFormatBMP, strFileName
CATIA.RefreshDisplay = False
objViewer.PutBackgroundColor arrOldBackgroundColor
objViewer.RenderingMode = intOldRenderingMode
objWindow.Layout = intOldLayout
' This might be extended to restore the old window dimensions as well
End Sub
It works by temporarily changing the background color (among other things, such as spec. tree visibility, rendering mode and camera settings) and by using the CaptureToFile
method. By changing the window size, you also change the dimensions of the captured image. Unfortunately, it cannot capture to PNG format (even though the interactive Capture tool can). This version instead captures to BMP. The JPEG mode compresses the picture beyond reason and is unusable. The compass will be visible in the pictures captured with this macro, if it is enabled in the interactive session.
Upvotes: 0