Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Michael.Navara
in reply to: ice_sid

In my opinion the longest edge must not be the right edge.

It is better to use semi-automatic rule, which allows you to pick the edge you want to align text to and use GeometricalConstraints to align text to this projected edge.

 

Dim pick = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeLinearFilter, "Pick the edge")
Dim edge As Edge = TryCast(pick, Edge)
If edge Is Nothing Then Return


Dim largestFace As Face = Nothing
Dim largestArea As Double = 0
For Each face As Face In edge.Faces
    'Skip non-planar faces
    If Not TypeOf (face.Geometry) Is Plane Then Continue For

    If face.Evaluator.Area > largestArea Then
        largestFace = face
        largestArea = face.Evaluator.Area
    End If
Next

'Return, when largest planar face wasn't found
If largestFace Is Nothing Then Return

Dim pointOnFace As Point = largestFace.PointOnFace

'Create sketch
Dim partDef As PartComponentDefinition = edge.Parent.ComponentDefinition
Dim sketch As PlanarSketch = partDef.Sketches.Add(largestFace)
Dim addByProjectingEntity As SketchEntity = sketch.AddByProjectingEntity(edge)
Dim textBox As Inventor.TextBox = sketch.TextBoxes.AddFitted(sketch.ModelToSketchSpace(pointOnFace), "<-->")
textBox.ShowBoundaries = True
sketch.GeometricConstraints.AddParallel(addByProjectingEntity, textBox.BoundaryGeometry(2))