Search code examples
vbadrawingcatia

Change cut view text in CATIA


I'm currently working with CATIA V5, and I want to use Macros (VBA), but I have some problems!

My question is: how to change the text of a cut view? (see the picture)

enter image description here

I tried to use : myView.Texts.item(1) to access to this "text" but I think that CATIA dont consider it as text...

I want to change this text without the intervention of the user ( without selections), can I do that?


Solution

  • IME, VBA scripting in drafting workbench is quite tricky at first..."MyTexts" is a collection of DrawingText objects.

    MyDrawingText.Text = "MyNewTextValue"
    

    The main trouble you will have is getting a handle on the specific text object that you want to modify. I found that the best way around this is to either scan the entire DrawingTexts collection in the DrawingView, and apply a unique name, DrawingText.Name="UniqueObjectName", or you create the drawing text from the script and you can more easily get a handle on the DrawingText object to put whatever value you want in there. Creating Unique Names makes your drawing more robust for future scripting

    MyView.Texts.Count will also be useful to get the item number if the last created DrawingText object(s).

    I'm happy to further explain if you need. Good luck!

    Update/Edit: As mentioned above, scripting with the drafting workbench is not always straight forward. It turns out that the callout texts do not exactly live in the DrawingTexts collection of a DrawingView, but they do live somewhere inside the drawing view...In this case, you're trying to edit the "ID" of the section view..That property isn't exposed through VBA either.

    There is a hack/work-around which is to search the parent view for drawing texts and and then with some logic, which you'll need to come up with, scan the Selection for the texts you want to change. You should rename then while you're at it, this way it's easier to come back and find them again.

    Here's an example starting with an Object Resolution of the Front View (the parent view of the section view)

    Sub ChangeCallout()
    
    '---- Begin resolution script for object : Front View
    
    Dim drawingDocument1 As DrawingDocument
    Set drawingDocument1 = CATIA.ActiveDocument
    
    Dim drawingSheets1 As DrawingSheets
    Set drawingSheets1 = drawingDocument1.Sheets
    
    Dim drawingSheet1 As DrawingSheet
    Set drawingSheet1 = drawingSheets1.Item("Sheet.1")
    
    Dim drawingViews1 As DrawingViews
    Set drawingViews1 = drawingSheet1.Views
    
    Dim drawingView1 As DrawingView
    Set drawingView1 = drawingViews1.Item("Front view") 'this is the parent view of the section view
    
    '---- End resolution script
    
    Dim sel As Selection
    Set sel = drawingDocument1.Selection
    Dim CalloutText As drawingText
    
    sel.Clear 'clear the selection / good practice
    sel.Add drawingView1 'add the parent view to the selection
    sel.Search "Drafting.Text,sel" 'this will search the current selection for all drawing texts and add them to the selection
    
    Dim thing As Variant
    Dim i As Integer
    For i = 1 To sel.Count
        Set thing = sel.Item2(i)
        Set CalloutText = thing.Value
        'do some things/logic here to determine if this is a callout with some Ifs or Case statements
        'CalloutText.Name = "Useful Unique Name"
        'CalloutText.Text = "New Callout Label" 'whatever you want to rename it to
    Next
    
    End Sub