durga_abishek_
Mechanical
- Jul 28, 2023
- 3
Greetings!!
I need help in refining of my Catia Macro where it searches the given input text and highlight them as red
1.in my case suppose i have a text in drawing as Engineeringstandards ,my input text is standards
when i run the macro it highlights the entire Engineeringstandards words not the specific words given in the input
please help me on this
2.this works only for the first sheet not the activated sheet
please help me to resolve the above issues
here is the code
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
regards
abishek
I need help in refining of my Catia Macro where it searches the given input text and highlight them as red
1.in my case suppose i have a text in drawing as Engineeringstandards ,my input text is standards
when i run the macro it highlights the entire Engineeringstandards words not the specific words given in the input
please help me on this
2.this works only for the first sheet not the activated sheet
please help me to resolve the above issues
here is the code
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
regards
abishek