我需要在Catia 5中编写一个宏。我的目标是将cgm文件转换为所需的背景颜色和所需的分辨率。我手动通过Capture-> image-> options(设置分辨率和背景色)->另存为来执行此操作。
我需要通过宏来做。
我可以使用CATIA.StartCommand“ Capture”打开“捕获”窗口 但无法继续进行。我该怎么办?
谢谢。
我们如何使用宏中的对象浏览器提供的命令?我直接写却没用。
答案 0 :(得分:0)
不幸的是, Capture 命令似乎无法通过宏API使用。但是,我已经成功使用了这种解决方法:
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
它可以通过临时更改背景颜色(除其他功能外,例如,树的可见性,渲染模式和相机设置),还可以使用CaptureToFile
方法。通过更改窗口大小,您还可以更改捕获图像的尺寸。不幸的是,它不能捕获为PNG格式(即使交互式 Capture 工具可以捕获)。该版本将捕获到BMP。 JPEG模式会过度压缩图片,因此无法使用。如果在交互式会话中启用了指南针,则该指南针将显示在使用此宏捕获的图片中。