sketch on a face with dimension text

sketch on a face with dimension text

Anonymous
Not applicable
627 Views
5 Replies
Message 1 of 6

sketch on a face with dimension text

Anonymous
Not applicable

Hi,

I would like to create a text on a face we select.  The text should be the length of the selected face.

 

For example. We have a square with 100x80mm (thickness doesn't matter). On a top face, we want a text with the length (100mm). It would be good if fontsize could be adjustable in code. Is that possible to create using iLogic?

 

Appreciate the help.

0 Likes
Accepted solutions (1)
628 Views
5 Replies
Replies (5)
Message 2 of 6

Michael.Navara
Advisor
Advisor

Try this sample. It works on faces parallel to XY. You need to specify what do you mean "length of face". I use global size of face in X and Y direction.

 

 

Sub Main()
    Dim pick = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select face")
    Dim face As Face = pick

    Dim faceBox = face.Evaluator.RangeBox
    Dim x As Double = faceBox.MaxPoint.X - faceBox.MinPoint.X
    Dim y As Double = faceBox.MaxPoint.Y - faceBox.MinPoint.Y

    'To [mm]
    x *= 10
    y *= 10

    Dim partDef As PartComponentDefinition = face.Parent.Parent
    Dim planarSketch = partDef.Sketches.Add(face)

    'Fixed position
    'Dim position As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)

    'Projected center of mass
    Dim position As Point2d = planarSketch.ModelToSketchSpace(partDef.MassProperties.CenterOfMass)
    
    planarSketch.TextBoxes.AddFitted(position, String.Format("{0}x{1}", x, y))

End Sub

 

 

0 Likes
Message 3 of 6

Anonymous
Not applicable

Look at the attached picture. I need this length to be as a text on the measured face. If I understand right, the dimension in your code is from 0,0 point in the global coordinate system? I only need the dimension of the specific element.

0 Likes
Message 4 of 6

Michael.Navara
Advisor
Advisor

In my example is shown how to:

  • Pick face
  • Get its dimensions
  • Convert coordinates of Point in model space to sketch space 
  • Create new sketch on selected face
  • Add text box to this sketch

Now you need to test my code on simple model (simple box for example). Then you can try to modify this code to your needs. Size of the face can be calculated in many ways and only you know what is the right way. You can read some parameters value, calculate distance between vertices, etc.

 

Message 5 of 6

Anonymous
Not applicable

Thank you! Solved my problem. One more question.. How can I convert decimal numbers to integer? I am new to iLogic

0 Likes
Message 6 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

In this case it is not necessary convert double to int. You can use formatting in String.Format function. See https://docs.microsoft.com/en-us/dotnet/api/system.string.format?view=net-5.0#control-formatting

for more information. 

For example string.Format("{0:N0}", 1.213) returns "1" (First argument has zero decimal places)