Center a leader on an edge.

Center a leader on an edge.

Anonymous
Not applicable
594 Views
3 Replies
Message 1 of 4

Center a leader on an edge.

Anonymous
Not applicable

Greetings,  I am using Inventor 2016 and Windows7

 

Attached are the part files I am using to develop this process.

Currently, the code labled "Leaderswithspecificedge" creates a leader on the corner of the edge and not the midpoint of the edge.

So, one would think you need to get the midpoint of the edge right?  So it was created about half way down the code.

However, when I use the midpoint it creates a leader that is actually inside the box and not outside.

I removed the second node because it was not necessary.  

 

I have been playing around with the translations on the oLeaderPoints and it now creates what I want.  Just needs to be on the midpoint of the line.

 

 

Thoughts on how to make this work?  

Since this is answers day, might as well ask.

 

 

SyntaxEditor Code Snippet

'edge for this view{3,6,9,12}

    
    Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
         
    Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet
         
    Dim orefdoc As PartDocument = ThisApplication.Documents.Open("K:\Part1.ipt", False)
    
    Dim oDrawingCurvesEnum As DrawingCurvesEnumerator
       
    Dim oEdge As Edge = orefdoc.ComponentDefinition.SurfaceBodies.Item(1).Edges.Item(6)
            
    Dim oView As DrawingView = oDrawDoc.ActiveSheet.DrawingViews.Item(1)
        
     oDrawingCurvesEnum = oView.DrawingCurves(oEdge)
   
    Dim oDrawingCurve As DrawingCurve = oDrawingCurvesEnum.Item(1)

   
    Dim oMidPoint As Point2d = oDrawingCurve.MidPoint

    
    Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

    Dim oLeaderPoints As ObjectCollection
     oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection

    ' Create a few leader points.
     oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X-2.54, oMidPoint.Y+6))
     'oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X+1, oMidPoint.Y + 6))

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

     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 = "API Leader Note"

    Dim oLeaderNote As LeaderNote
     oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
     
    ' Insert a node.
    Dim oFirstNode As LeaderNode
     oFirstNode = oLeaderNote.Leader.RootNode.ChildNodes.Item(1)

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

     'oFirstNode.InsertNode(oSecondNode, oTG.CreatePoint2d(oMidPoint.X, oMidPoint.Y + 5))

photo of what is happenening

 

leaderphoto.png

 

0 Likes
Accepted solutions (1)
595 Views
3 Replies
Replies (3)
Message 2 of 4

ekinsb
Alumni
Alumni
Accepted solution

What you have is so close.  You need to specify the attachment point as part of the geometry intent, not as part of the leader definition.  I fyou just add the second argument to the CreateGeometryIntent, as shown below you should get the result you're looking for.

 

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

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 4

Anonymous
Not applicable

Ekins,

Awesome.  Thanks for Identifying the issue and sharing your knowledge!

 

0 Likes
Message 4 of 4

V_L_F
Enthusiast
Enthusiast

Greetings Brian,

 

I know that it's been a while since this particular post has seen any activity, but I'm running into an issue with the code block that you guys were discussing.  I'm trying to adapt the code block into a project of mine, and I keep getting a Run-time error '5' when I get to the line of code marked below:

Sub VIEW1LeaderCreator()
    ' This sub block will create the leader notes for the Crate model in VIEW1.

    ' Set a reference to the drawing document.
    Dim oDrawDoc As Inventor.DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
    
    ' Set a reference to the active sheet.
    Dim oSheet As Inventor.sheet
    Set oSheet = oDrawDoc.ActiveSheet
       
    ' Set a reference to the first drawing view (VIEW1).
    Dim oView As Inventor.DrawingView
    Set oView = oSheet.DrawingViews.Item(1) ' Sets oView to "117441536", a.k.a. "VIEW1".
    
    ' Set a reference to all drawing views.
    Dim oViews As DrawingViews
    Set oViews = oSheet.DrawingViews
    
    ' Set a reference to the assembly document.
    Dim oAssemblyDoc As Inventor.AssemblyDocument
    Set oAssemblyDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
    
    ' Readies code for creation of reference points for dimension placement.
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry
'-------------------------------------------------------------------------------------
    ' Set a reference to the FileManager Object.
    Dim oFileManager As FileManager
    Set oFileManager = ThisApplication.FileManager
    
    Dim sFullFileName As String
    sFullFileName = "C:\Assembly1.iam"
    
    ' Get the name of the last active LOD representation.
    Dim sLastActiveLOD As String
    sLastActiveLOD = oFileManager.GetLastActiveLevelOfDetailRepresentation(sFullFileName) ' Produces "iLogic"
    
    ' Get the full document name using the full file name & LOD name.
    Dim sFullDocName As String
    sFullDocName = oFileManager.GetFullDocumentName(sFullFileName, sLastActiveLOD) ' Produces "C:\Assembly1.iam<iLogic>"

    Dim oRefDoc As AssemblyDocument
    Set oRefDoc = ThisApplication.Documents.Open(sFullDocName, False)
    
    Dim oEdge As Edge
    Set oEdge = oRefDoc.ComponentDefinition.Occurrences.ItemByName("top_endcap_r").SurfaceBodies.Item(1).Edges.Item(11) ' Produces "67120288"
    
    Dim oDrawingCurvesEnum As DrawingCurvesEnumerator
    Set oDrawingCurvesEnum = oView.DrawingCurves(oEdge)

Dim oDrawingCurve As DrawingCurve
Set oDrawingCurve = oDrawingCurvesEnum.Item(1) ' THIS is where the run-time error 5 code keeps appearing. '.......' End Sub

My goal is to grab an edge of an iPart named "top_endcap_r" within my assembly model (Assembly1.iam), and use that edge to generate a leader note when I execute my macro.  Since the "top_endcap_r" iPart is nested within my assembly model, I created the sFullFileName, sLastActiveLOD & sFullDocName variables for use in defining the oRefDoc variable.  But I can't get past this cursed error, and it's driving me insane.  I'm wondering if I somehow goofed up the definition of oRefDoc...

 

Would you be able to help shed some light into what I'm doing wrong so that I can get this code snippet to behave?  Any help that you can provide would be immensely appreciated.  If you can offer a solution that actually gets my code block to work as I've intended, I'll totes give you a kudo and link this solution to my original posting (found here).

 

Thank you for your time.  I hope to hear from you soon!

 

- Sincerely,
Vinny

0 Likes