Help with code...please!

Help with code...please!

Anonymous
Not applicable
393 Views
1 Reply
Message 1 of 2

Help with code...please!

Anonymous
Not applicable
Hi guys! This is my first time in here..and I`m going after help .. xD

ok, I have this assignment to do. It is supposed to find where there are locators in the scene, get their position and create a wind turbine on it...also, the user has to be able to tell the program how many blades, height and blades length...

all of it is already done, including the UI..

It works when u run it from mayas scripts editor fine...but the assignment says....the code will go to the users computers (maya scripts folder)..then the user will type in the command line...

from (name of script) import*

When I do that, the global vaiables ( the ones right at the beggining of the code) wont be read!

can someone please help me?

Here is the code


------------------------------------------------

import maya.cmds as cmds
import maya.cmds as mc

numbBlades=1
heightTurb=1
lenghtBlades=1


####Above are the variables that only work when I run it through
####script editor (select the whole code and execute)
#### but when ran through command line
####(from (filename) import*) it doesn't read them.

#Window
def myWindow():

if cmds.window("Window", ex=True):
cmds.deleteUI("Window")

cmds.window('Window', t='Turbines Creation Window', w=500, h=250)
cmds.scrollLayout('scrollLayout')
cmds.columnLayout(adjustableColumn=True)
cmds.button(l="Refresh", c="myWindow()")
cmds.intSliderGrp('blades1', l="Number of Blades", min=2, max=50, field=True, s=1, v=3)
cmds.intSliderGrp('blades2', l="Turbine's Height", min=2, max=50, field=True, s=1, v=1)
cmds.intSliderGrp('blades3', l="Blades Length", min=2, max=50, field=True, s=1, v=15)

cmds.frameLayout(label='Full Creation Mode', borderStyle='in' )
cmds.text('Full Creation Mode will:' )
cmds.text('Create all turbines')
cmds.text('Set Animation to 1000 frames')
cmds.text('Set Playback to PAL')
cmds.text('Set Playback speed to Real-Time')
cmds.text('Animation will be played automatically')

cmds.button(l='Create Turbines (Full Creation Mode)', w=500, h=50, c="cmds.currentUnit(t='pal');cmds.playbackOptions(max=1000, aet=1000, ps=1); cmds.currentTime(1);cmds.play(f=1); global numbBlades;numbBlades=cmds.intSliderGrp('blades1', q=True, v=True);global heightTurb;heightTurb=cmds.intSliderGrp('blades2', q=True, v=True);global lenghtBlades;lenghtBlades=cmds.intSliderGrp('blades3', q=True, v=True);findLocators()")

cmds.frameLayout(label='Free Creation Mode', borderStyle='in' )
cmds.text('Free Creation Mode will let ypu choose the optimal options for your project.' )
cmds.button(l='Create Turbines', c="global numbBlades;numbBlades=cmds.intSliderGrp('blades1', q=True, v=True);global heightTurb;heightTurb=cmds.intSliderGrp('blades2', q=True, v=True);global lenghtBlades;lenghtBlades=cmds.intSliderGrp('blades3', q=True, v=True);findLocators()")
cmds.button(l='Set Playback to Pal', c="cmds.currentUnit(t='pal')")
cmds.button(l='Set Playback speed to Real-Time', c="cmds.playbackOptions(ps=1)")
cmds.button(l='Set Animation to 1000 frames', c="cmds.playbackOptions(max=1000, aet=1000)")
cmds.button(l='Set Current Time to Frame 1', c="cmds.currentTime(1)")
cmds.button(l='Play', c="cmds.play(f=1)")

cmds.showWindow()
myWindow()

#Arrow

wind = cmds.curve(n="Wind Direction", degree=1, p=, k= )
cmds.scale(15,15,15)
cmds.move(100, y=True)

#r = cmds.getAttr(wind)


#Turbines
def turbine(x, y, z):



#Construction
#Pole
pole=cmds.polyCylinder(n='pole', r=1, h=2, sx=20, sz=1)
cmds.scale(1, 25, 1)
mc.xform(ws=True, rotatePivot=(0,0,0))
cmds.scale(25+heightTurb, y=True)

#Axel Base
axel=cmds.polyCylinder(n='axel', r=1, h=2, sx=20, sz=1)
cmds.move(0.1, 25+heightTurb, 0)
cmds.rotate(0, 0, 90)
cmds.scale(1.5, 1.5, 1.5)

#Axel Engine
axelEngine=cmds.polyCylinder(n='axelEngine', r=1, h=2, sx=20, sz=1)
cmds.move(2, 25, 0)
cmds.rotate(0, 0, 90)
cmds.scale(1, 1, 1)

listOfBlades=[]

#Blades
blades=cmds.polyCube(n='blade')
cmds.move(2.2, 25, -7.6)
cmds.rotate(0, 0, 16)
cmds.scale(0.2, 1, 15)
cmds.move(0, 0, 7.6, ('blade.scalePivot', 'blade.rotatePivot'), r=True)
cmds.scale(15+lenghtBlades, z=True)
listOfBlades.append('%s' l;ades)


#Duplication
i=numbBlades

for blades in range (1,i):
newBlade=cmds.duplicate(n='blade')
cmds.rotate(blades*360/i, 0, 0, newBlade)
listOfBlades.append(newBlade)


#Grouping

cmds.select(listOfBlades, axelEngine)
fan=cmds.group()
mc.xform(ws=True, rotatePivot=(0,25,0))
cmds.move(0, 0+heightTurb, 0)

#Rotate Expression

cmds.expression(o="%s"ún, s="%s.rotateX = 360/24*(time/4);"ún)


cmds.select(fan, pole, axel)
fullTurbine=cmds.group(n='Turbine1')
mc.xform(ws=True, rotatePivot=(0,-25,0))
cmds.move(x, y+25, z)



#Arrow Expression
cmds.expression(o="%s" u;llTurbine, s="%s.rotateY = %s.rotateY;"%(fullTurbine, wind))
#Shading
SG=cmds.sets(renderable=True, nss=True, empty=True, n='BlinnSG')
shader=cmds.shadingNode('blinn', asShader=True, n='RedBlinn')
cmds.connectAttr(shader+'.outColor', SG+'.surfaceShader')
cmds.setAttr(shader+'.color', 1.0, 0.0, 0.0)
cmds.sets(fullTurbine, edit=True ,forceElement=SG)

SG2=cmds.sets(renderable=True, nss=True, empty=True, n='BlinnSG2')
shader2=cmds.shadingNode('blinn', asShader=True, n='WhiteBlinn')
cmds.connectAttr(shader2+'.outColor', SG2+'.surfaceShader')
cmds.setAttr(shader2+'.color', 1.0, 1.0, 1.0)
cmds.sets(fan, edit=True ,forceElement=SG2)


#Locators Finder
def findLocators():
listLocators=cmds.ls(type='locator')
for position in listLocators:
transNode=cmds.listRelatives(position, p=True)
x=cmds.getAttr(transNode+".tx")
y=cmds.getAttr(transNode+".ty")
z=cmds.getAttr(transNode+".tz")
print x,y,z
noLocator = position
print noLocator
turbine (x,y,z)

---------------------------------------------------------------------


Since now..Thanks guys!
I appreciate any support.

Regards
0 Likes
394 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
It looks like pasting my code in here makes it lose its indentatiun.

here is the code again...

import maya.cmds as cmds
import maya.cmds as mc

numbBlades=1
heightTurb=1
lenghtBlades=1

#Window
def myWindow():

if cmds.window("Window", ex=True):
cmds.deleteUI("Window")

cmds.window('Window', t='Turbines Creation Window', w=500, h=250)
cmds.scrollLayout('scrollLayout')
cmds.columnLayout(adjustableColumn=True)
cmds.button(l="Refresh", c="myWindow()")
cmds.intSliderGrp('blades1', l="Number of Blades", min=2, max=50, field=True, s=1, v=3)
cmds.intSliderGrp('blades2', l="Turbine's Height", min=2, max=50, field=True, s=1, v=1)
cmds.intSliderGrp('blades3', l="Blades Length", min=2, max=50, field=True, s=1, v=15)

cmds.frameLayout(label='Full Creation Mode', borderStyle='in' )
cmds.text('Full Creation Mode will:' )
cmds.text('Create all turbines')
cmds.text('Set Animation to 1000 frames')
cmds.text('Set Playback to PAL')
cmds.text('Set Playback speed to Real-Time')
cmds.text('Animation will be played automatically')

cmds.button(l='Create Turbines (Full Creation Mode)', w=500, h=50, c="cmds.currentUnit(t='pal');cmds.playbackOptions(max=1000, aet=1000, ps=1); cmds.currentTime(1);cmds.play(f=1); global numbBlades;numbBlades=cmds.intSliderGrp('blades1', q=True, v=True);global heightTurb;heightTurb=cmds.intSliderGrp('blades2', q=True, v=True);global lenghtBlades;lenghtBlades=cmds.intSliderGrp('blades3', q=True, v=True);findLocators()")

cmds.frameLayout(label='Free Creation Mode', borderStyle='in' )
cmds.text('Free Creation Mode will let ypu choose the optimal options for your project.' )
cmds.button(l='Create Turbines', c="global numbBlades;numbBlades=cmds.intSliderGrp('blades1', q=True, v=True);global heightTurb;heightTurb=cmds.intSliderGrp('blades2', q=True, v=True);global lenghtBlades;lenghtBlades=cmds.intSliderGrp('blades3', q=True, v=True);findLocators()")
cmds.button(l='Set Playback to Pal', c="cmds.currentUnit(t='pal')")
cmds.button(l='Set Playback speed to Real-Time', c="cmds.playbackOptions(ps=1)")
cmds.button(l='Set Animation to 1000 frames', c="cmds.playbackOptions(max=1000, aet=1000)")
cmds.button(l='Set Current Time to Frame 1', c="cmds.currentTime(1)")
cmds.button(l='Play', c="cmds.play(f=1)")

cmds.showWindow()
myWindow()

#Arrow

wind = cmds.curve(n="Wind Direction", degree=1, p=, k= )
cmds.scale(15,15,15)
cmds.move(100, y=True)

#r = cmds.getAttr(wind)


#Turbines
def turbine(x, y, z):



#Construction
#Pole
pole=cmds.polyCylinder(n='pole', r=1, h=2, sx=20, sz=1)
cmds.scale(1, 25, 1)
mc.xform(ws=True, rotatePivot=(0,0,0))
cmds.scale(25+heightTurb, y=True)

#Axel Base
axel=cmds.polyCylinder(n='axel', r=1, h=2, sx=20, sz=1)
cmds.move(0.1, 25+heightTurb, 0)
cmds.rotate(0, 0, 90)
cmds.scale(1.5, 1.5, 1.5)

#Axel Engine
axelEngine=cmds.polyCylinder(n='axelEngine', r=1, h=2, sx=20, sz=1)
cmds.move(2, 25, 0)
cmds.rotate(0, 0, 90)
cmds.scale(1, 1, 1)

listOfBlades=[]

#Blades
blades=cmds.polyCube(n='blade')
cmds.move(2.2, 25, -7.6)
cmds.rotate(0, 0, 16)
cmds.scale(0.2, 1, 15)
cmds.move(0, 0, 7.6, ('blade.scalePivot', 'blade.rotatePivot'), r=True)
cmds.scale(15+lenghtBlades, z=True)
listOfBlades.append('%s' l;ades)


#Duplication
i=numbBlades

for blades in range (1,i):
newBlade=cmds.duplicate(n='blade')
cmds.rotate(blades*360/i, 0, 0, newBlade)
listOfBlades.append(newBlade)


#Grouping

cmds.select(listOfBlades, axelEngine)
fan=cmds.group()
mc.xform(ws=True, rotatePivot=(0,25,0))
cmds.move(0, 0+heightTurb, 0)

#Rotate Expression

cmds.expression(o="%s"ún, s="%s.rotateX = 360/24*(time/4);"ún)


cmds.select(fan, pole, axel)
fullTurbine=cmds.group(n='Turbine1')
mc.xform(ws=True, rotatePivot=(0,-25,0))
cmds.move(x, y+25, z)



#Arrow Expression
cmds.expression(o="%s" u;llTurbine, s="%s.rotateY = %s.rotateY;"%(fullTurbine, wind))
#Shading
SG=cmds.sets(renderable=True, nss=True, empty=True, n='BlinnSG')
shader=cmds.shadingNode('blinn', asShader=True, n='RedBlinn')
cmds.connectAttr(shader+'.outColor', SG+'.surfaceShader')
cmds.setAttr(shader+'.color', 1.0, 0.0, 0.0)
cmds.sets(fullTurbine, edit=True ,forceElement=SG)

SG2=cmds.sets(renderable=True, nss=True, empty=True, n='BlinnSG2')
shader2=cmds.shadingNode('blinn', asShader=True, n='WhiteBlinn')
cmds.connectAttr(shader2+'.outColor', SG2+'.surfaceShader')
cmds.setAttr(shader2+'.color', 1.0, 1.0, 1.0)
cmds.sets(fan, edit=True ,forceElement=SG2)


#Locators Finder
def findLocators():
listLocators=cmds.ls(type='locator')
for position in listLocators:
transNode=cmds.listRelatives(position, p=True)
x=cmds.getAttr(transNode+".tx")
y=cmds.getAttr(transNode+".ty")
z=cmds.getAttr(transNode+".tz")
print x,y,z
noLocator = position
print noLocator
turbine (x,y,z)

0 Likes