> pip install rhino3dm> pip show rhino3dmName: rhino3dmVersion: 8.6.0Summary: Python library based on OpenNURBS with a RhinoCommon styleHome-page: Author: Robert McNeel & AssociatesAuthor-email: steve@mcneel.comLicense: Location: C:\Users\USERNAME\.conda\envs\ai\Lib\site-packagesRequires: Required-by: compute-rhino3d
3 Example 1
from rhino3dm import*import requests # pip install requestsreq = requests.get("https://files.mcneel.com/TEST/Rhino Logo.3dm")model = File3dm.FromByteArray(req.content)for i inrange(len(model.Objects)): obj = model.Objects[i] geometry = obj.Geometry bbox = geometry.GetBoundingBox()print("model object ", i, ':', obj)print("bbbox min & max: {}, {}".format(bbox.Min, bbox.Max), '\n')
Bounding box solver. Gets the world axis aligned bounding box for the geometry.
Parameters:
accurate (bool) – If true, a physically accurate bounding box will be computed. If not, a bounding box estimate will be computed. For some geometry types there is no difference between the estimate and the accurate bounding box. Estimated bounding boxes can be computed much (much) faster than accurate (or “tight”) bounding boxes. Estimated bounding boxes are always similar to or larger than accurate bounding boxes.
Returns:
The bounding box of the geometry in world coordinates or BoundingBox.Empty if not bounding box could be found.
# spherelines.py# Sample script that demonstrates how to use Rhino3dm.py# https://github.com/mcneel/rhino3dm# This sample creates a 3dm file containing a group of randomly# distributed lines defining an sphere.import rhino3dmimport randomimport mathimport os# Initial parameterstheta_min =0.0theta_max = math.pialpha_min =0.0alpha_max = math.pi *2.0sphere_radius =100.0num_lines =1500# Create a center pointcenter_pt = rhino3dm.Point3d(0.0, 0.0, 0.0)# Create a File3dm objectmodel = rhino3dm.File3dm()for i inrange(num_lines):# Calculate random line end point random.seed(i *100) theta = random.uniform(theta_min, theta_max) alpha = random.uniform(alpha_min, alpha_max) x = sphere_radius * math.sin(theta) * math.cos(alpha) y = sphere_radius * math.sin(theta) * math.sin(alpha) z = sphere_radius * math.cos(theta) end_pt = rhino3dm.Point3d(x, y, z)# Create line curve line_curve = rhino3dm.LineCurve(center_pt, end_pt)# Add to model model.Objects.AddCurve(line_curve)# Full path to 3dm file to savedesktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop') filename ='spherelines.3dm'# path = os.path.join(desktop, filename)path ='./spherelines.3dm'# Write model to diskmodel.Write(path, 6)
---title: "test rhino3dm"---# Docs- [rhino3dm github](https://github.com/mcneel/rhino3dm)- [rhino3dm doc](https://mcneel.github.io/rhino3dm/python/api/index.html)- [developer examples](https://github.com/mcneel/rhino-developer-samples/tree/7/rhino3dm) - [rhino3dm.py](https://github.com/mcneel/rhino-developer-samples/tree/7/rhino3dm/py) - [rhino3dm.js](https://github.com/mcneel/rhino-developer-samples/tree/7/rhino3dm/js)# Install rhino3dm:```shell > pip install rhino3dm> pip show rhino3dmName: rhino3dmVersion: 8.6.0Summary: Python library based on OpenNURBS with a RhinoCommonstyleHome-page:Author: Robert McNeel &AssociatesAuthor-email: steve@mcneel.comLicense:Location: C:\Users\USERNAME\.conda\envs\ai\Lib\site-packagesRequires:Required-by: compute-rhino3d```# Example 1```pythonfrom rhino3dm import*import requests # pip install requestsreq = requests.get("https://files.mcneel.com/TEST/Rhino Logo.3dm")model = File3dm.FromByteArray(req.content)for i inrange(len(model.Objects)): obj = model.Objects[i] geometry = obj.Geometry bbox = geometry.GetBoundingBox()print("model object ", i, ':', obj)print("bbbox min & max: {}, {}".format(bbox.Min, bbox.Max), '\n')```::: {.column-margin}::: {.callout-tip title="File3dm.FromByteArray -> File3dm" collapse="true"}[File3dm.FromByteArray](https://mcneel.github.io/rhino3dm/python/api/File3dm.html#rhino3dm.File3dm.FromByteArray)Read a 3dm file from a byte array- Returns: New File3dm on success, None on error.- Return type: File3dm::::::::: {.column-margin}::: {.callout-tip title="File3dm.Objects --> File3dmObjectTable" collapse="true"}[File3dm.Objects](https://mcneel.github.io/rhino3dm/python/api/File3dm.html#rhino3dm.File3dm.Objects)File3dmObjectTable: Gets access to the class associated with this file, which contains all objects.::::::::: {.column-margin}::: {.callout-tip title="File3dmObject.Geometry -> rhino3dm.GeometryBase" collapse="true"}[File3dmObject.Geometry](https://mcneel.github.io/rhino3dm/python/api/File3dmObject.html#rhino3dm.File3dmObject.Geometry)rhino3dm.GeometryBase: Gets the geometry that is linked with this document object.::::::::: {.column-margin}::: {.callout-tip title="GeometryBase.GetBoundingBox -> rhino3dm.BoundingBox" collapse="true"}[GeometryBase.GetBoundingBox](https://mcneel.github.io/rhino3dm/python/api/GeometryBase.html#rhino3dm.GeometryBase.GetBoundingBox)Bounding box solver. Gets the world axis aligned bounding box for the geometry.Parameters:- accurate (bool) – If true, a physically accurate bounding box will be computed. If not, a bounding box estimate will be computed. For some geometry types there is no difference between the estimate and the accurate bounding box. Estimated bounding boxes can be computed much (much) faster than accurate (or “tight”) bounding boxes. Estimated bounding boxes are always similar to or larger than accurate bounding boxes.Returns:- The bounding box of the geometry in world coordinates or BoundingBox.Empty if not bounding box could be found.Return type:- rhino3dm.BoundingBox::::::::: {.column-margin}::: {.callout-tip title="rhino3dm.BoundingBox" collapse="true"}[class rhino3dm.BoundingBox](https://mcneel.github.io/rhino3dm/python/api/BoundingBox.html#rhino3dm.BoundingBox)> `BoundingBox(minX, minY, minZ, maxX, maxY, maxZ)`> > Constructs a bounding box from numeric extremes.> > Parameters:>> - minX (float) – Lower extreme for box X size.> - minY (float) – Lower extreme for box Y size.> - minZ (float) – Lower extreme for box Z size.> - maxX (float) – Upper extreme for box X size.> - maxY (float) – Upper extreme for box Y size.> - maxZ (float) – Upper extreme for box Z size.::::::# Example 2 ```pythonfrom rhino3dm import*center = Point3d(1, 2, 3)arc = Arc(center, 10, 1)nc = arc.ToNurbsCurve()start = nc.PointAtStartprint('start point', type(start))```# Example 3```{python}import rhino3dmimport randommodel = rhino3dm.File3dm()for i inrange(20): pt = rhino3dm.Point3d(random.uniform(-10,10), random.uniform(-10,10), 0) model.Objects.AddPoint(pt) circle = rhino3dm.Circle(pt, random.uniform(1,4)) model.Objects.AddCircle(circle)model.Write("./circle.3dm", 70)```# Example 4```python# Sample read render meshes from 3dm fileimport rhino3dmmodel = rhino3dm.File3dm.Read('./data/myBox.3dm')print(model)brep = model.Objects[0].Geometryprint(brep)face = brep.Faces[0]print(face)mesh = face.GetMesh(rhino3dm.MeshType.Any)print(mesh)# print (len(mesh.Faces))```# Example 5```python# spherelines.py# Sample script that demonstrates how to use Rhino3dm.py# https://github.com/mcneel/rhino3dm# This sample creates a 3dm file containing a group of randomly# distributed lines defining an sphere.import rhino3dmimport randomimport mathimport os# Initial parameterstheta_min =0.0theta_max = math.pialpha_min =0.0alpha_max = math.pi *2.0sphere_radius =100.0num_lines =1500# Create a center pointcenter_pt = rhino3dm.Point3d(0.0, 0.0, 0.0)# Create a File3dm objectmodel = rhino3dm.File3dm()for i inrange(num_lines):# Calculate random line end point random.seed(i *100) theta = random.uniform(theta_min, theta_max) alpha = random.uniform(alpha_min, alpha_max) x = sphere_radius * math.sin(theta) * math.cos(alpha) y = sphere_radius * math.sin(theta) * math.sin(alpha) z = sphere_radius * math.cos(theta) end_pt = rhino3dm.Point3d(x, y, z)# Create line curve line_curve = rhino3dm.LineCurve(center_pt, end_pt)# Add to model model.Objects.AddCurve(line_curve)# Full path to 3dm file to savedesktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop') filename ='spherelines.3dm'# path = os.path.join(desktop, filename)path ='./spherelines.3dm'# Write model to diskmodel.Write(path, 6)```