Catia V5 Macro - Efficient Drawing String Replacement

Catia V5 Macro - Efficient Drawing String Replacement

Please read Liability Disclaimer and License Agreement CAREFULLY

Looking for a powerful and efficient solution to automate the tedious task of replacing strings in Catia V5 drawings?

Look no further than my Catia V5 Macro for string replacement!

This easy-to-use tool streamlines your workflow by allowing you to quickly and accurately replace any string in your drawings with just a few clicks.

Replace String VBA Form

Create a form and name it "ReplaceString", change the back color to "&H00BDE7FF&".

Add TextBox1 with property "Text" set to "Text To Find"

Add TextBox2 with property "Text" set to "Replacing Text"

Add CheckBox1 with "BackColor" set to "&H00BDE7FF&" and "Caption" set to "Case Sensitive"

Add on Button with "Name" set to "OkBtn"

Option Explicit
Dim DrwDoc As DrawingDocument
Dim Sheet As DrawingSheet
Dim View As DrawingView
Dim txt As DrawingText
Private Sub OkBtn_Click()
    Dim aString As String
    Dim Count As Integer
    Dim cTxt As Integer
    Count = 0
    cTxt = 0
    For Each Sheet In DrwDoc.Sheets
        For Each View In Sheet.Views
            If View.Texts.Count > 0 Then
                For Each txt In View.Texts
                    cTxt = cTxt + 1
                    If CheckBox1.Value Then
                        If InStr(txt.Text, TextBox1.Text) Then
                            aString = Replace(txt.Text, TextBox1.Text, TextBox2.Text)
                            txt.Text = aString
                            Count = Count + 1
                        End If
                        If InStr(VBA.UCase(txt.Text), VBA.UCase(TextBox1.Text)) Then
                            aString = Replace(VBA.UCase(txt.Text), VBA.UCase(TextBox1.Text), TextBox2.Text)
                            txt.Text = aString
                            Count = Count + 1
                        End If
                    End If
            End If
    MsgBox "The Macro has finish the job" & VBA.Chr(13) & _
    Count & " replacements performed on " & cTxt & " texts processed", vbOKOnly, "GVI Replace String"
    Unload Me
End Sub
Private Sub UserForm_Initialize()
    Set DrwDoc = CATIA.ActiveDocument
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    Set txt = Nothing
    Set View = Nothing
    Set Sheet = Nothing
    Set DrwDoc = Nothing
End Sub

Replace String Project Structure

Create a Module called "StrReplace" and add the following code in it

Sub CATMain()
    If TypeName(CATIA.ActiveDocument) <> "DrawingDocument" Then
        MsgBox "Copyright © 2004 Grozea Ion" & VBA.Chr(13) & "This Macro runs only on Drawings!!!" & VBA.Chr(13) & _
        "Please load or activate one."
        Exit Sub
        MsgBox "Copyright © 2004 Grozea Ion" & VBA.Chr(13) & "Be aware that the string format will be lost on" & VBA.Chr(13) & _
        "the texts replaced. Do not forget to format the text Font/Size...", vbExclamation
    End If
End Sub





Comments powered by CComment

Who’s online

We have 128 guests and no members online