03-21-2024
09:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
03-21-2024
09:25 AM
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))