Inventor Drawing: Need to Create a Leader with Respect to the Point Selected

Inventor Drawing: Need to Create a Leader with Respect to the Point Selected

RoyWickrama_RWEI
Advisor Advisor
525 Views
4 Replies
Message 1 of 5

Inventor Drawing: Need to Create a Leader with Respect to the Point Selected

RoyWickrama_RWEI
Advisor
Advisor

I have found help form the forum for creating a leader with respect to a drawing curve (line) selected. That is fine. Thanks to the forum.

But, I am eager to have the leader created based on the point selected. Please see below.

    oPoint_Selected = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingDefaultFilter, "Select a point on any drawing curve")
    ' Get the point of the selected curve
    Dim oPoint As Point2d
    oPoint = oPoint_Selected

I look forward to receiving help.

0 Likes
526 Views
4 Replies
Replies (4)
Message 2 of 5

chandra.shekar.g
Autodesk Support
Autodesk Support

@RoyWickrama_RWEI,

 

As there is no SelectionFilterEnum for drawing point selection, appropriate SelectionFilterEnum would be DrawingCurveSegmentFilter. Hoping that below VBA code would help to create Leader.

 

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

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

    ' Set a reference to the drawing curve segment.
    ' This assumes that a drawing curve is selected.
    Dim oDrawingCurveSegment As DrawingCurveSegment
    Set oDrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a point on any drawing curve")
     

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

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

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

    Dim oLeaderPoints As ObjectCollection
    Set oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection

    ' Create a few leader points.
    Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 2, oMidPoint.Y + 2))
    
    ' 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
    Set 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 = "API Leader Note"

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

    
End Sub

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Like".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 5

RoyWickrama_RWEI
Advisor
Advisor

Thanks a lot.

I like to get the coordinates of the user selected point while it could be any drawing curve from within current drawing sheet.

Could you help. Thanks.

 

Roy Wickrama

 

0 Likes
Message 4 of 5

RoyWickrama_RWEI
Advisor
Advisor

Basically, I need to create the view labels using leaders because the labels so created are very friendly: they can be underlined or bold as required, deleted unnecessary or add additional text, add blank row etc..

I am using the center of the selected view. I am getting what I need, but I have two issues:

  • I am still selecting a linear drawing curve (in addition to selecting a drawing view)
  • Leader exists after the rule is done (need to know how can I delete the leader)

I delete the leader (manually) at the end.

 

Is it possible to assign the ordinates of the picked point (oPickedPoint) in the view:

e.g.: ...CreatePoint2d(oPickedPoint)

 

Sub Main()
On Error Goto 100:' 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
        
' Manually select a drawing view
Dim oDrawingView As DrawingView
oDrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "SELECT A DRAWING VIEW:")
oDrawingViewName = oDrawingView.Name

    oCurve_Selected = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "SELECT A SUITABLE CURVE FROM A DRAWING VIEW")
    ' Set a reference to the drawing curve segment.
    ' This assumes that a drawing curve is selected.
    Dim oDrawingCurveSegment As DrawingCurveSegment
    oDrawingCurveSegment = oCurve_Selected        'oDrawDoc.SelectSet.Item(1)

    ' Set a reference to the drawing curve.
    Dim oDrawingCurve As DrawingCurve
    oDrawingCurve = oDrawingCurveSegment.Parent
    
' a reference to the center of the base view.
Dim oPoint As Point2d
oPoint = oDrawingView.Center

    Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    Dim oLeaderPoints As ObjectCollection
    oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection

    ' Create a few leader points.
oAdjust_X_Left = -oDrawingView.Width*0
oAdjust_Y_Down = -oDrawingView.Height/2-1
MessageBox.Show("oAdjust_Y: " & oAdjust_Y_Down, "Title")

    Call oLeaderPoints.Add(oTG.CreatePoint2d(oPoint.X + oAdjust_X_Left, oPoint.Y + oAdjust_Y_Down))

    Dim oGeometryIntent As GeometryIntent
    oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve)        

    Call oLeaderPoints.Add(oGeometryIntent)
    Dim sText As String
    oModelDoc = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
    If iProperties.Value(oModelDoc, "Custom", "TOTAL_QTY") = "1" Then  
    iProperties.Value(oModelDoc, "Custom", "TOTAL_QTY_VL") = "ONE"
    Else
    iProperties.Value(oModelDoc, "Custom", "TOTAL_QTY_VL") = iProperties.Value(oModelDoc, "Custom", "TOTAL_QTY")
    End If
    'sText = "API Leader Note"
    oTOTAL_QTY_VL = iProperties.Value(oModelDoc, "Custom", "TOTAL_QTY_VL")
    oTITLE = iProperties.Value(oModelDoc, "Summary", "Title")
    oPartNumber = iProperties.Value(oModelDoc, "Project", "Part Number")
    sText =  oTOTAL_QTY_VL & " REQ'D " &  " - " & oTITLE & " - " & oPartNumber _
    & vbCrLf & "NOTE:" & vbCrLf & "SOME COMPONENTS NOT SHOWN FOR CLARITY"
    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)
100:End Sub

Could you help.

Thanks.

 

0 Likes
Message 5 of 5

RoyWickrama_RWEI
Advisor
Advisor

I also see some other issue:

The contents are static. Use is limited.

0 Likes