Python maya.OpenMaya.MPlug() Examples
The following are 14
code examples of maya.OpenMaya.MPlug().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
maya.OpenMaya
, or try the search function
.
Example #1
Source File: mayauserprops.py From cross3d with MIT License | 6 votes |
def keys(self): # TODO MIKE: I had to do a try except here for the the object called "|groundPlane_transform". # It's apparently always in the scene and error with that line. try: keys = cmds.listAttr(cross3d.SceneWrapper._mObjName(self._nativePointer), userDefined=True) if keys: return keys except ValueError: pass return [] # http://forums.cgsociety.org/showthread.php?t=888612 # Note: I was unable to find a way to identify userDefined keys in the following method # so I used the maya.cmds method. If possible this finish this method and replace the # above code. #depNode = om.MFnDependencyNode(mObj) #total = depNode.attributeCount() #count = 0 #while count < total: # attr = depNode.attribute(count) # plug = om.MPlug(mObj, attr) # count += 1 # print count, attr.apiTypeStr(), plug.name()
Example #2
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 6 votes |
def getCurveFn(self): inputCurvePlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.inputCurveAttr) curve = getSingleSourceObjectFromPlug(inputCurvePlug) # Get Fn from a DAG path to get the world transformations correctly if curve is not None: path = OpenMaya.MDagPath() trFn = OpenMaya.MFnDagNode(curve) trFn.getPath(path) path.extendToShape() if path.node().hasFn(OpenMaya.MFn.kNurbsCurve): return OpenMaya.MFnNurbsCurve(path) return None # Calculate expected instances by the instancing mode
Example #3
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 6 votes |
def getInstanceCountByMode(self): instancingModePlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.instancingModeAttr) inputCurvePlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.inputCurveAttr) if inputCurvePlug.isConnected() and instancingModePlug.asInt() == 1: instanceLengthPlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.instanceLengthAttr) maxInstancesByLengthPlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.maxInstancesByLengthAttr) curveFn = self.getCurveFn() # Known issue: even if the curve fn is dag path constructed, its length is not worldspace... # If you want perfect distance-based instancing, freeze the transformations of the curve curveLength = curveFn.length() curveStart = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.curveStartAttr).asFloat() * curveLength curveEnd = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.curveEndAttr).asFloat() * curveLength effectiveCurveLength = min(max(curveEnd - curveStart, 0.001), curveLength) return min(maxInstancesByLengthPlug.asInt(), int(math.ceil(effectiveCurveLength / instanceLengthPlug.asFloat()))) instanceCountPlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.instanceCountAttr) return instanceCountPlug.asInt()
Example #4
Source File: pluginMaya.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def _addAttr(_fnDependNode, _sName, _pValue): sType = core.getDataType(_pValue) # Skip empty list bIsMulti = sType == core.TYPE_LIST if bIsMulti and len(_pValue) == 0: return plug = None # Get attribute arguments try: # TODO: Is a try/catch really the best way to know if the plug exists? plug = _fnDependNode.findPlug(_sName) except: pass if plug is None: fnAtt = _createAttribute(_sName, _pValue) if fnAtt is None: return # In case of invalid value like missing pymel PyNode & Attributes fnAtt.setNiceNameOverride(_sName) moAtt = fnAtt.object() if moAtt is not None: _fnDependNode.addAttribute(moAtt) plug = OpenMaya.MPlug(_fnDependNode.object(), moAtt) if plug is not None: _setAttr(plug, _pValue)
Example #5
Source File: instance_data.py From spore with MIT License | 5 votes |
def __init__(self, node): log_lvl = sys._global_spore_dispatcher.spore_globals['LOG_LEVEL'] self.logger = logging_util.SporeLogger(__name__, log_lvl) dg_fn = om.MFnDependencyNode(node) self.node_name = dg_fn.name() self.node = node # TODO - hold on to selection list instead of mobj # self.bounding_box = None self.state = None self.data_plug = om.MPlug() self.data_object = om.MObject() # instance data attributes self.position = om.MVectorArray() self.scale = om.MVectorArray() self.rotation = om.MVectorArray() self.instance_id = om.MIntArray() self.visibility = om.MIntArray() self.normal = om.MVectorArray() self.tangent = om.MVectorArray() self.u_coord = om.MDoubleArray() self.v_coord = om.MDoubleArray() self.poly_id = om.MIntArray() self.color = om.MVectorArray() self.unique_id = om.MIntArray() self.exclusive_paint = [] # collect points for kd tree self.np_position = np.empty((0,3), float) self.tree = None self.logger.info('Instanciate new InstanceData object for: {}'.format(self.node_name))
Example #6
Source File: instance_data.py From spore with MIT License | 5 votes |
def initialize_data(self): """ get cache data from the sporeNode's instanceData plug/ :param instance_data_plug MPlug: instanceData plug """ node_fn = om.MFnDependencyNode(self.node) self.data_plug = node_fn.findPlug('instanceData') self.data_object = self.data_plug.asMObject() array_attr_fn = om.MFnArrayAttrsData(self.data_object) self.position = array_attr_fn.vectorArray('position') self.scale = array_attr_fn.vectorArray('scale') self.rotation = array_attr_fn.vectorArray('rotation') self.instance_id = array_attr_fn.intArray('objectIndex') self.visibility = array_attr_fn.intArray('visibility') self.normal = array_attr_fn.vectorArray('normal') self.tangent = array_attr_fn.vectorArray('tangent') self.u_coord = array_attr_fn.doubleArray('u_coord') self.v_coord = array_attr_fn.doubleArray('v_coord') self.poly_id = array_attr_fn.intArray('poly_id') self.color = array_attr_fn.vectorArray('color') self.unique_id = array_attr_fn.intArray('unique_id') # TODO - set bb # get position as numpy array for i in xrange(self.position.length()): position = [[self.position[i].x, self.position[i].y, self.position[i].z]] self.np_position = np.append(self.np_position, position, axis=0) self.logger.debug('Initialize InstanceData object for: {}'.format(self.node_name))
Example #7
Source File: mayascenewrapper.py From cross3d with MIT License | 5 votes |
def _getPlug(cls, mObj, name): """ For a given OpenMaya.MObject return the OpenMaya.MPlug object with that attribute name. If the property does not exist, raises "RuntimeError: (kInvalidParameter): Cannot find item of required type" :param mObj: The source MObject :param name: The name of the attribute to get from mObj. :return: A OpenMaya.MPlug object """ with ExceptionRouter(): depNode = om.MFnDependencyNode(mObj) attr = depNode.attribute(name) return om.MPlug(mObj, attr)
Example #8
Source File: oyTrajectoryDrawer.py From anima with MIT License | 5 votes |
def getSize(self): thisNode = self.thisMObject() plug = OpenMaya.MPlug(thisNode, self.aSize) sizeVal = plug.asMDistance() return sizeVal.asCentimeters()
Example #9
Source File: oyTrajectoryDrawer.py From anima with MIT License | 5 votes |
def getTPositions(self): """reads the trajectory positions from the attribute by using the plug instead of the dataBlock """ thisNode = self.thisMObject() plug = OpenMaya.MPlug( thisNode, self.aTPos ) vectorArrayDataFn = OpenMaya.MFnVectorArrayData( plug.asMObject() ) tPosVectArray = vectorArrayDataFn.array() return tPosVectArray
Example #10
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 5 votes |
def getShadingGroup(self): inputSGPlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.inputShadingGroupAttr) sgNode = getSingleSourceObjectFromPlug(inputSGPlug) if sgNode is not None and sgNode.hasFn(OpenMaya.MFn.kSet): return OpenMaya.MFnSet(sgNode) return None
Example #11
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 5 votes |
def getInputTransformPlug(self): # Backward compatibility inputTransformPlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.inputTransformAttr) legacyInputTransformPlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.legacyInputTransformAttr) if(legacyInputTransformPlug.isConnected()): inputTransformPlug = legacyInputTransformPlug return inputTransformPlug
Example #12
Source File: ml_arcTracer.py From ml_tools with MIT License | 5 votes |
def getWorldValueAtFrame(attr, frame): mSelectionList = OpenMaya.MSelectionList() mSelectionList.add(attr) plug = OpenMaya.MPlug() mSelectionList.getPlug(0, plug) context = OpenMaya.MDGContext(OpenMaya.MTime(frame)) return plug.asDouble(context)
Example #13
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 4 votes |
def __init__(self, mObject, dataBlock, rampAttr, normalize, instanceCount): self.ramp = OpenMaya.MRampAttribute(OpenMaya.MPlug(mObject, rampAttr.ramp)) self.rampOffset = dataBlock.inputValue(rampAttr.rampOffset).asFloat() self.rampRandomAmplitude = dataBlock.inputValue(rampAttr.rampRandomAmplitude).asFloat() self.rampAmplitude = dataBlock.inputValue(rampAttr.rampAmplitude).asFloat() self.rampRepeat = dataBlock.inputValue(rampAttr.rampRepeat).asFloat() if normalize: self.rampAxis = dataBlock.inputValue(rampAttr.rampAxis.compound).asVector().normal() else: self.rampAxis = dataBlock.inputValue(rampAttr.rampAxis.compound).asVector() self.useDynamicAmplitudeValues = False amplitudePlug = OpenMaya.MPlug(mObject, rampAttr.rampAmplitude) if amplitudePlug.isConnected(): # Get connected input plugs connections = OpenMaya.MPlugArray() amplitudePlug.connectedTo(connections, True, False) # Find input transform if connections.length() == 1: node = connections[0].node() nodeFn = OpenMaya.MFnDependencyNode(node) resultColors = OpenMaya.MFloatVectorArray() resultTransparencies = OpenMaya.MFloatVectorArray() uValues = OpenMaya.MFloatArray(instanceCount, 0.0) vValues = OpenMaya.MFloatArray(instanceCount, 0.0) # Sample a line, for more user flexibility for i in xrange(instanceCount): uValues.set(i / float(instanceCount), i) vValues.set(i / float(instanceCount), i) # For now... then we can just use the plug (TODO) if(node.hasFn(OpenMaya.MFn.kTexture2d)): OpenMayaRender.MRenderUtil.sampleShadingNetwork(nodeFn.name() + ".outColor", instanceCount, False, False, OpenMaya.MFloatMatrix(), None, uValues, vValues, None, None, None, None, None, resultColors, resultTransparencies) self.rampAmplitudeValues = [] self.useDynamicAmplitudeValues = True for i in xrange(resultColors.length()): self.rampAmplitudeValues.append(resultColors[i].length() / math.sqrt(3)) # Ramps base offset
Example #14
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 4 votes |
def compute(self, plug, dataBlock): try: curveDataHandle = dataBlock.inputValue(instanceAlongCurveLocator.inputCurveAttr) curve = curveDataHandle.asNurbsCurveTransformed() updateTranslation = (plug == instanceAlongCurveLocator.outputTranslationAttr.compound) updateRotation = (plug == instanceAlongCurveLocator.outputRotationAttr.compound) updateScale = (plug == instanceAlongCurveLocator.outputScaleAttr.compound) if not curve.isNull(): if updateTranslation or updateRotation or updateScale: curveFn = OpenMaya.MFnNurbsCurve(curve) instanceCount = self.getInstanceCountByMode() distOffset = dataBlock.inputValue(instanceAlongCurveLocator.distOffsetAttr).asFloat() curveLength = curveFn.length() # Curve thresholds curveStart = dataBlock.inputValue(instanceAlongCurveLocator.curveStartAttr).asFloat() * curveLength curveEnd = dataBlock.inputValue(instanceAlongCurveLocator.curveEndAttr).asFloat() * curveLength effectiveCurveLength = min(max(curveEnd - curveStart, 0.001), curveLength) lengthIncrement = self.getIncrementByMode(instanceCount, effectiveCurveLength) # Common data inputTransformPlug = self.getInputTransformPlug() inputTransformFn = self.getInputTransformFn() # Force update of transformation if OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.inputTransformAttr).isConnected(): dataBlock.inputValue(inputTransformPlug).asMatrix() # Manipulator data curveAxisHandleArray = dataBlock.inputArrayValue(instanceAlongCurveLocator.curveAxisHandleAttr.compound) axisHandlesSorted = getSortedCurveAxisArray(self.thisMObject(), curveAxisHandleArray, instanceCount) if updateTranslation: self.updateInstancePositions(curveFn, dataBlock, instanceCount, distOffset, curveStart, curveEnd, effectiveCurveLength, lengthIncrement, inputTransformPlug, inputTransformFn, axisHandlesSorted) if updateRotation: self.updateInstanceRotations(curveFn, dataBlock, instanceCount, distOffset, curveStart, curveEnd, effectiveCurveLength, lengthIncrement, inputTransformPlug, inputTransformFn, axisHandlesSorted) if updateScale: self.updateInstanceScale(curveFn, dataBlock, instanceCount, distOffset, curveStart, curveEnd, effectiveCurveLength, lengthIncrement) except: sys.stderr.write('Failed trying to compute locator. stack trace: \n') sys.stderr.write(traceback.format_exc()) return OpenMaya.kUnknownParameter