Bounding box around edges

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
LeviFiction
Posts: 18
Joined: Thu Jul 10, 2014 4:19 am

Bounding box around edges

Post by LeviFiction »

When I select a layer both in program and in script the boundaries seem focused on the points of the layer and not the curved edges. Just wondering, is there a pre-made routine or option for getting what the boundaries would be around the whole shape curves and all? Right now the curves extend beyond the bounding box presented?

Backstory;
So, this isn't really that big of a deal. But i thought i would ask just to check.

i was going through the help files and noticed that the only way to set the layer origin is manually, either with document coordinates or by clicking somewhere. This is nice as most of the time it won't be necessary to change the layer origin and if you do it rarely has to be precise. But it still bugged me that there wasn't a single click solution (at least not that I could find) so I turned to scripts.

i made a tiny script that:

1) checks to see if a selection exists on the current layer
2) if no selection, select everything in the layer
3) grab selected center
4) sets layer center as selected center

Nothing fancy, just enough to do what i need it to, quickly. And it works perfectly when the points are at the outer most part of the layer edges. But with oblong shapes where the curves extend beyond the points the center is slightly offset. Not by a lot. But enough that I'm curious if someone has worked out how to calculate the width and height of the layer based on the physical path and not just the points.

in the image below you can see where the layer origin was set compared to where the bbox center is set in the 'what i want to see' example.

Image
User avatar
synthsin75
Posts: 9935
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Bounding box around edges

Post by synthsin75 »

The Moho tools draw the bounding box around the points, even if the layer origin is centered in the shape. If you just want to set the origin in the center of the shape, you can just use: http://mohoscripting.com/methods/817
And you could probably average the centers of multiple selected or all shapes.



If you wanted to draw a shape-accurate bounding box, you'd probably need to take a look at the LM bounding box class: http://mohoscripting.com/classes/LM_BBox

You could probably get the curves of all the selected points, sample locations along the curves by percentage(1), accumulate those into your bounding box(2), and get the bounding box center.

(1) http://mohoscripting.com/methods/798
(2) http://mohoscripting.com/methods/186
Post Reply