Hi @abrahambarroeta. What you are asking for may be possible to some degree, but it will be pretty complicated to achieve by custom code, and the results will not be constrained. For one thing, you can't just get the angle of the line, then set that angle to the other line...it's way more complicated than that. We are dealing with a bunch of Point2d, Vector2d, and UnitVector2d objects. A Vector2d has both direction and magnitude (length), but do not provide a direct property for what angle they are from some imaginary fixed line. The 'direction' of the vector is determined by passing an imaginary line from a 0,0 coordinate through the X & Y coordinates it provides, which can be difficult to picture in your mind. And since view line you pick has a direction, not just an angle, that direction may be pointing in the opposite direction than you expect, which potentially has to be corrected later in the code. Another complication of this process is that we have to specify coordinates for where to place the node on the sheet, which is often a matter of personal preference and style. This code just tries to create a new node half way between the two existing nodes, then move that node to a position that makes the visible line look parallel with the view line, while leaving the balloon in place.
I have an iLogic rule you can try out for this task, and develop further if you want. When ran, it first asks you to select a straight drawing view line to use for aligning the balloon leader with. Then it asks you to select a Balloon (can't select just its leader or a leader segment) that you want to align with that line. There is a lot of code in there, and it could likely be done more efficiently, but it seemed to be working OK in my testing.
'<<< Drawing Curve section >>>
Dim sPrompt As String = "Select a straight drawing view line to align balloon leader with."
Dim oFilter As SelectionFilterEnum = SelectionFilterEnum.kDrawingCurveSegmentFilter
Dim oDCS As DrawingCurveSegment = ThisApplication.CommandManager.Pick(oFilter, sPrompt)
If oDCS Is Nothing Then Exit Sub
Dim oLineDir As UnitVector2d = Nothing
Dim bLineDirXPositive As Boolean = False
Dim bLineDirYPositive As Boolean = False
If oDCS.GeometryType = Curve2dTypeEnum.kLineCurve2d Then
Dim oL2D As Line2d = oDCS.Geometry
oLineDir = oL2D.Direction
bLineDirXPositive = (oLineDir.X > 0)
bLineDirYPositive = (oLineDir.Y > 0)
ElseIf oDCS.GeometryType = Curve2dTypeEnum.kLineSegmentCurve2d Then
Dim oLS2D As LineSegment2d = oDCS.Geometry
oLineDir = oLS2D.Direction
bLineDirXPositive = (oLineDir.X > 0)
bLineDirYPositive = (oLineDir.Y > 0)
Else
MsgBox("Selected Geometry Is Not A Straight Line", , "")
Exit Sub
End If
Logger.Info("Line Direction Is Positive? = " & bLineDirXPositive & vbCrLf & _
"Direction Coordinates = " & oLineDir.X & " , " & oLineDir.Y)
' <<< Balloon section >>>
sPrompt = "Select a Balloon to allign."
oFilter = SelectionFilterEnum.kDrawingBalloonFilter
Dim oBalloon As Inventor.Balloon = ThisApplication.CommandManager.Pick(oFilter, sPrompt)
If oBalloon Is Nothing Then Exit Sub
Dim oLeader As Inventor.Leader = oBalloon.Leader
If oLeader.HasRootNode = False Then Exit Sub
Logger.Info("HasRootNode = True")
Dim oRootNode As LeaderNode = oLeader.RootNode
Logger.Info("RootNode Position = " & oRootNode.Position.X & " , " & oRootNode.Position.Y)
Dim oNodes As LeaderNodesEnumerator = oLeader.AllNodes
If oNodes.Count < 2 Then Exit Sub
Dim oLastNode As LeaderNode = oNodes.Item(oNodes.Count)
Logger.Info("Last Node Position = " & oLastNode.Position.X & " , " & oLastNode.Position.Y)
Dim oNextNode As LeaderNode = oNodes.Item(oNodes.Count - 1)
Logger.Info("Next Node Position = " & oNextNode.Position.X & " , " & oNextNode.Position.Y)
Dim oV2D As Vector2d = oLastNode.Position.VectorTo(oNextNode.Position)
Dim oNodesDir As UnitVector2d = oV2D.AsUnitVector
Dim bNodesDirXPositive As Boolean = (oNodesDir.X > 0)
Dim bNodesDirYPositive As Boolean = (oNodesDir.Y > 0)
Logger.Info("Nodes Direction Is Positive? = " & bNodesDirXPositive & vbCrLf & _
"Direction Coordinates = " & oNodesDir.X & " , " & oNodesDir.Y)
If oNodesDir.IsParallelTo(oLineDir) Then Exit Sub
'<<< create new node half way between these two existing nodes >>>
Dim oNewP2D As Point2d = oLastNode.Position.Copy
oV2D.ScaleBy(0.5)
oNewP2D.TranslateBy(oV2D)
Dim oNewNode As LeaderNode = oRootNode.InsertNode(oLastNode, oNewP2D)
'<<< compare direction of view line and direction between nodes >>>
'<<< may need to do some math here to determine if directions need to be flipped >>>
Dim bBothXPos, bBothYPos, bBothXNeg, bBothYNeg, bXDiff, bYDiff As Boolean 'False by default
If bLineDirXPositive And bNodesDirXPositive Then
bBothXPos = True
ElseIf bLineDirXPositive = False And bNodesDirXPositive = False Then
bBothXNeg = True
Else
bXDiff = True
End If
If bLineDirYPositive And bNodesDirYPositive Then
bBothYPos = True
ElseIf bLineDirYPositive = False And bNodesDirYPositive = False Then
bBothYNeg = True
Else
bYDiff = True
End If
Dim oFinalP2D As Point2d = oLastNode.Position.Copy
If bBothXPos And bBothYPos Then
ElseIf bBothXNeg And bBothYNeg Then
ElseIf bXDiff And bYDiff Then 'when directions may need to be flipped
oLineDir.X = (oLineDir.X * -1) 'toggle between positive or negative
oLineDir.Y = (oLineDir.Y * -1) 'toggle between positive or negative
End If
Dim oFinalV2D As Vector2d = oLineDir.AsVector
oFinalV2D.ScaleBy(oLastNode.Position.DistanceTo(oNewNode.Position))
oFinalP2D.TranslateBy(oFinalV2D)
oNewNode.Position = oFinalP2D
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)