Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5749

Excel handling help in Rhino python

$
0
0

@Sachin_Saxena1 wrote:

Hi!
I was working on NURBS modeling using rhino python in which I had to draw several models whith several different sets of control point weights.Now,I have a matrix with 18 different sets of weight values.I use the below mentioned code for the same.Although I am getting 18 different files ,but the problem each of the file saved has all the curves from the previous saved files too,apart from the curve which is actually to be saved in that file.In short ,the save feature I am using keeps accumulating the curves to the later saved files.For example,the 10th saved file has all the 9 curves corresponding to the previous 9 weight points ,Can somebody help me with this.Thanks.

import Rhino
import scriptcontext
import os
import rhinoscriptsyntax as rs
import sys
import xlrd

k=0
Matrix = [[0 for x in range(18)] for x in range(18)]
Matrix=([[3.97,2.59,3.34],[1.34,4.16,3.09],[4.03,4.47,0.59],[0.84,3.28,2.47],[0.34,2.03,2.66],[2.22,1.84,4.66],[1.78,3.91,4.16],[4.78,1.03,4.47],[4.91,0.41,3.03],[1.72,1.47,2.03],[0.41,2.72,4.72],[3.16,4.53,2.34],[4.41,3.66,1.22],[4.47,1.28,2.09],[0.22,1.34,3.66],[2.34,4.66,2.91],[3.09,4.91,3.53],[3.28,2.97,4.78]])

def SaveAsRhinoFile(name="Default.3dm"):

filename = name
folder = "D:/Sachin/"
path = os.path.abspath(folder + filename)
cmd = "_-SaveAs " + chr(34) + path + chr(34)
rs.Command(cmd, True)

l=1
def TestNurbsCurve(l=1):
degree = 7
cv_count = 8
knot_count = cv_count + degree - 1
order = degree + 1
cvs = []
cvs.append(Rhino.Geometry.Point3d(0.0, 0.0, 0.0))
cvs.append(Rhino.Geometry.Point3d(458.0, 0.0, 0.0))
cvs.append(Rhino.Geometry.Point3d(458.0, 229.0, 0.0))
cvs.append(Rhino.Geometry.Point3d(458.0, 458.0, 0.0))
cvs.append(Rhino.Geometry.Point3d(0.0, 458.0, 0.0))
cvs.append(Rhino.Geometry.Point3d(0.0, 686.0, 0.0))
cvs.append(Rhino.Geometry.Point3d(0.0, 915.0, 0.0))
cvs.append(Rhino.Geometry.Point3d(458.0, 915.0, 0.0))
knots = []
knots.append(0)
knots.append(0)
knots.append(0)
knots.append(0)
knots.append(0)
knots.append(0)
knots.append(0)
knots.append(1)
knots.append(1)
knots.append(1)
knots.append(1)
knots.append(1)
knots.append(1)
knots.append(1)
curve = Rhino.Geometry.NurbsCurve(degree,False, order, cv_count)
for i in xrange(cv_count):
print "sach"+str(i)
cp = Rhino.Geometry.ControlPoint()
cp.Location = cvs[i]
if(i==0):
cp.Weight=1
if(i==7):
cp.Weight=1
if(i==1):
cp.Weight = Matrix[l-2][0]
if(i==6):
cp.Weight = Matrix[l-2][0]
if(i==2):
cp.Weight = Matrix[l-2][1]
if(i==5):
cp.Weight = Matrix[l-2][1]
if(i==3):
cp.Weight = Matrix[l-2][2]
if(i==4):
cp.Weight = Matrix[l-2][2]
curve.Points[i] = cp
for i in xrange(knot_count):
curve.Knots[i] = knots[i]
if curve.IsValid:
print "yeah"
scriptcontext.doc.Objects.AddCurve(curve)
scriptcontext.doc.Views.Redraw()
SaveAsRhinoFile(""+str(l))
del
l=2
while(l<20):
TestNurbsCurve(l)
l+=1

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 5749

Trending Articles