首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Catia 5捕获宏

Catia 5捕获宏
EN

Stack Overflow用户
提问于 2019-02-20 15:42:11
回答 1查看 1.2K关注 0票数 0

我需要在Catia 5中编写一个宏,我的目标是将cgm文件转换为png,具有所需的背景色和所需的分辨率。手动我是这样做的捕获->图像->选项(设置分辨率和背景色)->保存为。

我需要用宏来做。

我可以用CATIA.StartCommand“捕获”打开捕获窗口,但不能继续下去。我该怎么做?

提前谢谢。

如何在宏中使用对象浏览器中给出的命令?我是直接写的,但没有用。

EN

回答 1

Stack Overflow用户

发布于 2019-06-01 00:09:04

不幸的是,捕获命令似乎无法通过宏API获得。不过,我已经成功地使用了这个解决办法:

代码语言:javascript
复制
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模式压缩图片超出了合理的范围,是不可用的。如果在交互式会话中启用了指南针,则该指南针将在此宏捕获的图片中可见。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54790103

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档