Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Maya 2019/ 2020 executing scripts ends up in nothing happened

Maya 2019/ 2020 executing scripts ends up in nothing happened

KokiWatafak
Explorer Explorer
347 Views
1 Reply
Message 1 of 2

Maya 2019/ 2020 executing scripts ends up in nothing happened

KokiWatafak
Explorer
Explorer

All of these python scripts to generate stairs just outright not working at all. On script editor, when I click execute it didn't do anything as in nothing happened, not even error (except for the 2nd code which spits out // Error: Line 2.19: Invalid use of Maya object "object". error when I move it from Python tab to MEL. Oh by the way, I found the 2nd code from this post whereas the 1st one was from here). Saving it as a .py file and putting it on the scripts folder on Documents\Maya didn't do anything. Drag and dropping the .py file directly to Maya didn't do anything.

 

Untitled.png

Untitled1.png

 

And also I don't know how is there a Scripts menu on this video as well, but mine just outright not having it. Did I missed something here? Do I have to install Maya Devkit or something like Devkit + PyCharm combo? Or is it just minor mistake in the code?

 

Script #1:

"""
 OptionsWindow is a class definition of the basic window class.
 The class is adding a set of controls to create a template
 that resembles Maya's built-in tool option windows.
"""

import maya.cmds as cmds
import math

class OptionsWindow(object):
    """Base Window Class"" 
    
    #@classmethod
    def showUI(cls):
        win = cls()
        win.create()
        return win
        
    def __init__(self):
        self.window= "optionsWindow"
        self.title = "OptionsWindow"
        self.size = (546,350)
        self.buttonl= "Action"
        self.button2= "Apply"
        self.button3= "Close"
	
    def create (self):
        if mc.window(self.window,exists=True):
            mc.deleteUI(self.window,window=True)
		
    self.window = mc.window (self.window, title=self.title,widthHeight=self.size,menuBar=True)
	self.mainForm = mc.formLayout (nd=100)
    self.commandMenu()
    self.commonButtons()
    self.optionsBorder=mc.tabLayout (scrollable=True,height=1)
    mc.formLayout(self.mainForm, e=True,
                        attachForm=[
                            (self.optionsBorder, "top", 0),
                            (self.optionsBorder, "left", 2),
                            (self.optionsBorder, "right", 2)
                        ],
                        attachControl=[
                            (self.optionsBorder, "bottom", 5, self.applyBtn)
                        ])
					
    self.optionsForm-mc.formLayout (nd=100)
    mc.tabLayout(self.optionsBorder, edit=True, tabLabel= (self.optionsForm, "Test")) 
	self.displayOptions()
    mc.showWindow()
	
    def commandMenu(self):
        self.editMenu = mc.menu(label="Edit")
        self.editMenuSave = mc.menuItem (label="Save Settings",command-self.editMenuSaveCmd) 
        self.editMenuReset = mc.menuItem(label="Reset Settings",command=self.editMenuResetCmd)
        self.helpMenu = mc.menu (label="Help")
        self.helpMenuItem = mc.menuItem(label="Help on %s"%(self.title),command=self.helpMenuCmd)
    def helpMenuCmd(self, *args):
        mc.launch(web="http://maya-python.com")
        def editMenuSaveCmd (self, *args):pass
    def editMenuResetCmd (self, *args):pass

    def actionCmd(self,*args):
        print "ACTION"
    def applyBtnCmd(self,*args):
        print "APPLY"
    def closeBtnCmd(self,*args):
        mc.deleteUI(self.window,window=True)


    def commonButtons(self):
        self.commonBtnSize=(self.size[0]-18/3,26)
        self.acctionBtn=mc.text(label='')
        self.applyBtn=mc.text(label='')
        self.closeBtn=mc.button(label=""+self.button3,height=self.commonBtnSize[1],command=self.closeBtnCmd)


    mc.formLayout(self.mainForm, e=True,
                        attachForm=[
                            (self.actionBtn, "left", 5),
                            (self.actionBtn, "bottom", 5),
                            (self.applyBtn, "bottom", 5),
                            (self.closeBtn, "bottom", 5),
                            (self.closeBtn, "right", 5)
                        ],
                        attachPosition=[
                            (self.actionBtn, "right", 1, 33),
                            (self.closeBtn, "left", 0, 67)
                        ],
                        attachControl=[
                            (self.applyBtn, "left", 4, self.actionBtn),
                            (self.applyBtn, "right", 4, self.closeBtn)
                        ],
                        attachNone=[
                            (self.actionBtn, "top"),
                            (self.applyBtn, "top"),
                            (self.closeBtn, "top")
                        ])
                        
    def displayOptions(self):pass


class MyOptionsWindow(OptionsWindow):
    """Custom Window Class, subclass of the OptionWindow base class"""

    def __init__(self):
        self.window = "optionsWindow"
        self.title = "OptionsWindow"
        self.size = (546,350)
        self.buttonl= "Action"
        self.button2= "Apply"
        self.button3= "Close"

    def actionCmd(self,*args):
        self.radius = mc.floatFieldGrp(self.grp, query = True, valuel = True)#get value
        mc.polySphere(r=self.radius)

    def displayOptions(self):
        ############################################################################
        # Here insert custom controls
        # self.grp = mc.floatFieldGrp(numberOfFields = 1, label = "Radius", valuel = 5.0)

        mc.columnLayout()
        mc.text(label='StairSize')
        mc.text(label='Step Number')
        mc.intField("Steps", minValue-0,maxValue-50,value=10)
        mc.text(label='Angle PerStep')
        mc.intField("Angle", minValue=0,maxValue-360,value=15)
        mc.text(label='Step Dimension')
        self.stepXYZ = mc.floatFieldGrp(numberOfFields = 3,label = "input vector",valuel=5.0,value2=3.0,value3=0.5)
        mc.button (label="Regular", command = self.Normal,w=130)

    def Normal(self,*args):
        self.Nstep=mc.intField("Steps", q=true, value=True)
        step=[]
        width = mc.floatFieldGrp(self.stepXYZ,query = True,value1 =True) #red X
        depth = mc.floatFieldGrp(self.stepXYZ,query = True,value2 =True) #blue Z
        height= mc.floatFieldGrp(self.stepXYZ,query = True,value3 =True) #green Y
    
        for number in range(self.Nstep):
            print number
            step.append(mc.polyCube(w=width, d=depth, h=height, n='Smallstep')[0])
            mc.move(0,number*height,(depth/2)*number * -1,r=True)
        self.twiststeps = mc.group(step, name="AllSteps")
        self.EntireStaircase = mc.group( em=True, name='EntireStaircase')
        mc.group( 'AllSteps', parent='EntireStairCase')


    def applyBtnCmd(self,*args):
        self.valueX = mc.floatFieldGrp(self.grp2, query = True,valuel =True)
        self.valueY = mc.floatFieldGrp(self.grp2, query = True,value2 =True) 
        self.valueZ = mc.floatFieldGrp(self.grp2, query = True,value3 =True) 
        finalCube = mc.polyCube(w=self.valueX,h=self.valueY,d=self.valueZ,n="myCube")

def EncapsulatedStairsGenerator():
    win = MyOptionsWindow()
    win.create()

 

 

Script #2:

 

from maya import cmds
class Stair(object):
    """
    import stairCreator as sc
    reload(sc)
    stair = sc.Stair()
    stair.createStair()
    stair.changeStair(steps=05, height=1)
    """
    # init sets up default vales
    def __init__(self):
        self.transform = None
        self.extrude = None
        self.constructor = None
    def createStair(self, steps=20, height=1, length=24, width=10):
        self.transform, self.constructor = cmds.polyPlane(subdivisionsHeight=steps, subdivisionsWidth=1, width=width, height=length)
        self.frontFaces = range(steps)
        for face in self.frontFaces:
            self.extrude = cmds.polyExtrudeFacet('%s.f[%s:%s]' % (self.transform, face, steps-1), localTranslateZ=height)[0]



    # changeing shape after creation----------------------------------
    def changeStair(self, steps=20, height=1, length=24, width=10):

        cmds.polyPlane(self.constructor, edit=True, subdivisionsHeight=steps, width=width, height=length, scaleY=height)

 

 

*Also hopefully this one isn't falsely marked as Spam again... Literally that's first time I ever posted something in here and it gets immediately busted for no reason

 

 

 

0 Likes
348 Views
1 Reply
Reply (1)
Message 2 of 2

mcw0
Advisor
Advisor
    import stairCreator as sc
    reload(sc)
    stair = sc.Stair()
    stair.createStair()
    stair.changeStair(steps=05, height=1)


You need to run the code that's been commented out.

0 Likes