我需要在Catia 5中编写一个宏,我的目标是将cgm文件转换为png,具有所需的背景色和所需的分辨率。手动我是这样做的捕获->图像->选项(设置分辨率和背景色)->保存为。
我需要用宏来做。
我可以用CATIA.StartCommand“捕获”打开捕获窗口,但不能继续下去。我该怎么做?
提前谢谢。
如何在宏中使用对象浏览器中给出的命令?我是直接写的,但没有用。
发布于 2019-06-01 00:09:04
不幸的是,捕获命令似乎无法通过宏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格式(即使交互式捕获工具可以)。这个版本反而捕获到BMP。JPEG模式压缩图片超出了合理的范围,是不可用的。如果在交互式会话中启用了指南针,则该指南针将在此宏捕获的图片中可见。
https://stackoverflow.com/questions/54790103
复制相似问题