Offset bounding box

I need to get the bounding box for parts to be CNC’d. I would like the BB to be offset from the part 0.1". Is there a way to create these boxes, without having to offset or scale regular BB’s?
Extra points if I can choose which axes should be offset. E.G. tight to the part in y but offset in x and z.
Thanks,
Nick

Not an offset per se, but here is a script that gets the tight existing bounding box, throws up a dialog on the screen with the current dimensions and allows you to change them in X, Y and Z. Then a new box will be created with the dimensions you input. Note this does not run on Mac, as there is no PropertyListBox method implemented yet. Let me know if it works for you, I recently re-wrote it and localized French/English for my colleagues, hope I caught all the possible bugs.

AdjustableBoundingBox.py (4.9 KB)

–Mitch

@Helvetosaur - I think you can use BoundingBox.Inflate() to do this too, just a thought…

import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs


def test():
    
    id = rs.GetObject()
    geo = sc.doc.Objects.Find(id).Geometry
    bb = geo.GetBoundingBox(True)
    
    bb.Inflate(1)
    sc.doc.Objects.AddBrep(bb.ToBrep())
    sc.doc.Views.Redraw()
    
test()

-Pascal

Thanks! Mitch/Pascal, can you remind me what I need to do with the script when creating a button? Do I add the 3 “import” lines as at the beginning of Pascal’s script? I

When I paste Pascal’s script to a button then use it, it just creates a Windows open dialogue.
Mitch’s gives me an unknown command error.

Hi Nick - Mitch’s script may be much fancier than my test, I don’t really want to butt in, I just wanted to point out a maybe quicker method to get the offset. It also works with three different numbers, not just one.

-Pascal

Open the script in a text editor copy the entire text. In the button editor type

! _NoEcho _-RunPythonScript (
<paste entire script in here>
)

then OK and close the button editor.

In principle it should work after that…

–Mitch

Yeah, the script was already a translation of an older .rvb script, I should look to see if inflate will streamline it a bit. All I do is get the original corner points and move them according to the offsets, then create a new box with those. The script does offer the possibility of keeping the box bottom or top of the new box concurrent with the old one, handy if you’re inflating in +Z only (like the part is fixed to the machine bed).

–Mitch

Hmmm. I have the attached pasted into my button. However when I run it I only get “Command: _NoEcho” in the command line.

AdjustableBoundingBox-Nick.py (4.9 KB)

My typo, I put two underscores in front of _-RunPythonScript in the post above… Take one out and it should work (I hope!)… Sorry!

@nick did you get this to work?

–Mitch

Well that solved one problem and revealed another. Please see attached.
Thanks for your efforts BTW!

Hmm, that doesn’t look too good… Can you try the following?

  • Type EditPythonScript to open the script editor.
  • In the editor, at the upper left hit the “Open file” icon - browse to where the original script (AdjustableBoundingBox.py) is stored and open it.
  • Hit the green arrow to run the script - does it run or do you get the same error?

I’m worried there is something haywire with your Rhino/Python install…

–Mitch

The editor isn’t happy, but I think it is the script.

No, actually, the line
! _NoEcho _-RunPythonScript (
does not belong in the script - as well as the final
)
which I guess is also in there even though it’s not visible in the image. Those are necessary for the script to run when pasted into the toolbar button editor, but not in the script editor.

–Mitch

OK, the script editor likes it now.


But Pascal says I need that initial statement and curved brackets to make it work in Rhino, which gives the previous series of errors.
N