Over 1.092.000 registered users (EN+CZ).
AutoCAD tips, Inventor tips, Revit tips.
Try the new precise Engineering calculator.
New AutoCAD 2026 commands and variables.
CAD tip # 14527:
Question
A
Use the following iLogic macro to easily search and bulk-replace arbitrary text in Inventor IDW or DWG drawings. You can use either regular expression mode or plain text string search/replace (see USEREGEX settings in line #2).
Text will be replaced in general notes, leader notes, dimensions, tables (except BOM/parts lists), title blocks and sketched symbols.
Create the following iLogic macro and run it on the active sheet in your Inventor drawing.
'Search/Replace drawing texts - 2025, www.cadforum.cz Class ReplaceClass Dim USEREGEX = True 'regular expressions, case sensitive OR plain substring, insensitive Dim repcount As Integer = 0 Sub Main If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then MsgBox("A Drawing document must be active", vbCritical, "") Exit Sub End If Dim oSheet As Sheet = ThisDrawing.Document.ActiveSheet Dim oTextBox As TextBox Dim oldText As String Dim newText As String Dim oldprompt As String = "case insensitive match, no wildcards" Dim newprompt As String = "" 'prompt for search/replace strings: If USEREGEX Then oldprompt = "regular expression; case sensitive; use () for capture groups, \d as number, .* as wildcards, \ as escape" newprompt = "regular expression; use $1,$2 as capture groups, \ as escape" End If oldText = InputBox("String to find (old):" & vbCrLf & vbCrLf & oldprompt, "iLogic - Replace", "old") If oldText = "" Then Return 'exit rule newText = InputBox("String to replace '" & oldText & "' with:" & vbCrLf & vbCrLf & _ newprompt & vbCrLf & vbCrLf & _ "(replaces notes, leaders, dimensions, tables, sketches, titleblocks)", _ "iLogic - Replace", "new") If newText = "" Then Return 'exit rule 'error handling On Error Resume Next 'look in General Notes For Each oGeneralNote In oSheet.DrawingNotes.GeneralNotes oText = oGeneralNote.FormattedText oText = ReplaceText(oText, oldText, newText) oGeneralNote.FormattedText = oText Next 'look in Leader notes For Each oLeaderNote In oSheet.DrawingNotes.LeaderNotes oText = oLeaderNote.FormattedText oText = ReplaceText(oText, oldText, newText) oLeaderNote.FormattedText = oText Next 'look in Dimensions For Each oDimension In oSheet.DrawingDimensions oText = oDimension.Text.FormattedText oText = ReplaceText(oText, oldText, newText) oDimension.Text.FormattedText = oText Next 'look in Tables For Each oTable In oSheet.CustomTables oTable.Title = ReplaceText(oTable.Title, oldText, newText) ' Title Dim oRows As Inventor.Rows = oTable.Rows For Each oRow As Inventor.Row In oRows For Each oCell As Inventor.Cell In oRow oCell.Value = ReplaceText(oCell.Value,oldText, newText) ' Cells Next 'oCell Next 'oRow Next 'look in Title blocks Dim oTitleBlock = oSheet.TitleBlock For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes oText = oTitleBlock.GetResultText(oTextBox) oText = ReplaceText(oText, oldText, newText) oTitleBlock.SetPromptResultText(oTextBox, oText) Next 'look in Sketched symbols For Each oSymbol In oSheet.SketchedSymbols For Each oTextBox In oSymbol.Definition.Sketch.TextBoxes oText = oSymbol.GetResultText(oTextBox) oText = ReplaceText(oText, oldText, newText) oSymbol.SetPromptResultText(oTextBox, oText) Next Next MsgBox("Performed " & repcount & " replacements","Replacements") End Sub Function ReplaceText(oText As String, oldText As String, newText As String) Dim prev As String prev = oText If USEREGEX Then oText = System.Text.RegularExpressions.Regex.Replace(oText,oldText,newText) If oText <> prev Then repcount = repcount + 1 Else If oText = oldText Or oText.Contains(oldText) Then oText = Replace(oText, oldText, newText) repcount = repcount + 1 End If End If Return oText End Function End Class
Inventor


6.5.2025
631×
FAQ
applies to: Inventor ·