Baloons: how to get position of label text

Valued Contributor
Valued Contributor

 

Hello all,

I'm trying to import drawings to raster images from SolidEdge to be used in a different custom application. Drawings has elements referenced by balloons with ref numbers. Balloons successfully become part of the raster tif image. But then I need to identify coordinates of balloon text to be able to create a hotspot above the ref number at the image.

I need a way to get position of balloon text. I've found NO suitable methods in API. '.Range' method returns complete balloon size including terminator arrow, but I need just a position of notation text. The only solution I found so far is to create a text balloon object w/o terminator arrow and subtract it's size from a corresponding corner of total surrounding box depending on the direction of the arrow. Please see the code below:

                     // get total bounding rectangle including terminator arrow

                     recTextRange = SolidEdgeRectangle.GetBoundingRectangle(baloonAutoPtr);

                    double xTerm, yTerm, zTerm = 0;                   

                    int h;

                    SolidEdgeFramework.KeyPointType t;

                    // get terminator point

                    baloonAutoPtr.GetKeyPoint(0, out xTerm, out yTerm, out zTerm, out t, out h);

 

                    // create test balloon w/o terminator arrow to get sizes of

                    if (probeBaloon == null)

                    {

                        probeBaloon = ((SolidEdgeFrameworkSupport.Balloons)SolidEdgeApplication.ActiveWindow.ActiveSheet.Balloons).Add(xTerm, yTerm, zTerm);

                    }

                    probeBaloon.BalloonType = baloonAutoPtr.BalloonType;

                    probeBaloon.Style.Font = baloonAutoPtr.Style.Font;

                    probeBaloon.Style.TextClearanceGap = baloonAutoPtr.Style.TextClearanceGap;

                    probeBaloon.BalloonText = baloonAutoPtr.BalloonText;

                    SolidEdgeRectangle recProbeTextRange = SolidEdgeRectangle.GetBoundingRectangle(probeBaloon);

 

                    // get width and height of the probe hotspot                   

                    double hspWidth = recProbeTextRange.Width;

                    double hspHeight = recProbeTextRange.Height;

                    double dispXleftConer;

                    double dispXrightConer;

                    double dispYtopConer;

                    double dispYbottomConer;

                    // correct position depending on the properties of the balloon, probably incorrect, need to count all different properties of the balloon

                     if (!baloonAutoPtr.BreakLine)

                    {

                        dispXleftConer = 0.05 * hspHeight;

                        dispXrightConer = -0.05 * hspHeight;

                        dispYtopConer = -0.15 * hspHeight;

                        dispYbottomConer = 0.15 * hspHeight;

                    }

                    else

                    {

                        dispXleftConer = -0.16 * hspWidth;

                        dispXrightConer = -0.39 * hspWidth;

                        dispYtopConer = 0.3 * hspHeight;

                        dispYbottomConer = 0.65 * hspHeight;

                    }

                    double hspX = recTextRange.Left;

                    double hspY = recTextRange.Top;

                    // step out the found width and height from the corner opposite to terminator arrow

                    if (Math.Abs(recTextRange.Left - xTerm)

                    else hspX = recTextRange.Left + dispXleftConer;

                    if (Math.Abs(recTextRange.Top - yTerm)

                    else hspY = recTextRange.Top + dispYtopConer;

                    // create new rectangle, supposed to be over text label of the balloon

                    recTextRange = new SolidEdgeRectangle(hspX, hspY, hspX + hspWidth, hspY + hspHeight);                   

 

 I have to introduce correction coefficients if balloon has breakline for example. The code not always works correctly.

Is there a direct way to obtain balloon text position and size? How can I remove terminator so that balloon.Range() returned only notation text position? Is there more elegant way to resolve this problem?

Please help! Thanks

 

 

Posted by: Valeriy Romanov
Post date: 9/9/2008 12:38:17 PM

1 REPLY

RE: Baloons: how to get position of label text

Valued Contributor
Valued Contributor

 

Hi,

i solved the problem getting the text position of any of the balloon labels by copying all balloons i'm interested in to the clipboard. Then paste and group the pasted objects (balloons). For each balloon in the group remove all items (leader, breakline, texts) except the text you are interested in. Be aware that a positive x-offset happens when switching off leader/breakline. Now you can take use of  the Range method etc. to get the needed coordinates.

Here a code snippet for that interesting part:

       '(1) Copy balloons of matching criteria to the clipboard

        With gobjDoc.SelectSet

            'Clear SelectSet

            .RemoveAll

            For Each objBalloon In objBalloons

                  'Code for matching criteria is missing

                  'Add balloon matching criteria to SelectSet

                   .Add objBalloon

            Next

            'Copy selection to clipboard

            .Copy

            'Clear SeletSet

            .RemoveAll

        End With

 

        '(2) Paste clipboard contents

        gobjApp.StartCommand SolidEdgeConstants.DetailCommandConstants.DetailEditPaste

        '(3) Group pasted contents

        Set objGroup = objSheet.Groups.Add(Filename(App.EXEName))

 

        '(4) Remove leader/breakline and correct resulting x-offset

        For Each objBalloon In objGroup.Balloons

            With objBalloon

                If .BreakLine Then

                    .GetVertex 1, x1tmp, y1, z

 

                    bldist = .BreakLineDistance

                    bldir = .BreakLineDirection

 

                    .Leader = False

                    .Range x1, y1, x2, y2

                    wT = x2 - x1 + 0.75 * .Style.Height 'Empirical

 

                    If bldir Then

                        x1 = x1tmp - bldist - wT / 2#

                    Else

                        x1 = x1tmp + bldist + wT / 2#

                    End If

 

                ElseIf .Leader Then

                    .GetVertex 1, x1, y1, z

                Else

                    .GetFreeSpacePoint x1, y1, z

                End If

 

                .Leader = False

                .GetFreeSpacePoint x2, y2, z

 

                xoffset = x1 - x2

 

                .Move x2, y2, x2 + xoffset, y2

            End With

 

            '(5) Process balloon copy

            If Not ProcessBalloon(objBalloon, intSheetNo, colMapFile) Then

                Err.Raise 999, "ProcessBalloons", "Auswertung eines Balloons fehlgeschlagen", 4

            End If

        Next

 

I hope this may help you.

 

Posted by: Wolfgang Kunert
Post date: 9/15/2008 10:20:38 PM