Grasshopper Python - Get center point

python
unhandled

#1

I am not able to get my center point to the center of the bounding box.

20180914 00 problem get center point.gh (5.1 KB)


#2
avX = mt.fsum([(pnt.X) for pnt in list])/len(list)

#3

You could call the Center property directly on the BoundingBox.


#4

Really?! Can you tell me how in python?

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
import math as mt

list = rs.BoundingBox(x)

#avX = mt.fsum([(pnt.X) for pnt in list])/len(list)
#avY = mt.fsum([(pnt.Y) for pnt in list])/len(list)
#avZ = mt.fsum([(pnt.Z) for pnt in list])/len(list)

center = rs.BoundingBox.Center(rs.AddBox(list))

Is it possible in python?


#5

Indeed:

20180914_problem_get_center_point_AHD_00.gh (6.3 KB)


#6

Thank you, you answered my question.

Do you know how to make from a BB a Brep?


#7

You can call this method on the BB variable:

https://developer.rhino3d.com/5/api/RhinoCommonWin/html/M_Rhino_Geometry_BoundingBox_ToBrep.htm


#8

Thank you, I tried to implement that one, but I do not understand it (this is my first time using Rhinoceros code instead of rhinoscriptsyntax). (I found it earlier on, but did not know how.)

20180915 00 problem bbox to brep.gh (5.9 KB)


#9

There’s a lot of stuff going on there you do not need (the __main__ check, scriptcontext.doc bits etc). If you set your input typehints appropriately, you can simply call properties/methods on RhinoCommon objects directly like so:

20180915_problem_get_center_point_AHD_00.gh (5.8 KB)

I also called the Inflate method on the bounding box here, as a simpler alternative to scaling it (from your other thread on this topic).

I would suggest maybe going through some GHPython basics before going much further: