ilogic rule with automatic leader text

ilogic rule with automatic leader text

eduardolourencoGSSVM
Explorer Explorer
1,212 Views
7 Replies
Message 1 of 8

ilogic rule with automatic leader text

eduardolourencoGSSVM
Explorer
Explorer

Hello all, 

 

i was wondering if it is possible to have an ilogic rule where i pick an edge or point in a view and it adds a leader text with the following "W1", then i pick another edge and it creates a note with "W2", and so on.

This way i dont need to copy/place a leader text and enter everytime i need to change on each of them.

 

The final ideia is to have something like this

 

eduardolourencoGSSVM_0-1713969133252.png

I lack knowledge of ilogic, so sorry i dont have any code basis to start.

 

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

Michael.Navara
Advisor
Advisor
Accepted solution

You can implement very complex tool with selection events and preview graphics, but this is not for beginners.

You can use this simple macro which utilizes built-in command for creation of LeaderNotes. You create empty LeaderNotes and when you finish the command, appropriate values will be set automatically. You can run this rule multiple times and the index will continue.

 

Create LeaderNotes rule

 

Dim sharedVariableName As String = "W_index"
Dim drw As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = drw.ActiveSheet
Dim leaderNotes As LeaderNotes = sheet.DrawingNotes.LeaderNotes

'Setup index
Dim wIndex As Integer = 1
If SharedVariable.Exists(sharedVariableName) Then
    wIndex = SharedVariable(sharedVariableName)
End If

'Get count of LeaderNotes before start command
Dim countBefore As Integer = leaderNotes.Count

'Start command
'Don't put any text, when you are prompted and
'continue with Ctrl+Enter keyboard shortcut and
'create as many notes as you want
ThisApplication.CommandManager.ControlDefinitions("DrawingLeaderTextCmd").Execute2(True)

'Get count of LeaderNotes after command terminates
Dim countAfter As Integer = leaderNotes.Count

'Set text to currently created LeaderNotes
'previously inserted text will be overwritten
For i As Integer = countBefore + 1 To countAfter
    leaderNotes(i).Text = "W" & wIndex
    wIndex = wIndex + 1
Next

'Store last index for future use
SharedVariable(sharedVariableName) = wIndex

 

 

If you want to set new index value, you can use this rule

 

Dim sharedVariableName As String = "W_index"

'Setup index
Dim wIndex As Integer = 1
If SharedVariable.Exists(sharedVariableName) Then
    wIndex = SharedVariable(sharedVariableName)
End If

'Input new value
Dim newIndex = InputBox("Set new index", "W index", wIndex)
wIndex = Integer.Parse(newIndex)

'Store last index for future use
SharedVariable(sharedVariableName) = wIndex

 

 

0 Likes
Message 3 of 8

eduardolourencoGSSVM
Explorer
Explorer

thank you for your help, it works perfectly.

 

one quick question regarding ilogic coding.

Is there some sort of guide or some kind of "coding tree explanation" (i guess??) to know the commands or access to do stuff? 

 

like for example you have this command 

ThisApplication.CommandManager.ControlDefinitions("DrawingLeaderTextCmd").Execute2(True)

but how can i know that i need to write .CommandManager. ....

eduardolourencoGSSVM_0-1713974078071.png

 

there are some snippets that can help but in some rules there is coding that seems like it needs to be from coding experience. 

 

 

0 Likes
Message 4 of 8

harvey3ELEA
Advocate
Advocate

Michael, very nice tool to have.

Is there a simple way for the leader text that I type during creation of each leader note to stay as typed?

0 Likes
Message 5 of 8

Michael.Navara
Advisor
Advisor

Inventor API object tree is well described in API reference. There are lot of sample codes and the rest you can find on forums.

Print list of all Inventor Commands API Sample

Break alignment of a section view API Sample

 

Also you can scroll in dropdown and CommandManager is one line below your screenshot.

Message 6 of 8

Michael.Navara
Advisor
Advisor

For text modification is responsible line 27. You can modify the piece of ode as you want. You can keep them unmodified if leaderNotes(i).Text is not empty, add prefix or suffix, etc. 

0 Likes
Message 7 of 8

harvey3ELEA
Advocate
Advocate

Hi Michael,

 

Not being much of a coder, I don't know what to do to make my typed text at creation stick regarding line 27 in this group.  If you can offer some advice, I'd certainly appreciate it.  Harvey

 

'Set text to currently created LeaderNotes
'previously inserted text will be overwritten
For i As Integer = countBefore + 1 To countAfter
    LeaderNotes(i).Text = "W" & wIndex
    wIndex = wIndex + 1
Next

 

0 Likes
Message 8 of 8

eduardolourencoGSSVM
Explorer
Explorer

thank you for your reply,

i'll look into it to 🙂

0 Likes