Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

use ilogic to replace the text of existing leader note

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
omvcilindri
1711 Views, 8 Replies

use ilogic to replace the text of existing leader note

Hi everyone

I have a question propose, I would like  replace  text of  existing   Leader Note  with a new text  through ilogic , but the code does not work, can someone help me find the error.

 

I want  replace  "P9" in "N9"

 

 code :

If ThisApplication.ActiveDocumentType <> kDrawingDocumentObject Then

        MessageBox.Show("This rule only works in a drawing document.", "Change Leader Text",MessageBoxButtons.OK,MessageBoxIcon.Error)

        Return

End If



Dim oDoc As DrawingDocument

oDoc = ThisApplication.ActiveDocument



Dim oLeaderNote As LeaderNote

Dim TXT2Find As String

Dim NewTXT As String



saveOriginalText = False

addDescription = False



Question = MessageBox.Show("Overwrite existing leader text?", "Change Leader Text",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1)



Select Case Question:

Case vbYes

        saveOriginalText = False

Case vbNo

        saveOriginalText = True

Case vbCancel

        Return

End Select







oDescription = NewTXT



'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  

        Catch

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

               End Try

              

     

    Next



For Each oLeaderNote In oDoc.ActiveSheet.DrawingNotes

       

        'saves the original text

        originalText = oLeaderNote.FormattedText

       

        oLeaderNote.FormattedText = oDescription

              

        'adds original beginning to end of label text if applicable

        If saveOriginalText = True Then

               oLeaderNote.FormattedText = oLeaderNote.FormattedText & vbCr & originalText

        End If



Next 



 

 

 

Labels (1)
8 REPLIES 8
Message 2 of 9
WCrihfield
in reply to: omvcilindri

Are you familiar with formatted text?  They can get complicated, because they use XML tags within, to represent linked/live iProperties & parameters.  You may want to replace the regular text instead of the formatted text.

Here is an example code using the regular text.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Return
End If

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim saveOriginalText As Boolean = False
Dim addDescription As Boolean = False
Question = MsgBox("Overwrite existing leader text?",vbYesNoCancel + vbQuestion + vbDefaultButton1, "Change Leader Text")
Select Case Question:
Case vbYes
	saveOriginalText = False
Case vbNo
	saveOriginalText = True
Case vbCancel
	Return
End Select
Dim TXT2Find As String = InputBox("Enter Text To Find:", "iLogic")
If TXT2Find = "" Then
	MsgBox("Text to find was blank, so exiting.",vbOKOnly," ")
	Return
End If
Dim NewTXT As String = InputBox("Enter Text To Replace   '" & TXT2Find & "'  with.", "iLogic")
If oNewTXT = "" Then
	MsgBox("Text to replace original was blank, so exiting.", vbOKOnly, " ")
	Return
End If

Dim oLNotes As LeaderNotes
Dim oLNote As LeaderNote
For Each oSheet As Sheet In oDDoc.Sheets
	oLNotes = oSheet.DrawingNotes.LeaderNotes
	For Each oLNote In oLNotes
		If oLNote.Text = TXT2Find Then
			If saveOriginalText = True Then
				oLNote.Text = NewTXT & vbCrLf & oLNote.Text
			Else
				oLNote.Text = NewTXT
			End If
		End If
	Next
Next


Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 9
omvcilindri
in reply to: WCrihfield

Thanks for your help, I don't know the formatted text. Yes changing the regular text is fine, I only have to change the content of the text. I tested your code but it doesn't work, but the message you put is nice.

Message 4 of 9
JhoelForshav
in reply to: omvcilindri

Hi @omvcilindri 

@WCrihfieldjust accidentially added an "o" in the parameter name NewTXT on the line:

If oNewTXT = "" Then

The code works if you remove that:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Return
End If

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim saveOriginalText As Boolean = False
Dim addDescription As Boolean = False
Question = MsgBox("Overwrite existing leader text?",vbYesNoCancel + vbQuestion + vbDefaultButton1, "Change Leader Text")
Select Case Question:
Case vbYes
	saveOriginalText = False
Case vbNo
	saveOriginalText = True
Case vbCancel
	Return
End Select
Dim TXT2Find As String = InputBox("Enter Text To Find:", "iLogic")
If TXT2Find = "" Then
	MsgBox("Text to find was blank, so exiting.",vbOKOnly," ")
	Return
End If
Dim NewTXT As String = InputBox("Enter Text To Replace   '" & TXT2Find & "'  with.", "iLogic")
If NewTXT = "" Then
	MsgBox("Text to replace original was blank, so exiting.", vbOKOnly, " ")
	Return
End If

Dim oLNotes As LeaderNotes
Dim oLNote As LeaderNote
For Each oSheet As Sheet In oDDoc.Sheets
	oLNotes = oSheet.DrawingNotes.LeaderNotes
	For Each oLNote In oLNotes
		If oLNote.Text = TXT2Find Then
			If saveOriginalText = True Then
				oLNote.Text = NewTXT & vbCrLf & oLNote.Text
			Else
				oLNote.Text = NewTXT
			End If
		End If
	Next
Next

 

Message 5 of 9
JhoelForshav
in reply to: JhoelForshav

I also noticed that if you dont overwrite the existing text it adds a line break to the text.

This makes it a bit difficult to find that text again since you only have one row in the inputbox.

 

Therefore i suggest this change to the code:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Return
End If

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim saveOriginalText As Boolean = False
Dim addDescription As Boolean = False
Question = MsgBox("Overwrite existing leader text?",vbYesNoCancel + vbQuestion + vbDefaultButton1, "Change Leader Text")
Select Case Question:
Case vbYes
	saveOriginalText = False
Case vbNo
	saveOriginalText = True
Case vbCancel
	Return
End Select

Dim TXT2Find As String = InputBox("Enter Text To Find:", "iLogic")
If TXT2Find = "" Then
	MsgBox("Text to find was blank, so exiting.",vbOKOnly," ")
	Return
End If
Dim NewTXT As String = InputBox("Enter Text To Replace   '" & TXT2Find & "'  with.", "iLogic")
If NewTXT = "" Then
	MsgBox("Text to replace original was blank, so exiting.", vbOKOnly, " ")
	Return
End If

Dim oLNotes As LeaderNotes
Dim oLNote As LeaderNote

For Each oSheet As Sheet In oDDoc.Sheets
	oLNotes = oSheet.DrawingNotes.LeaderNotes
	For Each oLNote In oLNotes
		Dim oTxt As String = oLNote.Text
		If oTxt.Contains(Chr(10)) Then oTxt = oTxt.Replace(Chr(10), " ")
		If oTxt = TXT2Find Then
			If saveOriginalText = True Then
				oLNote.Text = NewTXT & vbCrLf & oLNote.Text
			Else
				oLNote.Text = NewTXT
			End If
		End If
	Next
Next

 It'll find the text even if there's a line break in it if you just use a simple blank space in the inputbox 🙂

Message 6 of 9
omvcilindri
in reply to: JhoelForshav

nice job congratulations

Message 7 of 9
robertast
in reply to: JhoelForshav

@JhoelForshav 

I am constantly amazed at your abilities. Looking at your work, it seems that nothing is impossible for you 👍 👍👍

Message 8 of 9

Hi @JhoelForshav ,

Would you able to help me in something similar? I have callouts already showing some Iproperties. I need to add more Iproperties and custom properties to some of these callouts. Is any way to run and Irule to select only the callouts I need to add the information and do it automatically. Something similar to the "Match Properties" in AutoCAD.
Thanks

Daniel V.

Message 9 of 9
JBEDsol
in reply to: JhoelForshav

So I came across this attempting to do something similar.  I have a bunch of drawings where I need to change the leader text to the proper acronyms.  So SHT needs to change to SH to comply w/ the ASME convention.  I'm using VB so I can better troubleshoot.  The code seems to work but where ever there's a break (meaning text in 2 rows on top of eachother) the code overwrites that to be one line.  How do I correct this so the format remains the same?

 

Private Sub Replace_Text_Click(sender As Object, e As EventArgs) Handles Replace_Text.Click
If appApp.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("This rule only works for Drawing Documents.", vbOKOnly, "WRONG DOCUMENT TYPE")
Return
End If

Dim oDDoc As DrawingDocument = appApp.ActiveDocument
Dim saveOriginalText As Boolean = False
Dim addDescription As Boolean = False
'Question = MsgBox("Overwrite existing leader text?",vbYesNoCancel + vbQuestion + vbDefaultButton1, "Change Leader Text")
'Select Case Question:
'Case vbYes
' saveOriginalText = False
'Case vbNo
' saveOriginalText = True
'Case vbCancel
' Return
'End Select

Dim TXT2Find As String = InputBox("Enter Text To Find:", "iLogic")
If TXT2Find = "" Then
MsgBox("Text to find was blank, so exiting.", vbOKOnly, " ")
Return
End If

Dim NewTXT As String = InputBox("Enter Text To Replace '" & TXT2Find & "' with.", "iLogic")
If NewTXT = "" Then
MsgBox("Text to replace original was blank, so exiting.", vbOKOnly, " ")
Return
End If

Dim oLNotes As LeaderNotes
Dim oLNote As LeaderNote

For Each oSheet As Sheet In oDDoc.Sheets
oLNotes = oSheet.DrawingNotes.LeaderNotes
For Each oLNote In oLNotes
Dim oTxt As String = oLNote.Text
If oTxt.Contains(TXT2Find) Then
oTxt = oTxt.Replace(TXT2Find, NewTXT)
appApp.ScreenUpdating = True

End If
If oTxt = TXT2Find Then

' Do Nothing
End If
Next
Next


End Sub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report