Add justified leader note with iLogic

Add justified leader note with iLogic

Togo
Participant Participant
2,992 Views
13 Replies
Message 1 of 14

Add justified leader note with iLogic

Togo
Participant
Participant

Hi guys,

 

I want to automate my workflow a little bit and I'd like to insert leader note to my drawings with ilogic rule.

 

I've managed to insert my note to the drawing like shown on the image below with iLogic rule.

1.PNG

Now I just need to justify the text of the note like shown below (justified manually). I don't know where and how to put justification property.

2.PNG

 

Thanks in advance for all replies.

 

0 Likes
Accepted solutions (1)
2,993 Views
13 Replies
Replies (13)
Message 2 of 14

dgreatice
Collaborator
Collaborator

insert your previous code, and others will upgrade your code.

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 3 of 14

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Please put this in your code:

 

Public Sub leaderMiddle()

Dim a As Application
Set a = ThisApplication
Dim b As DrawingDocument
Set b = a.ActiveDocument

Dim c As Sheet
'Select the item sheet you need to change!
Set c = b.Sheets.Item(1)

Dim d As LeaderNote
'Select the item you need to change! Set d = c.DrawingNotes.LeaderNotes.Item(1) d.HorizontalJustification = kAlignTextCenter d.VerticalJustification = kAlignTextMiddle End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 14

Togo
Participant
Participant

This is my code.

Sub main AddLeaderNote()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument

    ' Set a reference to the active sheet.
    Dim oActiveSheet As Sheet
    oActiveSheet = oDrawDoc.ActiveSheet

    ' Set a reference to the drawing curve segment.
    ' This assumes that a drawing curve is selected.
    Dim oDrawingCurveSegment As DrawingCurveSegment
    oDrawingCurveSegment = oDrawDoc.SelectSet.Item(1)

    ' Set a reference to the drawing curve.
    Dim oDrawingCurve As DrawingCurve
    oDrawingCurve = oDrawingCurveSegment.Parent

    ' Get the mid point of the selected curve
    ' assuming that the selected curve is linear
    Dim oMidPoint As Point2d
    oMidPoint = oDrawingCurve.MidPoint

    ' Set a reference to the TransientGeometry object.
    Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    Dim oLeaderPoints As ObjectCollection
    oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection

    ' Create a few leader points.
    Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 0.5, oMidPoint.Y - 0.5))
    'Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 5))

    ' Create an intent and add to the leader points collection.
    ' This is the geometry that the leader text will attach to.
    Dim oGeometryIntent As GeometryIntent
    oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve)

    Call oLeaderPoints.Add(oGeometryIntent)

    ' Create text with simple string as input. Since this doesn't use
    ' any text overrides, it will default to the active text style.
    Dim sText As String
    sText = "Measure<Br/>here"

    Dim oLeaderNote As LeaderNote
    oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
    oLeaderNote.HorizontalJustification = kAlignTextCenter
    oLeaderNote.VerticalJustification = kAlignTextMiddle

    ' Insert a node.
    Dim oFirstNode As LeaderNode
    oFirstNode = oLeaderNote.Leader.RootNode.ChildNodes.Item(1)

    'Dim oSecondNode As LeaderNode
    'oSecondNode = oFirstNode.ChildNodes.Item(1)

    Call oFirstNode.InsertNode(oSecondNode, oTG.CreatePoint2d(oMidPoint.X + 5, oMidPoint.Y + 5))
End Sub 

 I've  added code as bradeneurope suggested, but it does nothing with my text.

0 Likes
Message 5 of 14

bradeneuropeArthur
Mentor
Mentor

can you please put two msgboxes?

 

And write down what the first msgbox represents?

And write down what the second msgbox represents?

 

And share it with me?

 

 Dim oLeaderNote As LeaderNote
    oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
    oLeaderNote.HorizontalJustification = kAlignTextCenter
	MsgBox oLeaderNote.HorizontalJustification

    oLeaderNote.VerticalJustification = kAlignTextMiddle
	MsgBox oLeaderNote.VerticalJustification 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 6 of 14

bradeneuropeArthur
Mentor
Mentor

I have tested.

 

By me it is working.

 

Measure.PNG

 

Your code is correct.

 

What version of inventor are you using

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 14

dgreatice
Collaborator
Collaborator

Hi @bradeneuropeArthur

 

I have tested too, running at iLogic rule showing an error.

but running at VBA macro, its fine.

 

I using inventor 2014, any issue?

 

errorJustifyLeaderNote.JPG

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 8 of 14

bradeneuropeArthur
Mentor
Mentor

Hi,

 

I have tested Vb.net.

I have not tested I-logic.

 

Maybe this is not supported for I-Logic.

 

That's why  I am interested in the release and service packs that are uses of inventor.

 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 9 of 14

Togo
Participant
Participant

I'm using Autodesk Inventor Professional 2018.

5.PNG

 

Sorry, but I don't understand what you want from me with those msgboxes.

 

I'm also getting an error when I run the rule. How can I correct it?

3.PNG

 

But still my text is not justified.

4.PNG

 

0 Likes
Message 10 of 14

dgreatice
Collaborator
Collaborator

can you migrate from iLogic to VBA Macro?

 

in VBA Macro you code run fine.

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 11 of 14

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Change to this:

 

    oLeaderNote.HorizontalJustification = 19969

    oLeaderNote.VerticalJustification = 25601

Ilogic cannot use the object as name directly.

 

use the numbers like above! 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 12 of 14

Togo
Participant
Participant

Yes, I have tried that in VBA Macro and it worked.

 

And with numbers in iLogic it also works now.

 

I have alse get rid of the error message. It was caused by last line before End sub.

 

So the working code is:

Sub main AddLeaderNote()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument

    ' Set a reference to the active sheet.
    Dim oActiveSheet As Sheet
    oActiveSheet = oDrawDoc.ActiveSheet

    ' Set a reference to the drawing curve segment.
    ' This assumes that a drawing curve is selected.
    Dim oDrawingCurveSegment As DrawingCurveSegment
    oDrawingCurveSegment = oDrawDoc.SelectSet.Item(1)

    ' Set a reference to the drawing curve.
    Dim oDrawingCurve As DrawingCurve
    oDrawingCurve = oDrawingCurveSegment.Parent

    ' Get the mid point of the selected curve
    ' assuming that the selected curve is linear
    Dim oMidPoint As Point2d
    oMidPoint = oDrawingCurve.MidPoint

    ' Set a reference to the TransientGeometry object.
    Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    Dim oLeaderPoints As ObjectCollection
    oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection

    ' Create a few leader points.
    Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 0.5, oMidPoint.Y - 0.5))
    'Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 5))

    ' Create an intent and add to the leader points collection.
    ' This is the geometry that the leader text will attach to.
    Dim oGeometryIntent As GeometryIntent
    oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve)

    Call oLeaderPoints.Add(oGeometryIntent)

    ' Create text with simple string as input. Since this doesn't use
    ' any text overrides, it will default to the active text style.
    Dim sText As String
    sText = "Measure<Br/>here"

Dim oLeaderNote As LeaderNote
    oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
    oLeaderNote.VerticalJustification = 25601

    ' Insert a node.
    Dim oFirstNode As LeaderNode
    oFirstNode = oLeaderNote.Leader.RootNode.ChildNodes.Item(1)

    'Dim oSecondNode As LeaderNode
    'oSecondNode = oFirstNode.ChildNodes.Item(1)

End Sub

 

Thank you very much for help. 

0 Likes
Message 13 of 14

bradeneuropeArthur
Mentor
Mentor

Your thanks are appreciated!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 14 of 14

dgreatice
Collaborator
Collaborator

hi,

 

make some code are better.

 

oDrawingCurveSegment = ThisApplication.CommandManager.Pick(16914, "select Line")

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014