CATIA - 如何使用宏将 CATPart 编号和名称获取到绘图中的文本编辑器中

CATIA - how to get CATPart number and name into text editor in drawing using macro

我想请人帮忙。我正在尝试在 CATIA 中创建一个宏。宏应该使用带有按钮的用户窗体。单击按钮后,它会自动在文本字段中填写数据(零件名称+零件编号)。 我想指出,我是 VBA 脚本的新手。 谁能帮忙? 非常感谢

Private Sub CommandButton1_Click()

将 DrwDocument 调暗为 DrawingDocument 设置 DrwDocument = CATIA.ActiveDocument

Set DrwSheets = DrwDocument.Sheets
Set Selection = DrwDocument.Selection
Set DrwSheet = DrwSheets.ActiveSheet
Set DrwView = DrwSheet.Views.ActiveView
Set DrwTexts = CATIA.ActiveDocument.Sheets.ActiveSheet.Views.ActiveView.Texts


Dim parameters4 As Parameters
Set parameters4 = DrwDocument.Parameters

Dim realParam4 As Parameter
Set realParam4 = parameters4.Item("Sheet.1\ViewMakeUp.3\Scale")

DrwView.Activate
    Set Projekt = DrwTexts.Add(tbProjekt.Text, (288), (45.5))
    Projekt.AnchorPosition = catMiddleLeft
    Projekt.SetFontName 0, 0, "Monospac821 BT"
    Projekt.SetFontSize 0, 0, 3
    
    Set PocetKs = DrwTexts.Add(tbPocetKs.Text + "x", (36), (78))
    PocetKs.AnchorPosition = catMiddleLeft
    PocetKs.SetFontName 0, 0, "Monospac821 BT"
    PocetKs.SetFontSize 0, 0, 3
    
        If OptionZrk = True Then
            Set PocetKsZrk = DrwTexts.Add(tbPocetKs.Text + "x", (36),(70))
            PocetKsZrk.AnchorPosition = catMiddleLeft
            PocetKsZrk.SetFontName 0, 0, "Monospac821 BT"
            PocetKsZrk.SetFontSize 0, 0, 3
            
            Set ZrkText = DrwTexts.Add("Zrkadlový", (102), (80))
            ZrkText.AnchorPosition = catMiddleLeft
            ZrkText.SetFontName 0, 0, "Monospac821 BT"
            ZrkText.SetFontSize 0, 0, 3
            
        End If
 
    Set Material = DrwTexts.Add(cbMaterial.Text, (288), (37.5))
    Material.AnchorPosition = catMiddleLeft
    Material.SetFontName 0, 0, "Monospac821 BT"
    Material.SetFontSize 0, 0, 3
    
    Set Mierka = DrwTexts.Add(realParam4.ValueAsString, (238), (40))
    Mierka.AnchorPosition = catMiddleLeft
    Mierka.SetFontName 0, 0, "Monospac821 BT"
    Mierka.SetFontSize 0, 0, 3
    
    Set DatumUpravy = DrwTexts.Add(tbDatum.Text, (355), (38))
    DatumUpravy.AnchorPosition = catMiddleLeft
    DatumUpravy.SetFontName 0, 0, "Monospac821 BT"
    DatumUpravy.SetFontSize 0, 0, 3
    
    

结束子

通过视图的 GenerativeBehavior,您可以获得显示的产品。

dim oProduct as Product
Set oProduct = DrwView.GenerativeBehavior.Document

MsgBox CStr(oProduct.PartNumber)
MsgBox CStr(oProduct.Nomenclature)

确保视图具有 link 到 geometry/product