03-20-2024
11:44 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
03-20-2024
11:44 PM
Wishing everyone a great day!
I ask for advice on how to orient the text along the largest edge.
In wood processing there is a need to control wood grain texture vector in detail. For most of the details, I think the solution is to find the largest face of the detail. Then place the symbol indicating the direction of the material in the text box. The task has been partially solved.
Some examples of code were collected on the forum pages, which provided the following.
' Get the current details document
Dim oPart As PartDocument = ThisApplication.ActiveDocument
' Get the part component definition
Dim oCompDef As PartComponentDefinition = oPart.ComponentDefinition
'Initialize variables to store the largest face and its area
Dim maxFace As Face = Nothing
Dim maxArea As Double = 0.0
' Find the edge with the largest area
For Each oFace As Face In oCompDef.SurfaceBodies.Item(1).Faces
' Calculate the face area
Dim oAreaProps As Double
oAreaProps = oFace.Evaluator.Area
' Check whether the current face is the face with the largest area
If oAreaProps > maxArea Then
maxArea = oAreaProps
maxFace = oFace
End If
Next
' Create a sketch on the plane of the selected face
Dim oSketch As Sketch = oCompDef.Sketches.Add(maxFace)
' Find the face contour with index 1
Dim oEdgeLoop As EdgeLoop = maxFace.EdgeLoops(1)
' Find the minimum and maximum point of the bounding parallel
Dim oMinPt As Point = oEdgeLoop.RangeBox.MinPoint
Dim oMaxPt As Point = oEdgeLoop.RangeBox.MaxPoint
' Find the center of the bounding parallelepiped circuit
Dim CenterPt As Point = ThisApplication.TransientGeometry.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)
' Let’s convert the coordinates of the center into the coordinates of the sketch
Dim oTextPt As Point2d = oSketch.ModelToSketchSpace(CenterPt)
'Add text "Largest face" to the sketch center
oText = "↔"
Dim oTextBox As TextBox = oSketch.TextBoxes.AddFitted(oTextPt, oText)
' Set new text height (centimeters)
oFontSize = 6
oTextBox.FormattedText = "<StyleOverride FontSize = '" & oFontSize & "'>" & oText & "</StyleOverride>"
oTextBox.HorizontalJustification = kAlignTextCenter
oTextBox.VerticalJustification = kAlignTextUpper
iLogicVb.UpdateWhenDone = TrueWhat are the ways to orient the text along the largest edge?
Solved! Go to Solution.