A small little test - Create some basic geometry and save it using Python


In case that anyone could find this useful, just find below a little script to create an example model using the library and plain python. I hope that this helps a little.

# a.linares
# Creates a 3dm file containing a group of randomly distributed lines defining an sphere.

from rhino3dm import *
import random as rd
import math as m
import os

# Initial paramenters
thetaMin = 0
thetaMax = m.pi
alphaMin = 0
alphaMax = m.pi*2
sphereRad = 100

numLines = 1500
centerPt = Point3d(0,0,0)

ModelFilePath = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop') 
FileName = "SphereTest.3dm"

FilePath = os.path.join(ModelFilePath,FileName)

ModelFile = File3dm()
ModelObjectTable = ModelFile.Objects

for i in range(numLines):
	theta = rd.uniform(thetaMin, thetaMax)
	alpha = rd.uniform(alphaMin, alphaMax)

	pt0 = centerPt
	pt1X = sphereRad*m.sin(theta)*m.cos(alpha)
	pt1Y = sphereRad*m.sin(theta)*m.sin(alpha)
	pt1Z = sphereRad*m.cos(theta)

	pt1 = Point3d(pt1X,pt1Y,pt1Z)

	cLine = LineCurve(pt0,pt1)



Examples of passing data to Rhino
(Steve Baer) #2

Pretty cool huh?:slight_smile: Thanks for the sample, I’m excited to keep improving on this library


yep!..it remembers me the capabilities of processing (but with proper NURBS geometry). Love how easy and direct is to generate geometry and save it in 3dm.

I have a couple of ideas in mind to use it a little bit more extensively for stand-alone tools and to get my hands on C#.

Thanks a lot for the effort and the openness of the whole rhino3dm, rhinocompute and rhinoInside frameworks.