Did I missed something on my Maya install that every scripts wont run?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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. Btw I found the 2nd code from this post). 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. And I'm pretty sure there's supposed to be Scripts menu that is usually sitting between Arnold and Substance menu which didn't exists for me (Substance menu also didn't exists for me but I'm not looking for this for now. It's usually sits near Cache menu so in order it's Cache - Substance - Scripts - Arnold, but those two just do not exists at all)
Code 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 mc
class OptionsWindow(object):
"""Base Window Class"""
# This method was indented incorrectly and missing @classmethod decorator
@classmethod
def showUI(cls):
win = cls()
win.create()
return win
def __init__(self):
self.window = "optionsWindow"
self.title = "OptionsWindow"
self.size = (546, 350)
self.button1 = "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.actionBtn = 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.button1 = "Action"
self.button2 = "Apply"
self.button3 = "Close"
def actionCmd(self, *args):
self.radius = mc.floatFieldGrp(self.grp, query=True, value1=True) # get value'
mc.polySphere(r=self.radius)
def displayOptions(self):
############################################################################
# Here insert custom controls
# self.grp = mc.floatFieldGrp(numberOfFields=1, label="Radius", value1=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", value1=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):
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.twisteps = 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, value1=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()
Code 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)
Did I do something wrong here? What am I missing? Or if there's nothing really wrong with the first code, where do I go to launch the stair generator window? Maya version is 2019