return0
November 25, 2021, 4:29am
1
Hello, I’m working on a script that replicates ImagePlane position values to a PolyPlane.
by selecting the imagePlane1 object
self.objectSelected = cmds.ls(selection = True)
Then, by pressing the convert button, a PolyPlane with the correct X,Y,Z position and scale is created.
def select(self,*args):
self.select1 = cmds.ls(selection = True)
for item in select1:
self.x_value = cmds.getAttr("%s.translateX" % item)
self.y_value = cmds.getAttr("%s.translateY" % item)
self.z_value = cmds.getAttr("%s.translateZ" % item)
self.sx_value = cmds.getAttr("%s.scaleTranslationX" % item)
self.sy_value = cmds.getAttr("%s.scaleTranslationY" % item)
self.sz_value = cmds.getAttr("%s.scaleTranslationZ" % item)
cmds.polyPlane (name = 'polyPlane1' ,tx = x_value, ty = y_value, tz = z_value, sx = sx_value, sy = sy_value, sz = sz_value )
Unfortunately, it triggers errors, so I won’t be able to work it out on my own… Any ideas?
What errors are you getting?
I’m not seeing a class definition in your code, only a function. the ‘self’ reference is generally a class instance variable. Is that what your errors are referring to? If you remove the ‘self.’ before each variable does it behave differently?
return0
November 25, 2021, 6:39am
3
Sorry! here’s my code
import maya.cmds as cmds
import maya.mel
class script_Window(object):
def __init__(self):
self.window = "x"
self.title = "x "
self.size = (500,500)
if cmds.window(self.window,exists=True):
cmds.deleteUI(self.window,window=True)
self.window = cmds.window(self.window,title=self.title,widthHeight=self.size)
cmds.columnLayout(adjustableColumn=True)
cmds.text(self.title)
cmds.separator(height=20)
self.conbtn = cmds.button(label = 'convert',command = self.imageSelected )
cmds.separator(height=20)
cmds.showWindow()
def selected(self,*args):
self.objectSelected = cmds.ls(selection = True)
for item in select1:
self.x_value = cmds.getAttr("%s.translateX" % item)
self.y_value = cmds.getAttr("%s.translateY" % item)
self.z_value = cmds.getAttr("%s.translateZ" % item)
self.sx_value = cmds.getAttr("%s.scaleTranslationX" % item)
self.sy_value = cmds.getAttr("%s.scaleTranslationY" % item)
self.sz_value = cmds.getAttr("%s.scaleTranslationZ" % item)
cmds.polyPlane (name = 'polyPlane1' ,tx = x_value, ty = y_value, tz = z_value, sx = sx_value, sy = sy_value, sz = sz_value )
cmds.polyPlane ()
cmds.setAttr('.rotateX',90)
activateScript = script_Window()
i had this problem # Error: NameError: file line 20: global name ‘select1’ is not defined #
i dont know how to fix it. also yes it does behave differently if I remember correctly.
amator
November 25, 2021, 6:32pm
4
it seams for now it should be-- for item in self.objectSelected