from random import random import functions f =functions.Functions() ####### widthValue=3*cm #spessore delle sezioni ####### topH_range=[20.0*cm,100.0*cm] #range per altezza concavità superiore bottomH_range=[20.0*cm,100.0*cm] #range per altezza concavità inferiore radius_range=[20.0*cm,100*cm] #range per raggio circonferenze terminali ####### nPanels=1 #numero di suddivisioni della parete wallLenght=100*cm #altezza dei larghezza della parete pannelHeight=100*cm #altezza dei pannelli percentage=1 #percentuale di bucatura fullShim=True #abilità l'unicità degli spessori per ampie bucature beamHeight=0*cm #altezza della trave per l'offset dei cavi ################ # la funzione inizializzante il programma. # seleziona le famiglie utili e le pone in un array che passe alla funzione createPanels ################ 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() ################ # gestisce la suddivisione dei pannelli. # suddivide la parete in larghezze random che non alteranno la lunghezza successiva ################ def createPanels(component): moduleLenght=wallLenght/nPanels position=0 randomOffset=(0.5-random())*moduleLenght/2 randomOffsetPrevious=0 num=int(round(pannelHeight/(widthValue*4),0))*4 # numero totale delle suddivisione verticali slats=int(round(num*percentage)) # numero di sezioni in relazione alla percentuale di bucatura 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) # array per la posizione delle sezioni 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) # array per la posizione degli spessori for j in slatsTotal: elimina=shimsArray.index(j) del shimsArray[elimina] createPanel(component,position,moduleRandomLenght,num,slatsArray,shimsArray,i) # crea i pannelli createRod(component[5],position) # crea i tondini slatsArrayPrevious=slatsArray position+=moduleRandomLenght createRod(component[5],position) # crea il tondino finale ##################################################### 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) # stabilisce la fase casuale per funzioni goniometriche offset=round((random()+0.5)*math.pi,2) # stabilisce l'offset casuale per funzioni goniometriche 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) # crea le componenti l/num,m/num,n/num sono gli stati d'avanzamento delle componenti lungo la verticale elif not fullShim: createShim(component[4],loc) # crea gli spessori frazionati 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) # crea gli spessori unici else: createFullShim(component[4],0,shimsArray,loc) # crea gli spessori unici l+=1 m+=1 # indici per incrementare lo stato d'avanzamento 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) ################################## def createComponenent(component,c2cValue,indexTop,indexBottom,indexR,loc,phase,offset): tollerance=0 funzione = int(round(random()*0,0)) topH_value = f.ParabolicNegative(topH_range[0],topH_range[1],indexTop) # consultare la libreria functions.py bottomH_value = f.ParabolicPositive(bottomH_range[0],bottomH_range[1],indexBottom) # per impostare funzioni corrette radius_value = f.ParabolicNegative(radius_range[0],radius_range[1],indexR) # altrimenti cambiarle indipendentemente da essa ma senza garanzie certe di risultato 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) # richiami i parametri.... 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') # ... e li setta 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()