首页 文章

如何通过VBA改变FTA中TXT和尺寸的位置

提问于
浏览
0

我有小问题,有没有人知道如何使用短宏更改现有尺寸和部件/产品中的注释的位置 .

我将简要介绍一下我想做什么以及我遇到了什么样的问题 .

  • 我有简单的模型(比方说矩形)

  • 在此模型中,我在FTA中创建了尺寸和注释 .

  • 下一步是彻底改变这个模型的位置(基点模型在点0,0,0,我希望将它的位置改为150,10000,80旋转)
    在此更改期间

  • 某些尺寸和注释(他们在3D中的位置)在几何图形之后并未完全跟随 .

因此,我希望在部件更新后使用简单的宏来创建尺寸和注释的新位置 .

我已经执行了一些简单的测试代码

我注意到的是,当我设置文本的新位置时:

  • 理论上文本改变位置但在3D中它保持在旧位置 .

  • 通过双击编辑我的文本然后单击确定我的文本将转换为之前在宏中设置的新位置 . 同样的情况是当我想改变文本或内容的框架(我有AAA并且我想要BBB)时,它只有在我打开文本编辑器时才会改变 .

Set part1 = CATIA.ActiveDocument
Set Selection = part1.Selection
Set VisPropertySet = Selection.VisProperties

Selection.Search ("name='Text.1',all")

' get selected annotation here
Dim anAnnotation As Annotation
Set anAnnotation = CATIA.ActiveDocument.Selection.Item(1).Value

' get annotation on the DrawingText interface
Dim txtAnnotation As DrawingText
Set txtAnnotation = anAnnotation.Text.Get2dAnnot()

' get TPS view that contains annotation on the DrawingView interface
Dim vwTPSView As DrawingView
Set vwTPSView = txtAnnotation.Parent.Parent

' get coordinates on a view
Dim dX ' as Double
txtAnnotation.X = 0
 txtAnnotation.Y = 30

txtAnnotation.FrameType = catEllipse

part1.Update

End Sub

1 回答

  • 0

    通常使用 Part.Update 刷新注释的位置和文本,但您也可以使用:

    Dim anAnnotation As Annotation
    'Code here
    anAnnotation.ModifyVisu 'This should work for both Texts and Dimensions
    

    但是,如果上述方法不起作用,您可以尝试重新复制注释上的文本(它仅适用于文本,而不适用于维度)

    Dim vwTPSView As DrawingView
    'Code here
    vwTPSView.Text = vwTPSView.Text
    

    但要注意这最后的方法 . 如果您的文本中包含任何参数或变量,则替换文本将清除它 .

相关问题