sketchText.BoundingBox

sketchText.BoundingBox

MichaelT_123
Advisor Advisor
877 Views
8 Replies
Message 1 of 9

sketchText.BoundingBox

MichaelT_123
Advisor
Advisor

Hi TF360,

 

After hours of searching for the code misbehaviour, I stumbled upon the unusual phenomenon.

 

propertyValue = sketchText_var.boundingBox ==> ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0))

 

I have pinched myself twice and slapped hard on a chin  ... still the same result. Am I sane .... ???

 

Regards

MichaelT

 

MichaelT
0 Likes
878 Views
8 Replies
Replies (8)
Message 2 of 9

MichaelT_123
Advisor
Advisor

Hi TF360,

 

I think, ... I have identified the problem!

It seems that the sketchText_var.boundingBox is calculated on the sketch open/close.

The boundingBox() does not bother recalculating the respective value while the sketch is in the editing mode.

Thus, the freshly created sketchText object has boundingBox .... not calculated !!!

 

Such methodology (or lack thereof) of dealing with boundingBox ... might spill over to the other design's aspects.

 

Ohhh, ohhh, ohhh, well, well, well ... TF360  

 

Sincerely

MichaelT

MichaelT
Message 3 of 9

BrianEkins
Mentor
Mentor

I can reproduce this and will see that a bug gets logged. 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 4 of 9

BrianEkins
Mentor
Mentor

I have some more information about this. The problem with the bounding box for text only occurs with text from old file or text created by the API using the retired createInput function. This creates the old single-line text. If you create text interactively or use the newer createInput2, the bounding box returned is correct. Because the problem is limited to retired functionality, I don't think any effort will be made to fix it.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 5 of 9

MichaelT_123
Advisor
Advisor

Hi Mr. Brian Ekins,

 

I have re-run the simple test using the code:

for skTxt in thisSketch.sketchTexts:        
    _text            = skTxt.text                   # logPoint: (_text) = {skTxt.text}
    _definition_type = type(skTxt.definition)       # logPoint: (_definition_type) = {type(skTxt.definition)}
    _textBBox        = skTxt.boundingBox            # logPoint: (_textBBox) = {(skTxt.boundingBox.minPoint.asArray(), skTxt.boundingBox.maxPoint.asArray())}
    iii = 111                                       # logPoint: (###)

The results, on the file already provided are as follwos:

(_text) = Sample Text
(_definition_type) = <class 'adsk.fusion.MultiLineTextDefinition'>
(_textBBox) = ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0))
(###)
(_text) = Sample Text
(_definition_type) = <class 'adsk.fusion.MultiLineTextDefinition'>
(_textBBox) = ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0))
(###)
   

The sketchText objects have been created using the standard UI (without any API software macka-geegee) in the previous version of F360.

The test was conducted on the freshly updated (today) the new one  Fusion 2602.0.71 x86_64.

Mind you, the the script was run on the sketch in the editing mode.

 

Regards

MichaelT

 

 

 

 

MichaelT
0 Likes
Message 6 of 9

BrianEkins
Mentor
Mentor

I was mistaken before about it being the old way of creating text. However, no matter what I do, I'm not able to create text with a zero-size bounding box. The only case I see is with the file you provided. I thought maybe it was something about the sketch being in another component, but that doesn't seem to be it either. Your text always returns the zero-size bounding box regardless of whether the sketch is active or not. If I edit the text, then I get a correct bounding box. Can you create new text that shows this behavior? Here are the functions I used for testing. One just reports the bounding box for all sketch text. The other one creates new sketch text, using both the old and new methods. I also tried creating text interactively and leaving the sketch active, but I always got back good results.

def GetExstingTextBoundingBoxTest():
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root = des.rootComponent

        for comp in des.allComponents:
            for sk in comp.sketches:
                for text in sk.sketchTexts:
                    bb = text.boundingBox
                    app.log(f'MultiLine> Min: {bb.minPoint.asArray()}, Max: {bb.maxPoint.asArray()}')
    except:  # pylint:disable=bare-except
        # Write the error message to the TEXT COMMANDS window.
        app.log(f"Failed:\n{traceback.format_exc()}")


def TextBoundingBoxTest():
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root = des.rootComponent

        # Check if a sketch is active and create the text there.
        # Otherwise, create a new sketch.
        sk: adsk.fusion.Sketch = None
        if type(app.activeEditObject) is adsk.fusion.Sketch:
            sk = app .activeEditObject
        else:
            sk = root.sketches.add(root.xYConstructionPlane)

        # Create a multiline text.
        tInput = sk.sketchTexts.createInput2('This is a test with new method.', 1.5)
        tInput.setAsMultiLine(adsk.core.Point3D.create(0,0,0),
                              adsk.core.Point3D.create(5,2,0),
                              adsk.core.HorizontalAlignments.CenterHorizontalAlignment,
                              adsk.core.VerticalAlignments.MiddleVerticalAlignment,
                              0)
        text = sk.sketchTexts.add(tInput)
        bb = text.boundingBox
        app.log(f'MultiLine> Min: {bb.minPoint.asArray()}, Max: {bb.maxPoint.asArray()}')

        # Create text with the retired function.
        tInput = sk.sketchTexts.createInput('This is a test with old method',
                                            1.5,
                                            adsk.core.Point3D.create(1,0,0))
        text = sk.sketchTexts.add(tInput)
        bb = text.boundingBox
        app.log(f'Retired> Min: {bb.minPoint.asArray()}, Max: {bb.maxPoint.asArray()}')
    except:  # pylint:disable=bare-except
        # Write the error message to the TEXT COMMANDS window.
        app.log(f"Failed:\n{traceback.format_exc()}")
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 7 of 9

MichaelT_123
Advisor
Advisor

Hi Mr. Brian Ekins,

 

 I created the new design/sketch from scratch. The file is attached.

I enhanced the sketchText Object … to more real-life content … and re-run the test script from my previous post.

The results are:

(_text) = Sample Text

Szczebrzeszyn

W szeleszczących trzcinach 
Wąż się zwinnie wije i tudzież 
Chrząszcz groźnie brzęczy na 
Pajączka w pajęczynie, więc 
Szczebrzeszyn z tegoż słynie!
(_definition_type) = <class 'adsk.fusion.MultiLineTextDefinition'>
(_textBBox) = ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0))
(###)
(_text) = Sample Text

Kaczka dziwaczka

Nad rzeczką opodal krzaczka
Mieszkała kaczka-dziwaczka,
Lecz zamiast trzymać się rzeczki
Robiła piesze wycieczki.

Raz poszła więc do fryzjera:
"Poproszę o kilo sera!"

Tuż obok była apteka:
"Poproszę mleka pięć deka."

Z apteki poszła do praczki
Kupować pocztowe znaczki.

Gryzły się kaczki okropnie:
"A niech tę kaczkę gęś kopnie!"

Znosiła jaja na twardo
I miała czubek z kokardą,
A przy tym, na przekór kaczkom,
Czesała się wykałaczką.

Kupiła raz maczku paczkę,
By pisać list drobnym maczkiem.
Zjadając tasiemkę starą
Mówiła, że to makaron,
A gdy połknęła dwa złote,
Mówiła, że odda potem.

Martwiły się inne kaczki:
"Co będzie z takiej dziwaczki?"

Aż wreszcie znalazł się kupiec:
"Na obiad można ją upiec!"

Pan kucharz kaczkę starannie
Piekł, jak należy, w brytfannie,

Lecz zdębiał obiad podając,
Bo z kaczki zrobił się zając,
W dodatku cały w buraczkach.
Taka to była dziwaczka!
(_definition_type) = <class 'adsk.fusion.MultiLineTextDefinition'>
(_textBBox) = ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0))
(###)

If I may suggest … looking at the completeness of the sketchText Object constructor might give the answer to the mystery. It seems that boundingBox attribute is not calculated/updated at the stage of closing the newly UI created sketchText. Some, but not all, editing actions on the object … do the recalculations and update the property.

SketchTextTest Pinch_Pinch_Slap!.png

 

 

Regards

MichaelT

MichaelT
0 Likes
Message 8 of 9

corbin2
Enthusiast
Enthusiast

Justing pinging to say that I see a similar problem. Latest version of Fusion still seems to cache an incorrect boundingBox in some cases.  I'm not sure when or why..

Corbin

Message 9 of 9

MichaelT_123
Advisor
Advisor

Thank you, Mr Corbin2,

 

... as far as I understand your post, it politely states that I am not insane.

What a relief! Huuurrraaa!

 

Regards

MichaelT

MichaelT