Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Size of the textbox on a drawing

Size of the textbox on a drawing

Size of the textbox on a drawing

Hello guys,
I need to get width and height of a textbox in CATIA drawing in order to get a center point of the text regardless of anchor point. Do you have any ideas how to achieve it?

Thanks for your help,

http://scripts4all.eu/txtoncurve/ - Text along a curve for Catia V5

RE: Size of the textbox on a drawing


I have not tried and the processing speed may be slow, but ...
1. Create a temporary DrawingView.
2. Copy and paste any DrawingText.
3. Get size with DrawingView.size.

But your "TxtOnCurve" is wonderful.
I also thought about creating similar things before, but it did not complete ....

RE: Size of the textbox on a drawing

Try it this.

CODE --> vba

'vba test_Get_DrawingText_Center
Option Explicit

Sub CATMain()
    Call CanExec
    'select DrawingText
    Dim filter As Variant: filter = Array("DrawingText")
    Dim msg As String: msg = "select DrawingText / ESC-Cancel"
    Dim selElm  As SelectedElement: Set selElm = GetSelectElm(msg, filter)
    If selElm Is Nothing Then Exit Sub
    'get obj
    Dim dr_txt As DrawingText: Set dr_txt = selElm.value
    Dim dr_view As DrawingView: Set dr_view = dr_txt.Parent.Parent
    Dim tmp_view As DrawingView
    Set tmp_view = dr_view.Parent.Add("AutomaticNaming")
    Dim sel As Selection: Set sel = CATIA.ActiveDocument.Selection
    With sel
        .Add tmp_view
    End With
    'get size
    Dim txt_Center As Variant
    txt_Center = GetViewCenterPos(tmp_view)
    'remove tmp_view
    With sel
        .Add tmp_view
    End With
    'Calculating Position
    Dim txtpos_world As Variant
    txtpos_world = Array(dr_view.x + txt_Center(0), _
                         dr_view.y + txt_Center(1))

    msg = "** Select DrawingText Info **" & vbNewLine & _
          "Name : " & dr_txt.Name & vbNewLine & _
          "Text : " & dr_txt.Text & vbNewLine & _
          "CenterPosition in view : " & Join(txt_Center, " , ") & vbNewLine & _
          "CenterPosition in world : " & Join(txtpos_world, " , ")
    MsgBox msg
    Debug.Print msg
End Sub

'return ary(x_pos,y_pos)
Private Function GetViewCenterPos(ByVal view As Variant) As Variant
    Dim size(3) As Variant
    Call view.size(size)
    GetViewCenterPos = Array((size(0) + size(1)) * 0.5, _
                             (size(2) + size(3)) * 0.5)
End Function

Private Function GetSelectElm(ByVal msg$, ByVal filter) As SelectedElement
    Set GetSelectElm = Nothing
    Dim sel As Variant ' Selection
    Set sel = CATIA.ActiveDocument.Selection
    Select Case sel.SelectElement2(filter, msg, False)
        Case "Cancel", "Undo", "Redo"
            Exit Function
    End Select
    Set GetSelectElm = sel.Item(1)
End Function

Private Sub CanExec()
    Dim msg As String: msg = vbNullString
    Select Case True
        Case CATIA.Windows.count < 1
            msg = "Please open the CATDrawing file"
        Case Not TypeName(CATIA.ActiveDocument) = "DrawingDocument"
            msg = "Please Activate the CATDrawing file"
    End Select
    If msg = vbNullString Then Exit Sub
    MsgBox msg, vbExclamation
End Sub 

RE: Size of the textbox on a drawing

Hi kantoku,
your idea is really great. Although not very effective (I need to apply it to few hundreds of elements), but it works. Unfortunatelly it seems that there is no direct way to get bounding box (and center point) of text.

I also found one way to get center point of text, but it works only for balloons (enough for me):
  • create leader
  • get base point of a leader
  • remove leader
  • in case of balloons base point is exactly in a center of a circle
This method however could not be applied to regular text box, because then base point of a leader lies on the side of textbox. So your method is definitelly more versatile.

Thank you very much for your effort, good job :)

http://scripts4all.eu/txtoncurve/ - Text along a curve for Catia V5

RE: Size of the textbox on a drawing


I've just wasted 20 minutes describing leader approach in this crappy message editor.

Going to be short then:
1. Move text anchor to top-left
2. Create leader, get it's base point
3. Move anchor to bottom-right
4. Create another leader, get it's base point as well

Points from 2 and 4 are located exactly at bounding box opposite corners. Enjoy!

By the way, the complete code can be found at COE, function is called GetTextBoxWithAnchors (inspired by Rolando Garza, implemented by me)

RE: Size of the textbox on a drawing

Thank you.
I also learned a lot.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


eBook - Mastering Tolerances for Machined Parts
When making CNC machined parts, mastering tolerances can be challenging. Are general tolerances good enough? When does it make sense to call out for tighter tolerances? Do you need a better understanding of fits, datums, or GD&T? Learn about these topics and more in Xometry's new e-book. Download Now
eBook – How to Choose the Correct Corrosion Testing Method
When designing a metal component, engineers have to consider how susceptible certain alloys are to corrosion in the final product’s operating environment. In a recent study by NACE (National Association of Corrosion Engineers), it was estimated that the direct and indirect costs of corrosion in the United States is approximately 6.2% of the GDP. In 2016, that cost exceeded $1 trillion dollars for the first time. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close