Hello,
Can someon tell me if i can do a find for example letter a and replace it with b in a text in my drawings?
I have tekst 1 a2 and it has to be 1 b2 but i have multiple numbers with the letter a that has to be replaced.
Thanks for the help!
Solved! Go to Solution.
Solved by Sergio.D.Suárez. Go to Solution.
Hi, a while ago, I had this ilogic rule ready. This rule will replace a text specified in each note of your drawing file. I guess it has to work.
oDoc = ThisDoc.Document Dim oSheets As Sheets Dim oSheet As Sheet Dim oViews As DrawingViews Dim oView As DrawingView Dim oGeneralNotes As GeneralNotes Dim oGeneralNote As GeneralNote Dim oSymbol As SketchedSymbol Dim oSymbols As SketchedSymbols Dim oTitleBlock As TitleBlock Dim oTestBox As TextBox Dim TXT2Find As String Dim NewTXT As String 'get user input TXT2Find = InputBox("Enter Text To Find:", "iLogic", "XXX") 'look for blank value If TXT2Find ="" Then Return 'exit rule Else 'Continue rule End If NewTXT = InputBox("Enter Text To Replace '"& TXT2Find _ & "' with.", "iLogic", "****") oSheets = oDoc.Sheets For Each oSheet In oSheets Try oGeneralNotes = oSheet.DrawingNotes.GeneralNotes 'look at gerenal notes For Each oGeneralNote In oGeneralNotes If oGeneralNote.FormattedText = TXT2Find Then oGeneralNote.FormattedText = NewTXT Else End If Next oLeaderNotes = oSheet.DrawingNotes.LeaderNotes 'look at gerenal notes For Each oLeaderNote In oLeaderNotes If oLeaderNote.FormattedText = TXT2Find Then oLeaderNote.FormattedText = NewTXT Else End If Next oTitleBlock = oSheet.TitleBlock For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes If oTitleBlock.GetResultText(oTextBox) = TXT2Find Then oTitleBlock.SetPromptResultText(oTextBox, NewTXT ) Else End If Next oSymbols = oSheet.SketchedSymbols 'look at sketched symbols For Each oSymbol In oSymbols For Each oTextBox In oSymbol.Definition.Sketch.TextBoxes If oSymbol.GetResultText(oTextBox) = TXT2Find Then oSymbol.SetPromptResultText (oTextBox, NewTXT) Else End If Next Next Catch 'do nothing here, 'this simply catches errors, for 'exampl: when a sheet has no title block End Try Next
I hope these lines of code can help you develop the code you need. Regards
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
Thank you! But the problem here is that i just want to replace a letter in a text with an other letter. Is that something that is possible you think?
Hello, the following simplified code should serve to replace a character or part of text with another one that you specify. I have prepared it in general notes and leadernotes.
I hope I can serve you to develop the code you need. Regards
oDoc = ThisDoc.Document Dim TXT2Find As String Dim NewTXT As String 'get user input TXT2Find = InputBox("Enter Text To Find:", "iLogic", "XXX") 'look for blank value If TXT2Find ="" Then Exit Sub NewTXT = InputBox("Enter Text To Replace '"& TXT2Find _ & "' with.", "iLogic", "****") For Each oSheet As Sheet In oDoc.Sheets For Each oGeneralNote As GeneralNote In oSheet.DrawingNotes.GeneralNotes oGeneralNote.FormattedText = oGeneralNote.FormattedText.Replace(TXT2Find,NewTXT) Next For Each oLeaderNote As LeaderNote In oSheet.DrawingNotes.LeaderNotes oLeaderNote.FormattedText = oLeaderNote.FormattedText.Replace(TXT2Find,NewTXT) Next Next
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
I want to do the same thing. This is a leader note text. If I use this code it will delete the text but not the leader attached to it. Is it possible to delete the leader as well?
If I click the text, then the text including the leader will be selected and I can delete both in one click.
Now I use this code:
oDoc = ThisDoc.Document
For Each oSheet As Sheet In oDoc.Sheets
For Each oLeaderNote As LeaderNote In oSheet.DrawingNotes.LeaderNotes
oLeaderNote.FormattedText = oLeaderNote.FormattedText.Replace("C.O.G.", "")
Next
Next
I would try this:
oDoc = ThisDoc.Document
For Each oSheet As Sheet In oDoc.Sheets
For Each oLeaderNote As LeaderNote In oSheet.DrawingNotes.LeaderNotes
If oLeaderNote.FormattedText.Contains("C.O.G.") = True Then
oLeaderNote.Delete
End If
Next
Next
That worked!
Could you merge your code with this code? I tried but got an error:
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet
Dim CenterMark As Centermark
For Each CenterMark In oSheet.Centermarks
If CenterMark.CentermarkType = Inventor.CentermarkTypeEnum.kCenterOfGravityCentermarkType Then
CenterMark.Delete()
End If
Next
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim oLeaderNote As LeaderNote
Dim CenterMark As Centermark
For Each oSheet In oDoc.Sheets
For Each oLeaderNote In oSheet.DrawingNotes.LeaderNotes
If oLeaderNote.FormattedText.Contains("C.O.G.") = True Then
oLeaderNote.Delete
End If
Next
For Each CenterMark In oSheet.Centermarks
If CenterMark.CentermarkType = Inventor.CentermarkTypeEnum.kCenterOfGravityCentermarkType Then
CenterMark.Delete()
End If
Next
Next
This is very helpful. Is there a way for this to work with balloons too? For example, we have text in leaders and text in balloons that would need to be changed. Sometimes the text in the balloon is overridden. Any help is awesome! Thank you!
Hi, to work with balloons you should try something similar to what I show you here.
Dim oDoc As DrawingDocument = ThisDoc.Document For Each oSheet As Sheet In oDoc.Sheets For Each oBalloon As Inventor.Balloon In oSheet.Balloons oBalloon.BalloonValueSets.Item(1).OverrideValue = oBalloon.BalloonValueSets.Item(1).Value & " - Testing" Next Next 'oBalloon.BalloonValueSets.Item(1).Value
You can work with the overridden or directly define the value with the value.
In the example, put a simple routine so that you understand what is being done.
I hope this helps with your problem
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
Thank you for your help! I am not very familiar with coding and was hoping there was a find and replace ilogic code that could be used. We tag out valves and instruments with balloons. Sometimes the customer wants custom tags for each job where only the prefix changes. So I was hoping there was a way to say "search for 1404 and replace with 1409"
Thank you again!
Hi, I think this code could work, it is to overwrite the value of the balloon without changing the value of the balloon item
Dim oDoc As DrawingDocument = ThisDoc.Document Dim TXT2Find, NewTXT As String TXT2Find = InputBox("Enter Text To Find:", "iLogic", "XXX") If TXT2Find ="" Then Exit Sub NewTXT = InputBox("Enter Text To Replace '"& TXT2Find & "' with.", "iLogic", "****") For Each oSheet As Sheet In oDoc.Sheets For Each oBalloon As Inventor.Balloon In oSheet.Balloons oBalloon.BalloonValueSets.Item(1).OverrideValue = _ oBalloon.BalloonValueSets.Item(1).OverrideValue.Replace(TXT2Find, NewTXT) Next Next
Next to change the balloon item
Dim oDoc As DrawingDocument = ThisDoc.Document Dim TXT2Find, NewTXT As String TXT2Find = InputBox("Enter Text To Find:", "iLogic", "XXX") If TXT2Find ="" Then Exit Sub NewTXT = InputBox("Enter Text To Replace '"& TXT2Find & "' with.", "iLogic", "****") For Each oSheet As Sheet In oDoc.Sheets For Each oBalloon As Inventor.Balloon In oSheet.Balloons oBalloon.BalloonValueSets.Item(1).Value = _ oBalloon.BalloonValueSets.Item(1).Value.Replace(TXT2Find, NewTXT) Next Next
I hope this helps with your problem. Cheers!!
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
Hi Sergio,
The second code worked perfectly
The one for overridden balloons gave me an error
"Object reference not set to an instance of an object."
Thank you again.
Thank you very much for this logic, it worked very well some day Inventor will add this to the base system like every other program in the 20th century 🙂
Hope you are well.
I have been trying to do a find and replace for Datums in drawings. im not sure what the come line would be
i keep coming across DrawingEditDatumTargetSymbolCtxCmd but not sure that is the correct call out.
I'm trying to change 3.
in 3.1 & 3.2
to 2.1 & 2.2 respectfully
I'm using this code, Any help would be great.
oDoc = ThisDoc.Document Dim TXT2Find As String Dim NewTXT As String 'get user input TXT2Find = InputBox("Enter Text To Find:", "iLogic", "XXX") 'look for blank value If TXT2Find ="" Then Exit Sub NewTXT = InputBox("Enter Text To Replace '"& TXT2Find _ & "' with.", "iLogic", "****") For Each oSheet As Sheet In oDoc.Sheets For Each DrawingEditDatumTargetSymbol As DrawingDimension In oSheet.DrawingDimensions If DrawingEditDatumTargetSymbol.Text.FormattedText.Contains(TXT2Find) Then DrawingEditDatumTargetSymbol.Text.FormattedText = DrawingEditDatumTargetSymbol.Text.FormattedText.Replace(TXT2Find, NewTXT) End If Next Next
I am trying to wrap my head around this code but my programming capabilities failing me.
Could someone please help me out?
I want to automate iProperteis Project Part Number to be searched and corrected.
The Part Number is built as following: XX-XXXX_XXX-XXXX
I want the code to search for the underscore and replace it with space
The end result should look like this: XX-XXXX XXX-XXXX
This is how far I got:
FileName = ThisDoc.FileName
iProperties.Value("Project", "Part Number") = FileName
TXT2Find = FileName
‘From here I don’t know how to do it right
NewTXT = TXT2Find _ & "' with.", "iLogic", " "
.Replace(TXT2Find,NewTXT)
‘The new changed text should be written to the part number iProperty
iProperties.Value("Project", "Part Number") = NewTXT
I just can’t wrap my head around how to get the text to be searched and replaced.
Can't find what you're looking for? Ask the community or share your knowledge.