range(), list, for

1. range()

a=range(10)
print a
print type(a)
a=range(2,10)
print a
a=range(2,10,2)
print a

1.png

2. list

a=list()
a.append(0)
a.append(1)
a.append(2)
a.append(3)
a.append(4)
a.append(5)
a.append(6)
a.append(7)
a.append(8)
a.append(9)
print a
print type(a)

2.png

3. manipulating lsit

a=range(10)
print type(a)
print a[3]  #the third item
print a[5]  #the figth item
a.remove(3) # remove 3 from the list. Note that 3 is not an index but item itself
print a
a.pop(a.index(4)) #pop removes an item with a specific index
print a
a.insert(4,2)  #a[4] will be 2
print a
print len(a)  #total count of the list

3.png

4. "for i in list" syntax

Python is indent sensitive!
you must not miss colon and indent!

import rhinoscriptsyntax as rs
a=list()
for i in range(10):
    a.append(rs.AddPoint(i,0,0))

The first item of the list is substituted to "i" first and "rs.AddPoint(i,0,0)" is performed.
The second item of the list is substituted to "i" second and "rs.AddPoint(i,0,0)" is performed.
The third item of the list is substituted to "i" third and "rs.AddPoint(i,0,0)" is performed.
.
.
.4.png

5. nested for

import rhinoscriptsyntax as rs
a=list()
for i in range(10):
    for j in range(10):
        a.append(rs.AddPoint(i,j,0))

5.png
import rhinoscriptsyntax as rs
a=list()
for i in range(10):
    for j in range(10):
        for k in range(10):
            a.append(rs.AddPoint(i,j,k))
6.png

7. Arithmetic operators in point objects

7.png
Subtraction of two points returns a vector type object.
Addition of a vector with a point object returns a point object.
import rhinoscriptsyntax as rs
a=list()
N=10
Start=rs.PointCoordinates(x)
End=rs.PointCoordinates(y)
vec=(End-Start)/(N-1)
for i in range(N):
    a.append(rs.AddCircle(Start+vec*i,1))

8.png

8. a list type object can contain different types

import rhinoscriptsyntax as rs
a=list()
a.append(rs.AddPoint(0,0,0))
a.append(rs.AddLine([1,0,0],[0,1,0]))
a.append(rs.AddCircle([2,0,0],1))

9.png

9. Polyline

[a,b,c…] represents a list type object.
To create a polyline, a list of vertices is needed.

import rhinoscriptsyntax as rs
vertices=list()
vertices.append([0,2,1])
vertices.append([1,2,1])
vertices.append([1,2,0])
vertices.append([0,2,0])
a=rs.AddPolyline(vertices)

10.png

10. Drawing a circle by polyline

input: N(integer)
Connect a slider with N.
Set the type of the slider as an integer.

11.png
import rhinoscriptsyntax as rs
import math
vertices=list()
for i in rs.frange(0,math.pi*2,math.pi*2/N):
    vertices.append(rs.AddPoint(math.cos(i),math.sin(i),0))
a=rs.AddPolyline(vertices)

12.png

11. Quick introduction to surfaces and curves

input S,u,v
Connect a surface to S
Connect a float point number slider to u and v.

import rhinoscriptsyntax as rs
domainU=rs.SurfaceDomain(S,0)
domainV=rs.SurfaceDomain(S,1)
print domainU
print domainV
a=rs.EvaluateSurface(S,u,v)

Reflect the domainU and domainV to the min/max of the sliders.
13.png
14.png