May 03, 2016 Python: Built-in Functions hasattr(object, name), getattr(object, name, default),setattr(object, name, value),delattr(object, name) issubclass(class, classinfo).
![]() ![]()
1) getAttr and setAttrimport maya.cmdsloc = maya.cmds.spaceLocator0; //create a new locator and store the name of its transform mode in a variable called locsx = maya.cmds.getAttr(loc+ '.scaleX'); //store the locator's x-scale in a variable named sxprint(sx); // print the result, which will be 1 by defaultsx.= 2; //double the sx valuemaya.cmds.setAttr(loc+'.scaleX', sx); //assign the new value to the node's attribute by passing a string with the node's name, a period, and the attribute name2) Compound Attributesprint(maya.cmds. Xform(loc, q=True, translation=True)); //print the locator's translation using the xform command0.0, 0.0, 0.0 //the resultmaya.cmds. Xform(loc, translation=0,1,0); //using the xform command to set a new translation value (using a list)print(maya.cmds. GetAttr(loc+'.translate')); //print the locator's translation using getAttr command(0.0, 1.0, 0.0) // the command returns a list that contains a tuplemaya.cmds.
SetAttr(loc+'.translate', 1, 2, 3); //using setAttr to set a new translation value for the locatorResult. 3) connectAttr and disconnectAttrThe basic requirement for attributes to be connected is that they be of the same type.import maya.cmds;sphere = maya.cmds.polySphere0;cube = maya.cmds.polyCube0;//create a sphere and a cube and store the names of their transform nodesmaya.cmds.connectAttr(cube+'.ry', sphere+'.ty'); //connect the cube's y-rotation to the sphere's y-translationmaya.cmds.select(cube);maya.cmds.disconnectAttr(cube+'.ry', sphere+'.ty');# Result: Disconnect pCube2.rotate.rotateY from pSphere2translate.translateY. #//execute the following lines to create a multiplyDivide node between the two attributes to scale the effectmult = maya.cmds.createNode('multiplyDivide');maya.cmds.connectAttr(cube+'.rt', mult+'.input1X');maya.cmds.setAttr(mult+'.input2X', 1.0/90.0);maya.cmds.connectAttr(mult+'.outputX', sphere+'.ty');maya.cmds.select(cube);Result: if you rotate the cube, the sphere translates 1 unit for every 90 degrees of rotation.
Import maya.OpenMaya as omimport maya.OpenMayaUI as muiimport sipfrom PyQt4 import QtCore, QtGuiimage = om.MImageview = mui.M3dView.active3dViewview.readColorBuffer(image, True)w,h = view.portWidth, view.portHeightvptr = sip.voidptr(long(image.pixels))i = QtGui.QImage(vptr, w, h, QtGui.QImage.FormatRGB32)trans = QtGui.QTransformtrans.scale(-1, 1)trans.rotate(180)i = i.transformed(trans, QtCore.Qt.SmoothTransformation).rgbSwapped.copy(0,0,300,200)i.save('screencap.png').
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
February 2023
Categories |