Named Automatic Leaders

Named Automatic Leaders

youann21700
Advocate Advocate
251 Views
3 Replies
Message 1 of 4

Named Automatic Leaders

youann21700
Advocate
Advocate

Afternoon,

 

Our current iLogic endeavour is to implement automatic leaders when our drawing note tool is used. For example: If there are 3 notes specifying certain marking to be stenciled on a part,  3 leaders will apear with corresponding "See note XX" text. We have this first section working, however we would like a check to see if any leaders have been placed previously (our drawing notes tool can used as often as needed). Currently leaders will continue to be created regardless of existing ones.

My request:

Is it possible to name leaders when inserting them? So that we can check if leaders on a certain name exist, and update text accordingly. I have attached our leader insert code below.

To summarise: Can insert leaders, want to associate leaders with specific notes (i.e. name them on creation), would also like to be able to update existing leaders without changing their location

Thanks

 

Sub Main
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	Dim oASheet As Inventor.Sheet = oDDoc.ActiveSheet
	Dim oLNotes As LeaderNotes = oASheet.DrawingNotes.LeaderNotes
	Dim oTO As TransientObjects = ThisApplication.TransientObjects
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oObjColl As Inventor.ObjectCollection = oTO.CreateObjectCollection
	oObjColl.Add(oTG.CreatePoint2d(29.5, 10))
	oObjColl.Add(oTG.CreatePoint2d(28, 9.5))
	Dim sFText As String = "SEE NOTE " & (CDbl(iProperties.Value("Custom", "Leaderrow")) + 1) / 2
	Dim oLNote As LeaderNote = oLNotes.Add(oObjColl, sFText)
End Sub

 

 

252 Views
3 Replies
Replies (3)
Message 2 of 4

Stakin
Collaborator
Collaborator

LeaderNote don't have Name property,but you can add attribute to it.
and then retrieve attribute of it before each creating.
LeaderNode.AttributeSets() As AttributeSets

Message 3 of 4

WCrihfield
Mentor
Mentor

Hi @youann21700.  There is no simple or easy way to assign names to them as you create them, when creating them using normal Inventor API code to create them, as you are doing in that code example.  However, we can still assign names to them, but you would just need to include several more lines of code after where each one gets created.  And you will need to have a system in place to ensure that each leader note you create gets assigned a unique and meaningful name.  The 'traditional' way to assign names to nearly any type of Inventor entity, is to use the AttributeSets property of the entity.  This will usually return an AttributeSets collection type object, but it will normally not have any AttributeSet objects in it...until you add some into it.  Each AttributeSet can hold any number of individual Attribute objects.  The Attribute object has a name, a value type (String, Boolean, etc), and a Value.  The value type can be specified as String, and the value can be the custom name you want to assign to the entity.  You would just need to keep track of the names you use when creating the AttributeSet and Attribute objects along the way, because those will be used to retrieve the value of the Attribute later, to get/change/set its custom name.

 

However, there is also an iLogic shortcut snippet route for creating leader notes (IManagedLeaderNotes.Add ), and that does offer a built-in way to assign a name to the leader note as it gets created.  It uses the same AttributeSets/AttributeSet/Attribute system behind the scenes, but may be simpler to use, if you are not familiar with Attributes.

Below is a couple starter lines of code to get you to that point.  It does not go into the details of the 'inputs' being requested.

Dim oLNotes As IManagedLeaderNotes = ActiveSheet.DrawingNotes.LeaderNotes
Dim oMyLeaderNote As IManagedLeaderNote = oLNotes.Add("Name", oLeaderPoints, oGeomIntent, sFText)

This gives you a different type of resulting object (IManagedLeaderNote Interface), but it can lead you to the same Inventor API LeaderNote object, though its NativeEntity property.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 4

youann21700
Advocate
Advocate

Morning @WCrihfield ,

IManagedLeaderNote seems to be pretty much what I'm looking for. My coding is pretty poor so the easier to use the better. However, I am struggling to implement it into my exisitng code.

For clarify, there is a rule above this that iterates through a long list of possible notes, for the relevant notes, a "Leaderrow" and "LeaderName" as assigned as iproperties, and then this rule is run.

 

Sub Main
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	Dim oASheet As Inventor.Sheet = oDDoc.ActiveSheet
	Dim oLNotes As IManagedLeaderNotes = ActiveSheet.DrawingNotes.LeaderNotes
	Dim oTO As TransientObjects = ThisApplication.TransientObjects
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oObjColl As System.Collections.Generic.IEnumerable(Of Object) = oTO.CreateObjectCollection
	Dim geoint As Inventor.GeometryIntent = oTO.CreateObjectCollection
	oObjColl.Append(oTG.CreatePoint2d(29.5, 10+(CDblAny(iProperties.Value("Custom","Leaderrow")*0.2))))
	oObjColl.Append(oTG.CreatePoint2d(28, 9.5 + (CDblAny(iProperties.Value("Custom", "Leaderrow") * 0.2))))
	geoint.Add(oTG.CreatePoint2d(26.5, 9 + (CDblAny(iProperties.Value("Custom", "Leaderrow") * 0.2))))
	Dim sFText As String = "SEE NOTE " & (CDbl(iProperties.Value("Custom", "Leaderrow")) + 1) / 2
	Dim oLNote As IManagedLeaderNote = oLNotes.Add(iProperties.Value("Custom","LeaderName"),oObjColl,geoint,sFText)
End Sub

 This way I am hoping to use the assigned iproperties to create leaders with unique names in order to run checks for existing leaders if the rule is run again. 

My current code is throwing multiple errors about COM objects, would you have any tips to get this running smoothly?

Cheers

0 Likes