I am facing an error in using the PointCount in python
its giving an error of PointCount is not defined. Any suggestions?
import Rhino
import Rhino.Geometry as rg
from random import *
import System.Drawing
import rhinoscriptsyntax as rs
#step 1 moving vertices
def moveVertices(polyline):
ptNum = PointCount
pts = []
planePts = []
for i in range(ptNum):
pts.append(polyline.Point(i))
if len(pts) <= 3:
planePts.append(pts[i])
plane = rg.Plane(planePts[0], planePts[1], planePts[2])
for i in range(ptNum):
scalar = uniform(0.0, 2.0)
vec = plane.ZAxis * scalar
pts[i] = pts[i] + vec
pts[-1] = pts[0]
return pts, plane
a = moveVertices(cells[5])[0]
[pythontest.gh|attachment](upload://zW2NnEzGTCYgCswP7M2zeJAqEhc.gh) (12.2 KB)
pythontest.gh (12.2 KB)
I found this syntax in the rhino API for c# and vp but it doesn’t contain how to use it in python
eirannejad
(Ehsan Iran-Nejad)
2
What is this line intending to do?
to count the voronoi polygon point counts
I am trying to move the voronoi points up in the z axis
this script should move the points of one voronoi polygon up via
a = moveVertices(cells[5])[0]
here is my updated script but still no luck, it is thowing the error of PointCount:
import Rhino
import Rhino.Geometry as rg
from random import *
import System.Drawing
import rhinoscriptsyntax as rs
seed(1000)
#step 1 moving vertices
def moveVertices(polyline):
ptNum = PointCount
pts = []
planePts = []
for i in range(ptNum):
pts.append(polyline.Point(i))
if len(pts) <= 3:
planePts.append(pts[i])
plane = rg.Plane(planePts[0], planePts[1], planePts[2])
for i in range(ptNum):
scalar = uniform(0.0, 2.0)
vec = plane.ZAxis * scalar
pts[i] = pts[i] + vec
pts[-1] = pts[0]
return pts, plane
#Step 2: cell type A
def divPolygon(vertices, plane):
midIdx = len(vertices) //2
startPt = vertices[0]
endPt = vertices [midIdx]
centroid = getCentroid(vertices)
return centroid
xOff = plane.XAxis * uniform(0.0, 2.0)
yOff = plane.YAxis * uniform(0.0, 2.0)
zOff = plane.ZAxis * uniform(0.5, 2.0)
centroid[0] += centroid[0] * xOff[0] + yOff[0] + zOff[0]
centroid[1] += centroid[0] * yOff+ yOff[1] + zOff[1]
centroid[2] = centroid[2] * zOff+ yOff[2] + zOff[2]
curve = rg.Curve.CreateInterpolatedCurve([startPt, centroid, endPt], 3)
curve = japCurve(curve, plane, 24)
curve = rg.PolylneCurve(curve)
halfA = rg.PolylineCurve(vertices[:midIdx+1])
halfB = rg.PolylineCurve(vertices[vertices:1])
halfB.Reverse()
return curve, halfA, halfB
#Helper functions
def getCentroid(vertices):
centroid = [0,0,0]
for i in range(len(vertices)-1):
centroid[0] += vertices[i][0]
centroid[1] += vertices[i][1]
centroid[2] += vertices[i][2]
centroid = [val / (len(vertices) - 1) for val in centroid]
return rg.Point3d(centroid[0], centroid[1], centroid[2])
#JagCurve
def JagCurve(curve, plane, divisions):
totallen = curve.GetLength()
lenStep = totallen / divisions
ts = curve.DivideByLength(lenStep, True)
ts = [t for t in ts]
offDist = uniform(0.1, 0.3)
pts = []
for i in range(len(ts)):
t = ts[i]
newPt = curve.PointAt(t)
if i % 2 != 0 and i != (len(ts) -1):
vec = curve.CurvatureAt(t)
vec.unitize()
vec = -plane.ZAxis + vec
vec = vec * offDist
newPt = newPt + vec
pts.append(newPt)
return pts
testPolygon=moveVertices(cells[5])
a = divPolygon(testPolygon[0], testPolygon[1])
b = testPolygon[0]