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

时间:2018-02-08 13:30:11

标签: vba dimensions catia

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

我将很快描述我想做什么以及我遇到了什么样的问题。

  1. 我有简单的模型(比方说矩形)
  2. 在此模型中,我有在FTA中创建的尺寸和注释。
  3. 下一步是彻底改变这个模型的位置(0,0,0点的基础模型,我希望将它的位置改为150,10000,80 +旋转)
  4. 在此更改期间,某些尺寸和注释(他们在3D中的位置)在几何图形之后并未完全跟随。
  5. 因此,我希望在部件更新后使用简单的宏来创建尺寸和注释的新位置。

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

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

    1. 理论上文字更改位置,但在3D中它保持原位。
    2. 通过双击编辑我的文本然后单击“确定”,我的文本将转换为之前在宏中设置的新位置。同样的情况是当我想改变文本或内容的框架时(我有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 :(得分: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

尽管如此,请注意这最后的方法。如果您的文本中包含任何参数或变量,则替换文本将清除它。