create Leader from a work point api

create Leader from a work point api

Anonymous
Not applicable
1,385 Views
4 Replies
Message 1 of 5

create Leader from a work point api

Anonymous
Not applicable

Hi all,

 

I have a work point on a part and want to automatically create a leader on a drawing from this point.

I also would like the leader to pull in and combine 2 of the part parameters to create the leader text.

 

Is this possible using vb.net?

 

I have seen posts close but nothing that  really fits what i'm trying to do.

 

Any help is much appreciated.

 

Cheers

 

Chrisexample.jpg

0 Likes
Accepted solutions (1)
1,386 Views
4 Replies
Replies (4)
Message 2 of 5

BrianEkins
Mentor
Mentor
Accepted solution

Here's a sample that I believe does what you want.  It has an If statement so you can do it in one of two ways.  The first is that it includes the work point into the view and adds the leader to it.  The second is that it just uses the position of the work point to position the leader but the leader isn't actually attached to anything.  Since you have a work point you probably want the first option so then if the work point moves the leader will also adjust.

 

I also made the assumption that you're working on an assembly drawing so the view is of an assembly.  That's a more complex problem and that's what the sample demonstrates.  If that's not true there's quite a bit of code that can be removed and simplified.  Hopefully, this helps.  

 

Private Sub CreateLeader()
    Dim invApp As Inventor.Application = GetObject(, "Inventor.Application")
    Dim drawDoc As DrawingDocument = invApp.ActiveDocument

    ' Find the view named "TestView" on the active sheet.
    Dim sht As Sheet = drawDoc.ActiveSheet
    For Each drawView As DrawingView In sht.DrawingViews
        If drawView.Name = "TestView" Then
            ' Get the referenced assembly.
            Dim tankAsm As AssemblyDocument = drawView.ReferencedDocumentDescriptor.ReferencedDocument
            Dim tankAsmComp As AssemblyComponentDefinition = tankAsm.ComponentDefinition

            ' Get the occurrence of the tank in the assembly.
            Dim tankOcc As ComponentOccurrence = tankAsmComp.Occurrences.ItemByName("Tank:1")

            ' Get the tank part.
            Dim tankPartComp As PartComponentDefinition = tankOcc.Definition

            ' Get the work point named "TANKWP".
            Dim tankWP As WorkPoint = tankPartComp.WorkPoints.Item("TANKWP")

            ' Get the value of the parameters.
            Dim nameParam As Parameter = tankPartComp.Parameters.Item("TANKLEADER")
            Dim volParam As Parameter = tankPartComp.Parameters.Item("WORKINGVOLUME")
            Dim name As String = nameParam.Value
            Dim vol As String = volParam.Value

            Dim includeWP As Boolean = True
            If includeWP Then
                ' Get the proxy of the work point because we need it in the context of the assembly.
                Dim tankWPProxy As WorkPointProxy = Nothing
                tankOcc.CreateGeometryProxy(tankWP, tankWPProxy)

                ' Include the work point.
                Dim mark As Centermark = sht.Centermarks.AddByWorkFeature(tankWPProxy, drawView)

                ' Create the leader.
                Dim pnts As ObjectCollection = invApp.TransientObjects.CreateObjectCollection
                pnts.Add(invApp.TransientGeometry.CreatePoint2d(mark.Position.X + 3, mark.Position.Y + 2))
                pnts.Add(sht.CreateGeometryIntent(mark))
                sht.DrawingNotes.LeaderNotes.Add(pnts, name & "<Br/>" & vol)
            Else
                ' Get the position of the work point.  This is in the part space of the thank.
                Dim wpModelPosition As Point = tankWP.Point

                ' Get the transform of the tank occurence. This defines the part to assembly transform.
                Dim tankTrans As Matrix = tankOcc.Transformation

                ' Transform the point using this transform to go from part to assembly space.
                wpModelPosition.TransformBy(tankTrans)

                ' Get this point in sheet space.
                Dim wpViewPosition As Point2d = drawView.ModelToSheetSpace(wpModelPosition)

                ' Create the leader.
                Dim pnts As ObjectCollection = invApp.TransientObjects.CreateObjectCollection
                pnts.Add(invApp.TransientGeometry.CreatePoint2d(wpViewPosition.X + 3, wpViewPosition.Y + 2))
                pnts.Add(wpViewPosition)
                sht.DrawingNotes.LeaderNotes.Add(pnts, name & "<Br/>" & vol)
            End If
        End If
    Next
End Sub
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 5

Anonymous
Not applicable

That worked a treat! just need to tweak the values on the volume but good stuff.

 

Many thanks

0 Likes
Message 4 of 5

Anonymous
Not applicable

i was too quick! how do you suppress or round the value?

 

Capture.JPG

0 Likes
Message 5 of 5

Anonymous
Not applicable
'--------------Styles Editor Code-------------
	'[	
		'Change Precision for C-Series
			oDrawDoc.StylesManager.DimensionStyles("Default (MTPI)").LinearPrecision = 41729 			
	']
'If XX = "Zero" Then : XX1 = 41729 : XX2 = 42241 : End If
'If XX = "One" Then : XX1 = 41730 : XX2 = 42242 : End If
'If XX = "Two" Then : XX1 = 41731 : XX2 = 42243 : End If
'If XX = "Three" Then : XX1 = 41732 : XX2 = 42244 : End If
'If XX = "Four" Then : XX1 = 41733 : XX2 = 42245 : End If
'If XX = "" Then : Return : End If

'For more code about this, I found this here: https://clintbrown.co.uk/2020/07/04/setting-dimension-precision-with-ilogic/

 

0 Likes