Hi All,
I am working on a script for a college and seem to be stuck at a point. I am performing a set of operations on a permutation of lines and need to collect the resulting objects (curvebooleancombined) into a list for further operations. All my operations are buried in a class, and I can’t seem to figure out why it is not appending to the list. To collect all the resulting geometry at the end.
I am pasting the code below. Any help will be appreciated.
#Permutation Script
import rhinoscriptsyntax as rs
import math
#Permutation Function, input n and k and returns PermKeys - a nest listed of genes
def PermutationKey(n,k):
PermKeys = []
if n>4 or k>12:
print "Too LARGE!!!"
return None
for i in rs.frange(0,math.pow(k,n)-1,1):
key = []
for j in range(0,n):
key.append(int((i/(math.pow(k,n-j-1)))%k))
PermKeys.append(key)
return PermKeys
class MyColumns:
#A class that creates permutations of columns from a set of curves
def __init__(self):
self.allprofiles=[]
self.combined=[]
def makeColumn(self, gene, curves):
#assign variables
self.gene = gene
self.curves = curves
self.line1 = self.gene[0]
self.line2 = self.gene[1]
intersect=rs.CurveCurveIntersection(self.curves[self.line1],self.curves[self.line2])
if intersect == None:
return
else:
self.Offset()
if self.allprofiles != []:
return self.allprofiles
def Offset(self):
intersect=rs.CurveCurveIntersection(self.curves[self.line1],self.curves[self.line2])
if intersect[0][0]==2:
return
else:
#print len(self.allprofiles)
t= intersect[0][6]
#print t
offset1=rs.OffsetCurve(self.curves[self.line1],(0,0,0),1, style=1)
offset2=rs.OffsetCurve(self.curves[self.line1],(0,0,0),-1, style=1)
offset3=rs.OffsetCurve(self.curves[self.line1],(0,0,0),4, style=1)
offset4=rs.OffsetCurve(self.curves[self.line1],(0,0,0),-4, style=1)
offsetpt1=rs.EvaluateCurve(offset3,t)
pts1=rs.AddPoint(offsetpt1)
offsetpt2=rs.EvaluateCurve(offset4,t)
pts2=rs.AddPoint(offsetpt2)
edgept1=rs.CurveStartPoint(offset1)
edgept2=rs.CurveEndPoint(offset1)
edgept3=rs.CurveStartPoint(offset2)
edgept4=rs.CurveEndPoint(offset2)
loop1=rs.AddPolyline((edgept1,offsetpt1,edgept2,edgept4,offsetpt2,edgept3,edgept1))
rs.DeleteObjects((offset1,offset2,offset3,offset4))
t2= intersect[0][7]
offset1=rs.OffsetCurve(self.curves[self.line2],(0,0,0),1.5, style=1)
offset2=rs.OffsetCurve(self.curves[self.line2],(0,0,0),-1.5, style=1)
offset3=rs.OffsetCurve(self.curves[self.line2],(0,0,0),3, style=1)
offset4=rs.OffsetCurve(self.curves[self.line2],(0,0,0),-3, style=1)
offsetpt1=rs.EvaluateCurve(offset3,t2)
pts1=rs.AddPoint(offsetpt1)
offsetpt2=rs.EvaluateCurve(offset4,t2)
pts2=rs.AddPoint(offsetpt2)
edgept1=rs.CurveStartPoint(offset1)
edgept2=rs.CurveEndPoint(offset1)
edgept3=rs.CurveStartPoint(offset2)
edgept4=rs.CurveEndPoint(offset2)
loop2=rs.AddPolyline((edgept1,offsetpt1,edgept2,edgept4,offsetpt2,edgept3,edgept1))
rs.DeleteObjects((offset1,offset2,offset3,offset4))
diff=rs.CurveBooleanIntersection(loop1,loop2)
self.combined=rs.CurveBooleanUnion((loop1,loop2))
return self.combined
self.allprofiles.append(combined)#All these need to be collected into a list
rs.DeleteObjects((loop1,loop2))
def MasterBooleen(self):
self.allprofiles.append(self.combined)
print len(self.allprofiles)
def main():
#collect profiles from user
profiles = rs.GetObjects('Select Profile Curves for Input',rs.filter.curve)
#print profiles
#call PermutationKey function - arrange sets of 2 from number of input profiles
PermKeys = PermutationKey(2,len(profiles))
#loop to create all permutations
for i in range(0,len(PermKeys)):
#collect individual gene (list of two values) from PermKeys (list of al values)
gene = PermKeys[i]
#call instance of class, inputting origin point
columns = MyColumns()
#call .makeColumn method, providing gene, profiles and height
columns.makeColumn(gene, profiles)
columns.MasterBooleen()
#print allprofiles.columns.MyColumns()
#print columns.allprofiles
main()