Message 1 of 7
Quick leader adaptivity
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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