Hi guys, I’m new in programming. I would like to generate a parametric dome to calculate some kind of stresses and to visualize these stresses on the dome with different colors.
Now I defined a function ( called ‘S()’ ) that generates a dome by some parameters controlled by sliders. but I don’t find a way to execute two others different functions ( ‘T()’ , V() ) to control the color of the surface. These two functions have to be executed by radiobuttons.
Thanks to all for the help!
import maya.cmds as cmds
import numpy as np
#if cmds.window(ram, exists=True): #ogni volta che lancio il programma si cancella la finestra creata in precedenza
#cmds.deleteUI(ram)
angolo= range(10,360,10)
#Definisco una cupola fittizia per poter generare le altre
cmds.circle(nr=(1, 0, 0), c=(0, 0, 0), sw=-90, r=0, n="S1")
cmds.rotate(0,0,0)
cupola1=[]
for i in range (35):
cmds.duplicate()
cmds.rotate(0,angolo[i],0)
cupola1=cupola1+["S"+str(i+1)]
cmds.loft(cupola1, ['S36','S1'])
cmds.delete(cupola1, ['S36','S1'])
cmds.nurbsToPoly('loftedSurface1', name='pippo', mnd=1, ch=1, f=0, pt=0, pc=500, chr=0.9, ft=0.01, mel=0.001, d=0.1, ut=1, un=3, vt=1, vn=3, uch=0, ucr=0, cht=0.2,es=0,ntr=0,mrt=0,uss=1)
cmds.delete('loftedSurface1')
#Definisco la finestra di output
ram = cmds.window('Volte Sottili', t='Volte Sottili', w=300, h=300, sizeable = False) #definisco una finestra con il nome e le dimensioni
cmds.columnLayout(adj=True)
#imagePath = cmds.internalVar(upd = True)+'icons/img1.jpg'
#cmds.image(w=200, h=100, image = imagePath)
cmds.separator(h=20)
cmds.text('Parametri')
cmds.separator(h=20)
#Slider dei Parametri
radius2 = cmds.intSliderGrp(l = 'Radius [m]', min = 0.1, max = 50, field = True, dc='S()')
gamma2 = cmds.intSliderGrp(l = 'Peso specifico [KN/mc]', min = 0, max = 50, field = True, dc='S()')
spess2 = cmds.intSliderGrp(l = 'Spessore [m]', min = 0.1, max = 1, field = True, dc='S()')
sweep2 = cmds.intSliderGrp(l = 'Angolo [gradi]', min = 10, max = 90, value=90, field = True, dc='S()')
cmds.separator(h=20)
cmds.text('Solution Plot2')
cmds.separator(h=20)
cmds.showWindow(ram)
def S():
cmds.delete('pippo')
#Parametri della superficie
radius = cmds.intSliderGrp(radius2, q = True, value = True) #metri
gamma = cmds.intSliderGrp(gamma2, q = True, value = True) #KN/mc
spess = cmds.intSliderGrp(spess2, q = True, value = True) #metri
sweep = cmds.intSliderGrp(sweep2, q = True, value = True)
C = 1 #Ampiezza (dipende dal vincolo, consideriamo un carrello, C=1)
delta = 0 #Sfasamento (dipende dal vincolo, consideriamo un carrello, delta=0)
poisson = 0.15 #coeff. di poisson (dipende dal materiale)
#Definisco la cupola
angolo = range(10,360,10) #angolo di rotazione dei semiarchi
cmds.circle(nr = (1, 0, 0), c = (0, 0, 0), sw = -sweep, r = radius, n="S1")
cmds.rotate(0,0,0)
cmds.move(0,0,0)
cupola1 = []
for i in range (35):
cmds.duplicate()
cmds.rotate(0,angolo[i],0)
cupola1 = cupola1 + ["S"+str(i+1)]
cmds.loft(cupola1, ['S36','S1'])
cmds.delete(cupola1, ['S36','S1'])
#Trasformo il loft(NURBS) in una polisuperficie
cmds.nurbsToPoly('loftedSurface1', name='pippo', mnd=1, ch=1, f=0, pt=0, pc=500, chr=0.9, ft=0.01, mel=0.001, d=0.1, ut=1, un=3, vt=1, vn=3, uch=0, ucr=0, cht=0.2,es=0,ntr=0,mrt=0,uss=1)
cmds.delete('loftedSurface1')
#Analizzo il numero di punti della superficie
n = cmds.polyEvaluate('pippo', v=True, f=False)
#Definisco un vettore vertex lungo quanto il numero dei punti della superficie
vertex = np.zeros((n,3))
angolo = np.zeros(n) #parte dalla base
angolo_complementare = np.zeros(n) #parte dall'asse
stress = np.zeros(n)
stress_adm = np.zeros(n)
vertex_adm = np.zeros((n,3))
#Mi tiro fuori le coordinate xyz dei punti appartenenti alla superficie
for i in range(n):
vertex[i,:]=(cmds.pointPosition('pippo.pt[%d]' %i))
#Calcolo lo sforzo normale di meridiano
for i in range(n):
lato = np.sqrt(vertex[i,0]**2+vertex[i,2]**2) #trovo il lato in pianta
diagonale = np.sqrt(lato**2+vertex[i,1]**2) #trovo la diagonale
angolo[i] = abs(np.arcsin(vertex[i,1]/diagonale)*180/np.pi) #trovo l'angolo (omega), in gradi
angolo_complementare[i] = (90-angolo[i])*np.pi/180
stress[i] = abs(-gamma*spess*radius*(1-np.cos(angolo_complementare[i]))/(np.sin(angolo_complementare[i]**2)))
#Calcolo lo sforzo normale adimensionale
where_are_NaNs = np.isnan(stress)
stress[where_are_NaNs] = 12 #quando ho valori non validi li sostituisco
stress_max = np.amax(stress)
for i in range(n):
stress_adm[i] = stress[i]/stress_max
vertex_max = np.amax(vertex[i][1])
for i in range(n):
vertex_adm[i][1] = vertex[i][1]/vertex_max
cmds.delete('loftedSurface1')
#for i in range(n):
#cmds.polyColorPerVertex('pippo.vtx[%d]'%i, rgb=(stress_adm[i], 0.5, 0.5))
cmds.setAttr("pippo.displayColors", 1)
cmds.refresh()
cmds.select('pippo', d=True)
def T():
for i in range(n):
cmds.polyColorPerVertex('pippo.vtx[%d]'%i, rgb=(stress_adm[i], 0.5, 0.5))
cmds.setAttr("pippo.displayColors", 1)
cmds.refresh()
cmds.select('pippo', d=True)
def V():
for i in range(n):
cmds.polyColorPerVertex('pippo.vtx[%d]'%i, rgb=(vertex_adm[i][1], 0.5, 0.5))
cmds.setAttr("pippo.displayColors", 1)
cmds.refresh()
cmds.select('pippo', d=True)
cmds.rowColumnLayout(numberOfColumns=4, columnWidth=[(1,75), (2,25), (3,75), (4,25), (5,200)], columnOffset=[(1,'both', 3)])
cmds.radioCollection()
StressColore2 = cmds.radioButton(label = 'StressColore', editable = True, onCommand = T)
cmds.separator(h=10, style='none')
VerticeColore = cmds.radioButton(label = 'VerticeColore', editable = True, onCommand = V)
cmds.separator(h=10, style='none')