ilogic for custom annotation

ilogic for custom annotation

patrick3HNXX
Enthusiast Enthusiast
1,725 Views
7 Replies
Message 1 of 8

ilogic for custom annotation

patrick3HNXX
Enthusiast
Enthusiast

I am trying to add some custom labels in our assemblies. Th e fabrication shop prefers to have them labeled this way rather than regular ballons.

 

Ideally you could just click on the part and and it adds the part name and number to the leader. I noticed in the format text box you can see the part number and name in function box. I was going to pull the text from there and then split the string into pieces. I have quantity on there too but I don't need to automate that.

 

My coding skills aren't quite up to par so any help is appreciated.Untitled.jpg

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

JelteDeJong
Mentor
Mentor

You could try this. Create a rule.

Dim textNote As LeaderNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Select leader note")
MsgBox(textNote.FormattedText)
' or if you have inventor 2019 or later
 logger.Info(textNote.FormattedText)

Run this rule and note down the text in the messagebox (or in the log)

now change the rule to this:

Dim textNote As LeaderNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Select leader note")
textNote.FormattedText = "... found text here ..."

Replace the text "... found text here ..." with the text you previous found.

it will look something like this:

Dim textNote As LeaderNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Select leader note")
textNote.FormattedText = "<DerivedProperty DerivedID='29697'>FILENAME</DerivedProperty><Br/><Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property><Br/>"

Now you can run this rule to set the leader notes.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 8

patrick3HNXX
Enthusiast
Enthusiast

Thanks. That got me most of the way there. I just need to manipulate the text a bit more. Trim the part number and ".ipt" off, make the name uppercase. Also I will need to trim the part number so it's just a number. Untitled.jpg

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

When the text within the note is 'linked' to an iProperty (or similar), it will only show the contents of that iProperty.  It can be formatted certain ways, but can't change the actual contents.  If you need to show altered contents from what's in the iProperty, you will need to just get the value of that iProperty to a variable, then use String manipulation techniques to alter the contents to your needs, then assemble the note String the way you want it, then set the result to the note's FormattedText, replacing anything that was in it before.  You may need to use a <Br/> tag within the String, to let it know where to go to the next line, instead of using things like (vbCrLf, vbLf, vbCr, vbNewLine).  That text won't be 'linked' to those iProperties anymore this way though.

Here's a link to the online help page for dealing with FormattedText and their XML tags.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

patrick3HNXX
Enthusiast
Enthusiast

How do I assign the string to a variable?

0 Likes
Message 6 of 8

patrick3HNXX
Enthusiast
Enthusiast

Here's what I got so far, and it appears to be working. Still needs a few more tweaks to handle revision numbers and multiple part numbers.

 

Dim textNote As LeaderNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Select leader note")

textNote.FormattedText = "<DerivedProperty DerivedID='29697'>FILENAME</DerivedProperty>"

MyString = textNote.Text
RevNumber = Mid(MyString, 7, 2)

If RevNumber = "-A" Then
	
	StringLen = Len(MyString)
	PartName = Right(MyString, StringLen - 11)
	PartName = Left(PartName, Len(PartName) -4)
	PartNumber = Left(MyString, 8)
		
Else
	
	StringLen = Len(MyString)
	PartName = Right(MyString, StringLen - 7)
	PartName = Left(PartName, Len(PartName) - 4)
	PartNumber = Left(MyString, 6)
		
End If

PartName = UCase(PartName)
textNote.FormattedText = "<StyleOverride Font='Arial' Bold='True'>" & PartName & "</StyleOverride><Br/>PART NO. " & PartNumber
0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor
Accepted solution

I had so many things going on with work and the forums too, I lost track and didn't get back here very soon.  I created something (fairly complex) you may be able to use to help streamline this process a bit better.  It does the whole process from scratch.  It first allows you to select a model edge (DrawingCurveSegment) in a drawing view (the part you want to attach one of these custom leader note's to.  Then it inspects the selected DrawingCurveSegment object to retrieve all needed info about it for the leader note.  I'm attempting to make it work for either a view of a single part document, or a view of an assembly document, so it will be more flexible/useful, but I'm sure it can use some more refinement and additional error handling to suit various needs/scenarios.

 

This example pulls the model's 'Description' iProperty value to use as the first line of text in the note, then it pulls the model's 'Part Number' iProperty value to use in the second line of the note, then gets the Qty value (one way or another) to use in the third line of the note.  But you can change which properties it's using if you want.  You may also need to check if the property has a value (not empty) before attempting to put its value into the note.  There is a lot in this rule, and I'm assuming a lot, so read through it first.  When creating a leader note, you need to supply a point location for where you want to put it, so I just used the upper right corner of the drawing view as the outer point to place the text part of it.  This can also be changed however you want it.  Then I put a little message at the end of the process that pops up asking if you want to repeat it, just to make the whole thing way more handy. 🙂

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oDCurve As DrawingCurveSegment

RepeatProcess :
oDCurve = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a DrawingCurveSegment.")
If oDCurve Is Nothing Then
	MsgBox("Nothing was selected. Exiting.")
	Exit Sub
End If
Dim oView As DrawingView = oDCurve.Parent.Parent

'check view doc's type first, then use that to determine edge type (Edge or EdgeProxy), and other stuff
Dim oDTProps As PropertySet
Dim oQty As Integer
If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim oViewDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oEdge As EdgeProxy = oDCurve.Parent.ModelGeometry
	Dim oBody As SurfaceBodyProxy = oEdge.Parent
	Dim oOcc As ComponentOccurrence = oBody.Parent
	Dim oOccDoc As Document = oOcc.Definition.Document
	oDTProps = oOccDoc.PropertySets.Item("Design Tracking Properties")
	'now set value of oQty
	'may have to inspect & consider things like design view representation and/or Level of Detail (LOD) of the view be accurate
	Dim oBOMViews As BOMViews = oViewDoc.ComponentDefinition.BOM.BOMViews
	For Each oBOMView As BOMView In oBOMViews
		If oBOMView.ViewType <> BOMViewTypeEnum.kModelDataBOMViewType Then Continue For
		For Each oRow As BOMRow In oBOMView.BOMRows
			If oRow.ComponentDefinitions.Item(1) Is oOcc.Definition Then
				oQty = oRow.ItemQuantity
			End If
		Next
	Next
ElseIf oView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim oViewDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oEdge As Edge = oDCurve.Parent.ModelGeometry
	Dim oBody As SurfaceBody = oEdge.Parent
	Dim oPDef As PartComponentDefinition = oBody.Parent
	Dim oPDoc As PartDocument = oPDef.Document
	oDTProps = oPDoc.PropertySets.Item("Design Tracking Properties")
	oQty = 1
End If

Dim oDesc As String = oDTProps.Item("Description").Value
Dim oPN As String = oDTProps.Item("Part Number").Value

'create a new LeaderNote attached to the selected geometry
Dim oGeomIntent As GeometryIntent = oSheet.CreateGeometryIntent(oDCurve.Parent, .5)
Dim oPt As Point2d = ThisApplication.TransientGeometry.CreatePoint2d((oView.Left + oView.Width), oView.Top)
Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oLeaderPoints.Add(oPt)
oLeaderPoints.Add(oGeomIntent)
Dim oFText As String = oDesc & "<Br/>" & "Part No.  " & oPN & "<Br/>" & "Qty.  " & oQty
Dim oLNote As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, oFText)

oRepeat = MsgBox("Create another custom leader?", vbYesNo + vbQuestion, "REPEAT?")
If oRepeat = vbYes Then GoTo RepeatProcess

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 8

patrick3HNXX
Enthusiast
Enthusiast

Wow, this is amazing. Gets the quantity in there as well.

 

Thank you sir. You are a gentleman and a scholar.

0 Likes