Quick leader adaptivity

Quick leader adaptivity

dwatson5DQLA
Participant Participant
497 Views
6 Replies
Message 1 of 7

Quick leader adaptivity

dwatson5DQLA
Participant
Participant

Hi All,

 

I have written a rule as a, hopefully, temporary measure to label timbers in a section view. What I'm trying to display is "G_L x G_W" in the format, ideally this would be done as a specially formatted balloon but nearest I can get to is using custom sketches which isn't practical given the number of drawings in circulation that we maintain.

 

I've come up with the code below however there's a couple of issues

1. The leader is not associated with the item it grips to, so if the item is moved, the leader stays

2. The values grabbed are manual strings so unlike using the dialog box where the value is linked with the parameter, this way is just a dumb string

 

Anyone have any ideas or better suggestions?

 

Thanks

 

Friend Class Globals
	Public Shared sCoordX As Double
	Public Shared sCoordY As Double

	Sub Main
		
		'Add notes to timber uprights on section of drawing (used for section drawings)
		'Identifies timber sizes and adds Qleaders


		If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then Exit Sub

		' 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
		While True
			' Set a reference to the drawing curve segment.
			' This assumes that a drawing curve is selected.
			Dim oDrawingCurveSegment As DrawingCurveSegment
			oDrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Pick edge/line")
			'oDrawingCurveSegment = oDrawDoc.SelectSet.Item(1)

			If oDrawingCurveSegment Is Nothing Then Exit Sub

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

			Dim oOcc As ComponentOccurrence = oDrawingCurve.ModelGeometry.ContainingOccurrence
			Dim oPartDoc As Document = oOcc.Definition.Document

			'Get part parameter values
			Dim sG_W As String = GetCustomProp(oPartDoc, "G_W")
			Dim sG_T As String = GetCustomProp(oPartDoc, "G_T")

			Dim sCompPos As String = oDrawingCurve.MidPoint.Y.ToString
			Dim sAssyPos As String = oDrawingCurve.Parent.Center.Y.ToString

			' 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 = sG_W & "x" & sG_T

			'Determine position of part in relation to assembly and adjust leader

			If sText = "60x30" Then
				sVer = 0.75
			Else
				sVer = 0.5
			End If

			If sAssyPos > sCompPos Then
				sVer = sVer * (-1)
			End If

			sHor = 0.5

			sText = "<StyleOverride FontSize='0.2'>" & sText & "</StyleOverride>"


			' 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, oMidPoint.Y + sVer))

			' 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, 0.5)

			Call oLeaderPoints.Add(oDrawingCurve.MidPoint)

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

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

		End While
	End Sub

	Sub oMouse_OnMouseDown(Button As MouseButtonEnum, ShiftKeys As ShiftStateEnum, ModelPosition As Point, ViewPosition As Point2d, View As Inventor.View)

		MessageBox.Show(ModelPosition.X & " in cm", "X")
		MessageBox.Show(ModelPosition.Y & " in cm", "Y")

		sCoordX = ModelPosition.X
		sCoordX = ModelPosition.Y

	End Sub


	Public Function GetCustomProp(InventorDoc As Inventor.Document, oPropName As String)

		Try

			Dim CustomPropertySet As PropertySet
			CustomPropertySet = InventorDoc.PropertySets.Item("Inventor User Defined Properties")

			Dim oProperty As [Property]
			oProperty = CustomPropertySet.Item(oPropName)

			Dim oValue As String
			oValue = oProperty.Value

			Return oValue

		Catch ex As SystemException

			Return ""

		End Try

	End Function 'Get Custom Property Value
End Class

 

0 Likes
498 Views
6 Replies
Replies (6)
Message 2 of 7

bradeneuropeArthur
Mentor
Mentor
could you make a screenshot of what you need in the drawing?

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 3 of 7

dwatson5DQLA
Participant
Participant

Hi, this is what I am aiming to achieve. 

 

I've been working on code below to get the adaptive parameter but I'm just getting a blank field inserted.

oPropID = oPartDoc.PropertySets.Item("User Defined Properties").Item("G_T").PropId

"<Property Document='model' PropertySet='User Defined Properties' Property='G_W' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" & oPropID & "'>G_W</Property>"




 

 

Capture.PNG

0 Likes
Message 4 of 7

Michael.Navara
Advisor
Advisor

You can use LeaderNote with formatted text as good approach. Perhaps there can be issue in formatted text string. I  try this simple code which sets the formatted text to all leader notes on active sheet. Try it as a test how to set text binded to model iProperty

Dim formattedText As String  = "<Property Document='model' PropertySet='User Defined Properties' Property='G_W' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}'>G_W</Property>x<Property Document='model' PropertySet='User Defined Properties' Property='G_T' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}'>G_T</Property>"
Dim sheet As Sheet = ThisDrawing.ActiveSheet.Sheet

For Each lNote As LeaderNote In sheet.DrawingNotes.LeaderNotes
	lNote.FormattedText = formattedText
Next
0 Likes
Message 5 of 7

dwatson5DQLA
Participant
Participant

Hi, I've tried that method and I believe that brings in the value from the Assembly not the sub-component. After a bit of research I found bit of code to get the formatted text from a leader, however when I try insert that straight back in I get an error

 

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

Code

Sub Main
	
	
		Dim oLNote As LeaderNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Select a leader note.")
InputBox("Here is the current contents of the FormattedText:", "FORMATTED TEXT",oLNote.FormattedText)
	'exit sub
	
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

		Dim oActiveSheet As Sheet
		oActiveSheet = oDoc.ActiveSheet

Dim s As String
s = oLNote.FormattedText '"<StyleOverride><Parameter Resolved='True' ComponentIdentifier='D:\...\Part3.ipt' Name='G_W' Precision='0'>60</Parameter></StyleOverride>"


			Dim oDrawingCurveSegment As DrawingCurveSegment
			oDrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Pick edge/line")
			'oDrawingCurveSegment = oDrawDoc.SelectSet.Item(1)

			If oDrawingCurveSegment Is Nothing Then Exit Sub

			' 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, oMidPoint.Y + sVer))

			' 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, 0.5)
			'oGeometryIntent = oActiveSheet.CreateGeometryIntent(oMidPoint)

			'Call oLeaderPoints.Add(oGeometryIntent)
			Call oLeaderPoints.Add(oDrawingCurve.MidPoint)
			
MessageBox.Show("Error is here")

			Dim oLeaderNote As LeaderNote
			oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, s)
			'oLeaderNote.FormattedText = s
			
			oLeaderNote.VerticalJustification = kAlignTextMiddle '25601

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

End Sub
0 Likes
Message 6 of 7

dwatson5DQLA
Participant
Participant

Right, fixed one part. Seems I have to create the leadernote and then add format the text. So I end up created a blank leadernote then doing oLeaderNote.FormattedText = s

 

Now the other question, how can I make the leadernode adaptive to the part. At the moment it creates the leader and attaches it to the part but it is not adaptive, so if the part moves, the arrow stays where it was originally created. 

0 Likes
Message 7 of 7

dwatson5DQLA
Participant
Participant

If anyone finds this in the future and is looking for an answer, turns out it was quite easy, just needed to add an attached entity to the first node

 

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

 

0 Likes