How to use the rhino3dm.File3dm function in rhino3dm

To help you get started, we’ve selected a few rhino3dm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jesterKing / import_3dm / import_3dm.py View on Github external
def read_3dm(context, filepath, import_hidden):
    top_collection_name = os.path.splitext(os.path.basename(filepath))[0]
    if top_collection_name in context.blend_data.collections.keys():
        toplayer = context.blend_data.collections[top_collection_name]
    else:
        toplayer = context.blend_data.collections.new(name=top_collection_name)

    model = r3d.File3dm.Read(filepath)
    
    layerids = {}
    materials = {}
    
    handle_materials(context, model, materials)
    handle_layers(context, model, toplayer, layerids, materials)
        
    for ob in model.Objects:
        og=ob.Geometry
        if og.ObjectType not in [r3d.ObjectType.Brep, r3d.ObjectType.Mesh, r3d.ObjectType.Extrusion]: continue
        attr = ob.Attributes
        if not attr.Visible: continue
        if attr.Name == "" or attr.Name==None:
            n = str(og.ObjectType).split(".")[1]+" " + str(attr.Id)
        else:
            n = attr.Name
github jesterKing / import_3dm / import_3dm / read3dm.py View on Github external
def read_3dm(context, options):

    filepath = options.get("filepath", "")
    model = None

    try:
        model = r3d.File3dm.Read(filepath)
    except:
        print("Failed to import .3dm model: {}".format(filepath))
        return {'CANCELLED'}

    top_collection_name = os.path.splitext(os.path.basename(filepath))[0]
    if top_collection_name in context.blend_data.collections.keys():
        toplayer = context.blend_data.collections[top_collection_name]
    else:
        toplayer = context.blend_data.collections.new(name=top_collection_name)

    # Get proper scale for conversion
    scale = r3d.UnitSystem.UnitScale(model.Settings.ModelUnitSystem, r3d.UnitSystem.Meters) / context.scene.unit_settings.scale_length

    layerids = {}
    materials = {}
github mcneel / rhino3dm / docs / python / samples / getmeshes.py View on Github external
# Sample read render meshes from 3dm file
import rhino3dm
model = rhino3dm.File3dm.Read('mymodel.3dm')
brep = model.Objects[0].Geometry
face = brep.Faces[0]
mesh = face.GetMesh(rhino3dm.MeshType.Any)
print (len(mesh.Faces))
github mcneel / rhino3dm / docs / python / samples / spherelines.py View on Github external
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