Sketch.boundingBox is not reporting correctly current sketch boundary box

Sketch.boundingBox is not reporting correctly current sketch boundary box

gscotti
Enthusiast Enthusiast
1,852 Views
6 Replies
Message 1 of 7

Sketch.boundingBox is not reporting correctly current sketch boundary box

gscotti
Enthusiast
Enthusiast

an excerpt from my script:

        splineCurves = ag.project(sketch2)
        offsetSplineCurves = do_offset(splineCurves, self.inputs.basic.thickness.value) # local function calls sketch2.offset

        bbox = sketch2.boundingBox
        p0,p1 = bbox.minPoint,bbox.maxPoint
        print((p0.x,p0.y,p0.z),(p1.x,p1.y,p1.z))
print(sketch2.healthState, sketch2.isParametric, sketch2.isValid, sketch2.isComputeDeferred)

Returns:

(-1e+30, -1e+30, -1e+30) (1e+30, 1e+30, 1e+30)
0 True True False

Curiously, if I run another script right after this, that takes the same sketch object as selection, it reports correctly.

I'll try to create an stand alone version of this issue if you cannot repro it.

 

Attached screenshot.

0 Likes
1,853 Views
6 Replies
Replies (6)
Message 2 of 7

ekinsb
Alumni
Alumni

Is the sketch2 variable referencing a Sketch?  If so, that's not valid input for the project method.  I suspect that the project failed so there aren't any offset curves which would result in the min and max points of the bounding box being the same.  It's very useful to add a try except statement to all of your functions so that it will be obvious when something fails.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 7

gscotti
Enthusiast
Enthusiast

I tried to abstract my wrapper functions to Fusion's API, but failed on comment.

I'm attaching an working example of this failure.

Select the base face from given model and you will see what I was talking about. (look at stdout - I typically type print() at spyder2 console to get stdout flushed

 

0 Likes
Message 4 of 7

gscotti
Enthusiast
Enthusiast

Forgot to add initial point to close curve. Here it goes (v2).

 

0 Likes
Message 5 of 7

ekinsb
Alumni
Alumni

I'm able to reproduce the problem.  It appears to be a general problem with getting the bounding box from sketch geometry and sketches.  The only entity that worked correctly for me is sketch lines.  All others return the large bounding box that you're seeing.  I've file a defect so we can fix it in a future update.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 6 of 7

gscotti
Enthusiast
Enthusiast

Thanks for replying. I have two more bugs to report.

First, if you get my script and change line #115 moving it to after component creation, selection is gone!

        # create new component
        parent = design.rootComponent
        occurrence = parent.occurrences.addNewComponent(core.Matrix3D.create())
        component = occurrence.component

        # take selected face
        face = self.selectionInput.selection(0).entity

Second is, if you create a rectangle with large dimensions - i.e., same dimensions as reported by boudingBox, whole Fusion 360 app goes crazy.

 

0 Likes
Message 7 of 7

ekinsb
Alumni
Alumni

The first issue isn't a bug but a result of Fusion's behavior.  Selections are relatively fragile and if you do something to change the model they will be cleared.  To work around this behavior in your example, you can first get the selection and save the reference in a variable, create the component, and then do whatever you intended to do with the selected entity.

 

For the second issue, it doesn't surprise me.  There are limitations, both with very very small and large objects.  This is because of how the modeling kernel is implemented and also as a result of how floating point math is done on a computer.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes