Grasshopper

algorithmic modeling for Rhino

hello, there,

I was learning other people's python script, I found getBoundingBox was used after rhinoscripsyntax imported. But in he help file, I can't find an item named getBoundingbox. Why is that? And where can i learn more about those build-in function not listed in the help file??

Thanks a lot!!

Views: 987

Replies to This Discussion

Hi Aroving

You need to query rhinocommonSDK,If you speak Chinese, you can go to http://bbs.shaper3d.com/ to ask questions

Also, get acquainted with the dir(), help() and type() Python functions. They're really useful for inspecting RhinoCommon objects (well, for inspecting everything really :)

Thanks very much!!!

Aroving,

There are two ways to access the methods available to you in python. RhinoCommon is a library of methods that are very powerful but can be quite technical and more difficult for a first time user to understand. RhinoScript is a generally more straightforward and easy to use. You can think of it as a translation of RhinoCommon so that you don't have to write all the technical stuff.

In your first line you've said "import rhinoscriptsyntax as rs". To see the methods you can call from this library you can go to the help menu and choose 'Help for Rhinoscript'. It will show you a searchable window of all the the options you have. This is much easier for new users to learn than looking at the RhinoCommon SDK.

If you search the help file for 'BoundingBox' you'll get the screen capture below:

At the bottom you can see an example of how to use it. In your case you would replace the following lines:

2/ boxA=brepA.GetBoundingBox((0,0,0,)) --> boxA = rs.BoundingBox(brepA)

3/ boxB=brepB.GetBoundingBox((0,0,0,)) --> boxB = rs.BoundingBox(brepB)

The script you have written uses elements of both RhinoScript and RhinoCommonSDK. I would suggest you might start just using RhinoScript. See below, I have re-written the first 8 lines of your script using just RhinoScript:

import rhinoscriptsyntax as rs

#Get BoundingBox from breps.
BoundingBoxA = rs.BoundingBox(brepA) #Returns list of eight corner points.
BoundingBoxB = rs.BoundingBox(brepB)

#Get centre point of RhinoScript BoundingBox (which is a list of eight points).
boxA = rs.AddBox(BoundingBoxA) #Generate box from corner points
ptA = rs.SurfaceVolumeCentroid(boxA) #Get Volumetric Centroid of box
boxB = rs.AddBox(BoundingBoxB)
ptB = rs.SurfaceVolumeCentroid(boxB)

For reference the following will achieve the same thing using RhinoCommon, fewer lines, but more technical. There are a few other quirks as well, for example you have to explictly tell the python component what kind of object 'brepA' is. See below for example of same script in RhinoCommon:

import Rhino as rh

centerPtA = brepA.GetBoundingBox(rh.Geometry.Plane.WorldXY).Center
centerPtB = brepB.GetBoundingBox(rh.Geometry.Plane.WorldXY).Center

I'm not sure what you are trying to achieve overall and your loop doesn't make a lot of sense to me but I hope that clarifies some of the differences between the two libraries you can use.

Regards,

M

Thank you for you patient and reply, Thanks

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service