【问题标题】:Capture Macro in Catia 5在 Catia 5 中捕获宏
【发布时间】:2019-02-20 15:42:11
【问题描述】:

我需要在 Catia 5 中编写一个宏。我的目标是将 cgm 文件转换为所需背景颜色和所需分辨率的 png。手动我是通过 Capture->image->options(设置分辨率和背景颜色)-> 另存为 .

我需要通过宏来做。

我可以使用 CATIA.StartCommand "Capture" 打开 Capture 窗口 但无法继续进行。我该如何继续?

提前致谢。

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

【问题讨论】:

  • 您检查过 CATIA 自动化文档吗?如果没有,请检查关键字 CaptureToFile 和 Get / PutBackgroundColor
  • @ferdo 您好,感谢您的回答。您回答的问题是我们无法调整分辨率。
  • 你还有 CatPrintQuality 和 Viewer (Object)
  • @ferdo 非常感谢您的帮助。我会在星期一试试。很棒的信息。
  • @ferdo 您好,我刚刚尝试过 CatPrintQuality,但无法做到。你能具体输入我如何将命令准确地写入宏吗?

标签: macros capture image-capture catia visual-studio-macros


【解决方案1】:

不幸的是,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 模式会过度压缩图片,无法使用。如果在交互式会话中启用了指南针,则在使用此宏捕获的图片中可以看到指南针。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多