×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

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

Jobs

Size of the textbox on a drawing
2

Size of the textbox on a drawing

Size of the textbox on a drawing

(OP)
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,

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

RE: Size of the textbox on a drawing

Hi.tesak

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()
    'check
    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
        
    'copy&paste
    Dim tmp_view As DrawingView
    Set tmp_view = dr_view.Parent.Add("AutomaticNaming")
    
    Dim sel As Selection: Set sel = CATIA.ActiveDocument.Selection
    With sel
        .Copy
        .Clear
        .Add tmp_view
        .Paste
    End With
    dr_view.Activate
    
    'get size
    Dim txt_Center As Variant
    txt_Center = GetViewCenterPos(tmp_view)
    
    'remove tmp_view
    With sel
        .Clear
        .Add tmp_view
        .Delete
    End With
    
    'Calculating Position
    Dim txtpos_world As Variant
    txtpos_world = Array(dr_view.x + txt_Center(0), _
                         dr_view.y + txt_Center(1))

    'finish
    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
    
    sel.Clear
    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
End Sub 

RE: Size of the textbox on a drawing

(OP)
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 :)

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

RE: Size of the textbox on a drawing

Hi.

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!

UPD
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!


Resources


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