Python center box

Does there exist something like a python center box?
I can easily fix the problem in the image, but I want to be sure that I am not working inefficient.

0100 python centerbox.gh (8.6 KB)

I don’t think so. Might be a good idea to use VectorAdd with b being an input (point).

boxPts = []
boxPts.append(rs.VectorAdd(b, (x/2, y/2, -z/2)))
boxPts.append(rs.VectorAdd(b, (x/2, -y/2, -z/2)))
boxPts.append(rs.VectorAdd(b, (-x/2, -y/2, -z/2)))
boxPts.append(rs.VectorAdd(b, (-x/2, y/2, -z/2)))
boxPts.append(rs.VectorAdd(b, (x/2, y/2, z/2)))
boxPts.append(rs.VectorAdd(b, (x/2, -y/2, z/2)))
boxPts.append(rs.VectorAdd(b, (-x/2, -y/2, z/2)))
boxPts.append(rs.VectorAdd(b, (-x/2, y/2, z/2)))
a = rs.AddBox(boxPts)
1 Like

you could also use rhinocommon

import Rhino.Geometry as rg

box = rg.Box(
    plane,
    rg.Interval(-0.5*x,0.5*x),
    rg.Interval(-0.5*y,0.5*y),
    rg.Interval(-0.5*z,0.5*z))

a = box;
1 Like

Do you know how to make a plane to use that box?
I know having a problem of creating a non-type as a plane.

python box 01.gh (6.1 KB)

option 1.) create a new input parameter with name “planeBox” with type hint “Plane”.
option 2.)

import Rhino.Geometry as rg

planeBox = rg.Plane(
    rg.Point3d (4.0,2.0,1.0),   # Origin
    rg.Vector3d(1.0,0.2,0.0),   # xAxis    
    rg.Vector3d(0.2,1.0,0.0))   # yAxis    

(Other overloads are possible)
1 Like

Maybe just some additional notes:

I’m primarily coding in C#, so I’m more used to Rhinocommon instead of Rhinoscriptsyntax.
Rss is a wrapper library around Rhinocommon, to allow calling its functionality in a more “pythonic” way. However: Rss does not cover every Rhinocommon functionality. If you know how to work with Rhinocommon, you definitely have a richer toolset.
Rhino.Geometry is part of Rhinocommon. Most Grasshopper components are simple Rhinocommon calls. So if you look out for GH functionality, there is a high chance of a Rhinocommon equivalent.

here is the online sdk for Rhinocommon:

https://developer.rhino3d.com/api/RhinoCommon/html/N_Rhino.htm

and here the entry for the Plane Structure:
https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_Plane.htm

2 Likes