from random import random import functions f =functions.Functions() ####### widthValue=2*cm ####### topH_range=[10.0*cm,50.0*cm] bottomH_range=[10.0*cm,50.0*cm] radius_range=[10.0*cm,50*cm] ####### nPanels=1 wallLenght=100*cm pannelHeight=100*cm percentage=1 #[0.0-1.0] fullShim=True beamHeight=0*cm ################ def main(): t = Transaction(doc, 'Crea sezioni.') t.Start() symbName = ['MN-Sezione_TB_h','MN-Sezione_T_h','MN-Sezione_B_h','MN-Sezione_CC_h','MN-Spessore','MN-Tondino'] component=range(symbName.__len__()) collector = FilteredElementCollector(doc) collector.OfClass(FamilySymbol) famtypeitr = collector.GetElementIdIterator() for i in range(0,symbName.__len__()): famtypeitr.Reset() for item in famtypeitr: famtypeID = item famsymb = doc.get_Element(famtypeID) if famsymb.Family.Name == symbName[i]: component[i]=famsymb; createPanels(component) t.Commit() ##################################################### def createPanels(component): moduleLenght=wallLenght/nPanels position=0 randomOffset=(0.5-random())*moduleLenght/2 randomOffsetPrevious=0 num=int(round(pannelHeight/(widthValue*4),0))*4 slats=int(round(num*percentage)) slatsArrayPrevious=range(0) for i in range(0,nPanels): if(i==nPanels-1): moduleRandomLenght=wallLenght-position else: moduleRandomLenght=moduleLenght+randomOffset-randomOffsetPrevious randomOffsetPrevious=randomOffset randomOffset=(0.5-random())*moduleLenght/2 slatsArray=range(i%2, num+i%2, 2) for j in range(0,(num-slats)/2): elimina=int(round(random()*slatsArray.__len__()-1)) del slatsArray[elimina] slatsTotal=slatsArray+slatsArrayPrevious slatsTotal.sort() shimsArray=range(num) for j in slatsTotal: elimina=shimsArray.index(j) del shimsArray[elimina] createPanel(component,position,moduleRandomLenght,num,slatsArray,shimsArray,i) createRod(component[5],position) slatsArrayPrevious=slatsArray position+=moduleRandomLenght createRod(component[5],position) ##################################################### def createRod(famsymb,x): loc = XYZ(x,0,-widthValue) familyInst = doc.FamilyCreate.NewFamilyInstance(loc, famsymb, Structure.StructuralType.NonStructural) height = familyInst.get_Parameter('altezza') height.Set(widthValue+beamHeight+pannelHeight) def createPanel(component,x,c2cValue,num,slatsArray,shimsArray,panelNumber): l=0.0 m=0.0 n=0.0 phase=round(random()*0.5+1) offset=round((random()+0.5)*math.pi,2) if panelNumber==nPanels-1: shimsArrayLast=range(num) for j in slatsArray: elimina=shimsArrayLast.index(j) del shimsArrayLast[elimina] for i in range(0,num): loc = XYZ(x,0,i*widthValue) if i in slatsArray: createComponenent(component,c2cValue,l/num,m/num,n/num,loc,phase,offset) elif not fullShim: createShim(component[4],loc) elif i in shimsArray: base=shimsArray.index(i) if base>0: if not shimsArray[base-1]==shimsArray[base]-1: createFullShim(component[4],base,shimsArray,loc) else: createFullShim(component[4],0,shimsArray,loc) l+=1 m+=1 n+=1 if not i in slatsArray and panelNumber==nPanels-1: loc = XYZ(x+c2cValue,0,i*widthValue) if not fullShim: createShim(component[4],loc) elif i in shimsArrayLast: base=shimsArrayLast.index(i) if base>0: if not shimsArrayLast[base-1]==shimsArrayLast[base]-1: createFullShim(component[4],base,shimsArrayLast,loc) else: createFullShim(component[4],0,shimsArrayLast,loc) ''' print slatsArray print shimsArray print "------" ''' def createComponenent(component,c2cValue,indexTop,indexBottom,indexR,loc,phase,offset): tollerance=0 funzione = int(round(random()*0,0)) topH_value = f.ParabolicPositive(topH_range[0],topH_range[1],indexTop) bottomH_value = f.HalfParabolicPositive(bottomH_range[1],bottomH_range[0],indexBottom) radius_value = f.HalfParabolicPositive(radius_range[0],radius_range[1],indexR) #print topH_range[0]," ",topH_range[1]," ",funzione," ",topH_value if topH_value>=radius_value and bottomH_value>=radius_value : family=3 elif bottomH_value>=radius_value : family=1 elif topH_value>=radius_value : family=2 else: family=0 familyInst = doc.FamilyCreate.NewFamilyInstance(loc, component[family], Structure.StructuralType.NonStructural) interasse = familyInst.get_Parameter('interasse') spessore = familyInst.get_Parameter('spessore') topH = familyInst.get_Parameter('top_conca_h') bottomH = familyInst.get_Parameter('bottom_conca_h') radius = familyInst.get_Parameter('r') topH.Set(topH_value) bottomH.Set(bottomH_value) radius.Set(radius_value) interasse.Set(c2cValue) spessore.Set(widthValue) def createFullShim(famsymb,base,shimsArray,loc): h=1 consecutive=True; while consecutive: if h+base4: value=f.ParabolicNegative(dLimit,uLimit,counter) return value ''' ########################################################## if __name__=="__main__": main()