from random import random import functions f =functions.Functions() ####### widthValue=2*cm ####### topH_range=[2.0*cm,15.0*cm] bottomH_range=[2.0*cm,15.0*cm] radius_range=[2.0*cm,10.0*cm] ####### nPanels=5 wallLenght=400*cm pannelHeight=200*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; #print symbName[i] createPanels(component) t.Commit() ##################################################### def createPanels(component): moduleLenght=wallLenght/nPanels position=0 randomOffset=(0.5-random())*moduleLenght/2 randomOffsetPrevious=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 createPanel(component,position,moduleRandomLenght,widthValue*(i%2)) position+=moduleRandomLenght ##################################################### def createPanel(component,x,c2cValue,offset): l=0.0 m=0.0 n=0.0 num=int(round(pannelHeight/(widthValue*4),0)) tollerance=0.5 for i in range(0,num): loc = XYZ(x,0,(i*widthValue*2)+offset) topH_value = f.Sin(topH_range[0],topH_range[1],l/num,3) bottomH_value = f.Cos(topH_range[0],topH_range[1],m/num,2) radius_value = f.Sin(topH_range[0],topH_range[1],n/num,1) if topH_value>=radius_value+tollerance and bottomH_value>=radius_value+tollerance : family=3 elif bottomH_value>=radius_value+tollerance : family=2 elif topH_value>=radius_value+tollerance : family=1 else: family=0 familyInst = doc.FamilyCreate.NewFamilyInstance(loc, component[family], Structure.StructuralType.NonStructural) #modify FamilyInstance parameter using i and j values interasse = familyInst.get_Parameter('interasse') topH = familyInst.get_Parameter('top_conca_h') bottomH = familyInst.get_Parameter('bottom_conca_h') radius = familyInst.get_Parameter('r') modifica=int(round(random()*2,0)) #print modifica topH.Set(topH_value) bottomH.Set(bottomH_value) radius.Set(radius_value) interasse.Set(c2cValue) l+=1 m+=1 n+=1 ''' if modifica==0: l+=0.5 elif modifica==1: m+=0.5 elif modifica==2: n+=0.5 ''' if __name__=="__main__": main()