How to add text in Bend Note

How to add text in Bend Note

f_yilmaz_82
Contributor Contributor
1,117 Views
7 Replies
Message 1 of 8

How to add text in Bend Note

f_yilmaz_82
Contributor
Contributor

Hello,

I want to add an extra note in bend note.

If the angle value smaller than 90°, add "OPEN" note, or "Close" Note for bigger angles

For example; The bend note is "DOWN 135° R1,5"; I want to write auotmatically "DOWN 135° (Closed) R1,5"

How can i create an ILogic rule about this?

 

0 Likes
Accepted solutions (1)
1,118 Views
7 Replies
Replies (7)
Message 2 of 8

m.van.valen_ECO
Enthusiast
Enthusiast

Credits go to @JelteDeJong 

 

Dim view As DrawingView = ThisApplication.CommandManager.Pick(
	           SelectionFilterEnum.kDrawingViewFilter,
	           "Select a drawing view")
If (view Is Nothing) Then Return
	
Dim bendCurves = view.DrawingCurves.Cast(Of DrawingCurve).
    Where(Function(curve) curve.EdgeType = DrawingEdgeTypeEnum.kBendDownEdge Or
                          curve.EdgeType = DrawingEdgeTypeEnum.kBendUpEdge).ToList()
						  
Dim bendNotes = view.Parent.DrawingNotes.BendNotes
For Each curve As DrawingCurve In bendCurves
    bendNotes.Add(curve)
Next
Message 3 of 8

f_yilmaz_82
Contributor
Contributor

Sorry i dont understand. Because i am new at I Logic. 

I want it to be like in the example below

f_yilmaz_82_0-1642428870942.png

 

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

Hi @f_yilmaz_82.  This is likely going to be pretty challenging to achieve.  There is a lot of stuff going on behind the scenes of that fairly simple looking bend note on the drawing.  First of all, the default information shown by the bend line, is dictated by some settings within a dimension style.  On the Manage tab of the open/active drawing, click on the Styles Editor tool, to open up the main Style and Standard Editor dialog.  Then select the specific dimension style you were using when you created that bend note.  Now click on the 'Notes and Leaders' tab on the right part of the screen.  Now click on the Bend Notes icon just above the Note Format text box.

WCrihfield_0-1642445804867.png

Here is where you can dictate which pieces of information should always be present, and in what order, and any other characters or special characters you may want to include.  However, you can't use anything like a If...Then statements in there for including the extra "(OPEN)" or "(CLOSED)" text you want.

 

To add that extra optional text in there, you will need some code to get the BendNote object in your DrawingView, then you will need to check its contents, and be able to isolate just that angle part if the information, so you can check/compare it.  However, there are 3 different ways to check the 'contents' (a String) of that BendNote, and two of those returned Strings will include XML tag codes, which further complicates things.  In order to add the extra text into the bend note, in the location you are indicating, you will need to put it into the BendNote.FormattedBendNote, which is one of those with the XML tags in it.  To give you some idea of what all is actually included in that, here is an iLogic rule that will find the first BendNote on the 'active' sheet of the drawing, then show you the 3 different contents in it.  The first one is the plain text, as it is seen on your drawing.  The second one shows you the FormattedBendNote contents using an InputBox, so you can copy the contents to a text file if you want, to better inspect it.  Then the third one is the FormattedText contents, also using an InputBox, so that it will be select-able and copy-able.

oDDoc = ThisDrawing.Document
oBNotes = oDDoc.ActiveSheet.DrawingNotes.BendNotes
oBNote = oBNotes.Item(1)
MsgBox("oBNote.Text = " & oBNote.Text,,"")
oFBNote = oBNote.FormattedBendNote
oFText = oBNote.FormattedText
a = InputBox("", "FormattedBendNote", oFBNote)
a = InputBox("", "FormattedText", oFText)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

f_yilmaz_82
Contributor
Contributor

Unfortunately i couldn't succeed. I tried some different ilogic codes but its not work.

There is a ilogic rule below. I tried it. It is working. But its only for "135°" and "41°". I can write more number. But i know it is not true way. 


oDoc = ThisDoc.Document
oOriginalSheet = oDoc.ActiveSheet

'loop through sheets
For Each oSheet In oDoc.Sheets
oSheet.Activate
'loop through bend notes
For Each oNote In oSheet.DrawingNotes.BendNotes
'clear overrides (if any)
oNote.Hidevalue = False
oNote.Text = ""
'check direction and set note
If oNote.Text.Contains("135°") Then
oText = Replace(oNote.Text,"135°","135° (CLOSED)")
oNote.Hidevalue = True
oNote.Text = oText
End If
If oNote.Text.Contains("41°") Then
oText = Replace(oNote.Text,"41°","41° (OPEN)")
oNote.Hidevalue = True
oNote.Text = oText
End If
Next oNote
Next oSheet

'return to original sheet
oOriginalSheet.Activate

 

0 Likes
Message 6 of 8

WCrihfield
Mentor
Mentor

Hi @f_yilmaz_82.  The code I posted was just to help you see all the hidden code contents behind the note, to give you a better idea of how Inventor keeps the text shown accurate and linked to the model.  Replacing all that with simple, non-coded text will break that link, and just won't work out as you are hoping for.  First of all, I see in your code that you are setting the BendNote.Text to a empty String, before testing its contents, which defeats the purpose and won't work, because there is nothing left to check.  Next, simply attempting to replace that angle value in the BendNote.Text with the same bend angle, plus some extra text won't work either, because all the formatting code still exists within the BendNote.FormattedBendNote, so you end up with different results than you are expecting.  You need to make the changes within the BendNote.FormattedBendNote, for them to turn out the way you want, which is going to be a bit trickier to do, due to the XML tags involved.

 

I created a simple example to test this functionality on.  I have small sheet metal part with a 90 degree bend in it, that I created a flat pattern view of in a drawing.  I added a default bend note to its one bend linen.  It reads "UP 90° R.13".  If I try to just replace the "90°" within the BendNote.Text, I end up with nearly twice as much text as I started with...essentially the original text, followed by the modified text.  So, since I know I need to be dealing with the BendNote.FormattedBendNote contents, and I know what text that holds due to the first code I posted, I know what to search for.

The text within that is as follows:

"<BendDirection/> <BendAngle Precision='2' UpperTolerance='0.000000' LowerTolerance='0.000000' ToleranceType='kSymmetricTolerance' TolerancePrecision='2'></BendAngle> R<BendRadius Precision='2' AlternatePrecision='2' UpperTolerance='0.000000' LowerTolerance='0.000000' ToleranceType='kSymmetricTolerance' TolerancePrecision='2' ToleranceAlternatePrecision='2'></BendRadius>"

We can tell that there is a "<BendAngle" opener tag, then later a "</BendAngle>" closing tag, all of which represents the "90°" part of the main Text.  And we know we want to insert our extra text after that, but before the rest of it.  So, here is an iLogic rule I created to do that, and it is working for my example.

oDDoc = ThisDrawing.Document
oSheet = oDDoc.ActiveSheet
oBNote = oSheet.DrawingNotes.BendNotes.Item(1)
If oBNote.Text.Contains("90°") Then
	oTerm = "</BendAngle>" 'at the end of the bend angle note
	oFBN = oBNote.FormattedBendNote
	'find the position of that text within the overall text
	oPos = InStrRev(oFBN, oTerm)
	oBNote.FormattedBendNote = oFBN.Insert(oPos + Len(oTerm) -1, " (OPEN) ")
End If

This finds the position of the closing tag for the bend angle, so we can use that to help us know where to insert our extra text.  Then we set the new value of oBNote.FormattedBendNote to the new value we are inserting our extra text into.  Within that line, you see that I am also getting the length (# of characters) of the search term too, so that it will be inserted after the end of where that search term is found, instead of at the beginning of it.  The bend note in my drawing view now shows "UP 90°±.00° (OPEN) R.13±.00".  That's because, for some reason it toggled the settings within that note, and turned on the tolerances, that were previously not showing.  If I manually double click on that bend note, I get the small dialog labeled "Edit Bend Note" as seen here.  If I click on the Precision and Tolerance button, it will open up another small dialog labeled "Precision and Tolerance" as also seen here.

WCrihfield_0-1642518138285.png

  If I click on the Precision and Tolerance button, it will open up another small dialog labeled "Precision and Tolerance" as also seen here.

WCrihfield_1-1642518278734.png

I had to uncheck both of those check boxes to the right, then check the box by "Use Global Precision", then click OK.  Then my bend note looked as I wanted it to ("UP 90° (OPEN) R.13").  Since I did not have any of that turned on to start with, I don't know why those settings were turned on afterwards, when all I did was inject that little bit of extra text in the middle of what was already there, but that's what happened in my case.

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 8

WCrihfield
Mentor
Mentor
Accepted solution

I further developed the code to avoid the odd issue with the precision and tolerances.  Since neither you or I seem to be using any 'special' (non-default) settings for precision or tolerances, I added in a bit of code to completely replace all that unneeded special formatting for those things out of the BendAngle and BendRadius parts of the FormattedBendNote.  Also, you may want to change the special text it adds for a 90 degree bend to an empty string, instead of " (SQUARE) ".  I just included that for testing, to make sure everything was working as planned.

See if this works for you now.

 

Sub Main
	'get drawing document you want to target
	oDDoc = ThisDrawing.Document
	
	'specify what text to add after angle in different situations
	'we will use this later in the code
	oMap = ThisApplication.TransientObjects.CreateNameValueMap
	oMap.Add("<90", " (OPEN) ") 'angle is less than 90
	oMap.Add("=90", " (SQUARE) ") 'angle is 90
	oMap.Add(">90", " (CLOSE) ") 'angle is greater than 90

	For Each oSheet As Sheet In oDDoc.Sheets
		'if no bend notes on sheet, skip to next sheet
		If oSheet.DrawingNotes.BendNotes.Count = 0 Then Continue For
		oBNotes = oSheet.DrawingNotes.BendNotes
		For Each oBNote As BendNote In oBNotes
			oFBN = oBNote.FormattedBendNote
			'if this bend note does not contain any angle info, skip to next bend note
			If Not oFBN.Contains("<BendAngle") Then Continue For
			'create a variable to hold the text we will be adding after the angle
			Dim oTextToAdd As String = vbNullString
			'isolate and get the angle part of the text
			oParts = oBNote.Text.Split(" ") 'split into multiple sub-strings, by where spaces are
			Dim oAngle As String = vbNullString
			For Each oPart In oParts
				If oPart.Contains("°") Then 'if it contains the 'degree' mark
					oAngle = oPart
				End If
			Next
			'check to make sure we found the angle text
			If String.IsNullOrEmpty(oAngle) Then Continue For 'could not isolate the angle text
			'check angle (extract numerical value from String, then compare)
			If Val(oAngle) = 90 Then
				oTextToAdd = oMap.Value("=90") 'uses the Value of that place in the oMap
			ElseIf Val(oAngle) < 90 Then
				oTextToAdd = oMap.Value("<90") 'uses the Value of that place in the oMap
			ElseIf Val(oAngle) > 90 Then
				oTextToAdd = oMap.Value(">90") 'uses the Value of that place in the oMap
			End If
			'use our custom Function's below
			oFBN = FixBendAngle(oFBN, oTextToAdd)
			oFBN = FixRadius(oFBN)
			'now finally set the new value
			oBNote.FormattedBendNote = oFBN
		Next
	Next
End Sub

Function FixBendAngle(oFormattedBendNote As String, oTextToPutAfterAngle As String) As String
	'get BendAngle part of formatted text
	oPos1 = oFormattedBendNote.IndexOf("<BendAngle")
	oPos2 = oFormattedBendNote.IndexOf("</BendAngle>") + Len("</BendAngle>")
	oLen = oPos2 - oPos1
	oSubSt = oFormattedBendNote.Substring(oPos1, oLen)
	'MsgBox("oSubSt = " & oSubSt, , "")
	oResult = oFormattedBendNote.Replace(oSubSt, "<BendAngle> </BendAngle>" & oTextToPutAfterAngle)
	Return oResult
End Function

Function FixRadius(oFormattedBendNote As String) As String
	'get Radius part of formatted text
	oPos1 = oFormattedBendNote.IndexOf("<BendRadius")
	oPos2 = oFormattedBendNote.IndexOf("</BendRadius>") + Len("</BendRadius>")
	oLen = oPos2 - oPos1
	oSubSt = oFormattedBendNote.Substring(oPos1, oLen)
	'MsgBox("oSubSt = " & oSubSt, , "")
	oResult = oFormattedBendNote.Replace(oSubSt, "<BendRadius> </BendRadius>")
	Return oResult
End Function

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 8

f_yilmaz_82
Contributor
Contributor

Thank you so much for all.

It is working perfect. 

0 Likes