SIRIKONDAbishek
Student
I did a Catia macro where it searches the given input text and highlighted them as red in the drawing sheet
below is the macro in that I need to refine the macro to my requirement
my requirement is to highlight only the given text words,but the macro is highlighting the entire text
suppose my input text is engineer the text present in drawing is engineering it should make engineer as red not the rest of the letters ing
please help me on this
Sub CATMain()
' Set the CATIA popup file alerts to False
' It prevents the macro from stopping at each alert during its execution
CATIA.DisplayFileAlerts = False
Set oDrwDocument = CATIA.ActiveDocument
Dim InsertText As String
Dim TextFound As Boolean
InsertText = InputBox("Insert Text")
' Check if the user clicked the "Cancel" button or provided an empty input
If InsertText = "" Then
MsgBox "No input provided. Macro will now exit.", vbExclamation
Exit Sub
End If
TextFound = False
' Retrieve the drawing document's view collection
Set oDrwView = oDrwDocument.Sheets.Item(1).Views
' Loop through each view and check for the input text
For i = 1 To oDrwView.Count
' Loop through all the texts of the view
For numtxt = 1 To oDrwView.Item(i).Texts.Count
Set CurrentText = oDrwView.Item(i).Texts.Item(numtxt)
' Check if the text matches the input text
If InStr(1, CurrentText.Text, InsertText, vbTextCompare) > 0 Then
' Change the color of the matched text to RED
Set DrwSelect = CATIA.ActiveDocument.Selection
DrwSelect.Clear
DrwSelect.Add CurrentText
DrwSelect.VisProperties.SetRealColor 255, 0, 0, 0
' Set TextFound to true since we found at least one matching text
TextFound = True
End If
Next 'numtxt
Next 'i
CATIA.ActiveWindow.ActiveViewer.Reframe
' Check if any text was found and show a message accordingly
If TextFound Then
MsgBox "Text containing '" & InsertText & "' has been highlighted in RED.", vbInformation
Else
MsgBox "No text containing '" & InsertText & "' found.", vbExclamation
End If
End Sub
Best regards !!
below is the macro in that I need to refine the macro to my requirement
my requirement is to highlight only the given text words,but the macro is highlighting the entire text
suppose my input text is engineer the text present in drawing is engineering it should make engineer as red not the rest of the letters ing
please help me on this
Sub CATMain()
' Set the CATIA popup file alerts to False
' It prevents the macro from stopping at each alert during its execution
CATIA.DisplayFileAlerts = False
Set oDrwDocument = CATIA.ActiveDocument
Dim InsertText As String
Dim TextFound As Boolean
InsertText = InputBox("Insert Text")
' Check if the user clicked the "Cancel" button or provided an empty input
If InsertText = "" Then
MsgBox "No input provided. Macro will now exit.", vbExclamation
Exit Sub
End If
TextFound = False
' Retrieve the drawing document's view collection
Set oDrwView = oDrwDocument.Sheets.Item(1).Views
' Loop through each view and check for the input text
For i = 1 To oDrwView.Count
' Loop through all the texts of the view
For numtxt = 1 To oDrwView.Item(i).Texts.Count
Set CurrentText = oDrwView.Item(i).Texts.Item(numtxt)
' Check if the text matches the input text
If InStr(1, CurrentText.Text, InsertText, vbTextCompare) > 0 Then
' Change the color of the matched text to RED
Set DrwSelect = CATIA.ActiveDocument.Selection
DrwSelect.Clear
DrwSelect.Add CurrentText
DrwSelect.VisProperties.SetRealColor 255, 0, 0, 0
' Set TextFound to true since we found at least one matching text
TextFound = True
End If
Next 'numtxt
Next 'i
CATIA.ActiveWindow.ActiveViewer.Reframe
' Check if any text was found and show a message accordingly
If TextFound Then
MsgBox "Text containing '" & InsertText & "' has been highlighted in RED.", vbInformation
Else
MsgBox "No text containing '" & InsertText & "' found.", vbExclamation
End If
End Sub
Best regards !!