test rhino3dm

1 Docs

2 Install rhino3dm:

> pip install rhino3dm

> pip show rhino3dm

Name: rhino3dm
Version: 8.6.0
Summary: Python library based on OpenNURBS with a RhinoCommon
 style
Home-page: 
Author: Robert McNeel & Associates
Author-email: steve@mcneel.com
License: 
Location: C:\Users\USERNAME\.conda\envs\ai\Lib\site-packages
Requires: 
Required-by: compute-rhino3d

3 Example 1

from rhino3dm import *
import requests  # pip install requests

req = requests.get("https://files.mcneel.com/TEST/Rhino Logo.3dm")

model = File3dm.FromByteArray(req.content)

for i in range(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')

File3dm.FromByteArray

Read a 3dm file from a byte array

  • Returns: New File3dm on success, None on error.

  • Return type: File3dm

File3dm.Objects

File3dmObjectTable: Gets access to the class associated with this file, which contains all objects.

File3dmObject.Geometry

rhino3dm.GeometryBase: Gets the geometry that is linked with this document object.

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

class 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.

4 Example 2

from rhino3dm import *

center = Point3d(1, 2, 3)
arc = Arc(center, 10, 1)
nc = arc.ToNurbsCurve()
start = nc.PointAtStart
print('start point', type(start))

5 Example 3

import rhino3dm
import random

model = rhino3dm.File3dm()

for i in range(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)
True

6 Example 4

# Sample read render meshes from 3dm file

import rhino3dm

model = rhino3dm.File3dm.Read('./data/myBox.3dm')
print(model)

brep = model.Objects[0].Geometry
print(brep)

face = brep.Faces[0]
print(face)

mesh = face.GetMesh(rhino3dm.MeshType.Any)
print(mesh)
# print (len(mesh.Faces))

7 Example 5

# 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 rhino3dm
import random
import math
import os

# Initial parameters
theta_min = 0.0
theta_max = math.pi
alpha_min = 0.0
alpha_max = math.pi * 2.0
sphere_radius = 100.0
num_lines = 1500

# Create a center point
center_pt = rhino3dm.Point3d(0.0, 0.0, 0.0)

# Create a File3dm object
model = rhino3dm.File3dm()

for i in range(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 save
desktop = 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 disk
model.Write(path, 6)
Back to top