The simple Python script below shows how different equations can create different shapes.

Sample code 01:

As a start in scripting, it is necessary to import the libraries that can facilitate the programming process. In the code below Rhino Syntax library needs to be imported, which contains the rhino 3d related commands for modelling and design purposes, it is also important to import Math Library and Random library for all the random and math related calculations.

` import rhinoscriptsyntax as rs`

import random as rnd

import math as m

Here GETOBJECT command is used in order to import some predefined objects or models from Rhinoceros viewports;

`baseshape = rs.GetObject ("get object" ,4)`

centroid = rs.CurveAreaCentroid(baseshape)

centerPt = centroid[0]

list = []

Starting a loop is needed to go in Z direction while scaling and modifying the imported object from the previous step;

`for i in range (0,20):`

vectormov = [0,0,5*i]

newshape = rs.RotateObject(baseshape, centerPt, 10*i, axis = None,copy = True)

rs.ScaleObject(newshape,centerPt,

[m.sin(m.pi/10*i)+.2,m.sin(m.pi/10*i)+.2,m.sin(m.pi/10*i)+.2])

rs.MoveObject(newshape,vectormov)

list.append(newshape)

Finally, ADDLOFT command is used to convert the cross section stored in the cross section list to a surface.

`rs.AddLoftSrf(list)`

Sample code 02:

`import rhinoscriptsyntax as rs`

import random as rnd

import math as m

R = rnd.random()

strP = rs.GetObject("select plan outline", 4)

Acrvl = []

for i in range (0,100,10):

x = m.sin(i)

y = m.sin(i)

z = i

ccrv = rs.CopyObject(strP, [x,y,z])

crv = rs.RotateObject(ccrv, [x,y,z], R*i) ##i*5)

scaleval = m.cos(i/75)

rs.ScaleObject(crv,[x,y,z], [scaleval,scaleval,scaleval])

Acrvl.append(crv)

print Acrvl

Srf = rs.AddLoftSrf(Acrvl)

# rs.curveareacentroid(baseshape)

# you have to call the first item of ots result as centerPT = centroid =[0]

Comments are closed.