def createGenericAttr(longName, shortName): attrFn = OpenMaya.MFnGenericAttribute() attrObj = attrFn.create(longName, shortName) attrFn.addDataType(OpenMaya.MFnData.kAny) # All simple generic numeric types are equivalent, # and we can only add one, so just a kDouble here attrFn.addNumericType(OpenMaya.MFnNumericData.kDouble) # Add vector types for t in kSupportedVectorTypes: attrFn.addNumericType(t) return attrObj
def initialize(): """Set up the attributes and other details of the node.""" # Create the plug-in Attributes nAttr = OpenMaya.MFnNumericAttribute() tAttr = OpenMaya.MFnTypedAttribute() cAttr = OpenMaya.MFnCompoundAttribute() eAttr = OpenMaya.MFnEnumAttribute() gAttr = OpenMaya.MFnGenericAttribute() uAttr = OpenMaya.MFnUnitAttribute() # Input Point X VelocityNode.m_input_point_x = nAttr.create( "inputPointX", "ipx", OpenMaya.MFnNumericData.kDouble, 0.0) nAttr.storable = True nAttr.keyable = True OpenMaya.MPxNode.addAttribute(VelocityNode.m_input_point_x) # Input Point Y VelocityNode.m_input_point_y = nAttr.create( "inputPointY", "ipy", OpenMaya.MFnNumericData.kDouble, 0.0) nAttr.storable = True nAttr.keyable = True OpenMaya.MPxNode.addAttribute(VelocityNode.m_input_point_y) # Input Point Z VelocityNode.m_input_point_z = nAttr.create( "inputPointZ", "ipz", OpenMaya.MFnNumericData.kDouble, 0.0) nAttr.storable = True nAttr.keyable = True OpenMaya.MPxNode.addAttribute(VelocityNode.m_input_point_z) # Input Point (parent of input Point* attributes) VelocityNode.m_input_point = nAttr.create("inputPoint", "ip", VelocityNode.m_input_point_x, VelocityNode.m_input_point_y, VelocityNode.m_input_point_z) nAttr.storable = True nAttr.keyable = True OpenMaya.MPxNode.addAttribute(VelocityNode.m_input_point) # Time VelocityNode.m_time = uAttr.create("time", "time", OpenMaya.MFnUnitAttribute.kTime, 0.0) OpenMaya.MPxNode.addAttribute(VelocityNode.m_time) # Time Interval VelocityNode.m_time_interval = uAttr.create( "timeInterval", "timeInterval", OpenMaya.MFnUnitAttribute.kTime, 1.0) OpenMaya.MPxNode.addAttribute(VelocityNode.m_time_interval) # Frames Per-Second VelocityNode.m_frames_per_second = nAttr.create( "framesPerSecond", "framesPerSecond", OpenMaya.MFnNumericData.kDouble, 24.0) nAttr.storable = True nAttr.keyable = True OpenMaya.MPxNode.addAttribute(VelocityNode.m_frames_per_second) # Text Precision VelocityNode.m_text_precision = nAttr.create( "textPrecision", "textPrecision", OpenMaya.MFnNumericData.kInt, 3) nAttr.storable = True nAttr.keyable = True OpenMaya.MPxNode.addAttribute(VelocityNode.m_text_precision) # Unit Scale VelocityNode.m_unit_scale = eAttr.create("scale", "scale", UNIT_SCALE_DECIMETER_VALUE) for name, value in UNIT_SCALES: eAttr.addField(name, value) OpenMaya.MPxNode.addAttribute(VelocityNode.m_unit_scale) # Display Unit VelocityNode.m_display_unit = eAttr.create( "displayUnit", "displayUnit", DISPLAY_UNIT_KM_PER_HOUR_VALUE) for name, value in DISPLAY_UNITS: eAttr.addField(name, value) OpenMaya.MPxNode.addAttribute(VelocityNode.m_display_unit) # Out Speed VelocityNode.m_out_speed = nAttr.create( "outSpeed", "outSpeed", OpenMaya.MFnNumericData.kDouble, 0.0) nAttr.storable = False nAttr.keyable = False nAttr.readable = True nAttr.writable = False OpenMaya.MPxNode.addAttribute(VelocityNode.m_out_speed) # Out Speed VelocityNode.m_out_speed_raw = nAttr.create( "outSpeedRaw", "outSpeedRaw", OpenMaya.MFnNumericData.kDouble, 0.0) nAttr.storable = False nAttr.keyable = False nAttr.readable = True nAttr.writable = False OpenMaya.MPxNode.addAttribute(VelocityNode.m_out_speed_raw) # Out Speed Text string_data = OpenMaya.MFnStringData() string_obj = string_data.create() VelocityNode.m_out_speed_text = tAttr.create("outSpeedText", "outSpeedText", OpenMaya.MFnData.kString, string_obj) tAttr.storable = False tAttr.keyable = False tAttr.readable = True tAttr.writable = False OpenMaya.MPxNode.addAttribute(VelocityNode.m_out_speed_text) # Out Dummy node # # The attribute is used to trigger this node to compute values. # The value itself is not set, it is only used to help trigger a # compute. VelocityNode.m_out_dummy_float = nAttr.create( "outDummyFloat", "outDummyNodeFloat", OpenMaya.MFnNumericData.kDouble, 0.0) nAttr.storable = False nAttr.keyable = False nAttr.readable = True nAttr.writable = False OpenMaya.MPxNode.addAttribute(VelocityNode.m_out_dummy_float) # Out Dummy String # # The attribute is used to trigger this node to compute values. # The value itself is not set, it is only used to help trigger a # compute. string_data = OpenMaya.MFnStringData() string_obj = string_data.create() VelocityNode.m_out_dummy_string = tAttr.create( "outDummyString", "outDummyString", OpenMaya.MFnData.kString, string_obj) tAttr.storable = False tAttr.keyable = False tAttr.readable = True tAttr.writable = False OpenMaya.MPxNode.addAttribute(VelocityNode.m_out_dummy_string) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_input_point, VelocityNode.m_out_speed) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_input_point, VelocityNode.m_out_speed_raw) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_input_point, VelocityNode.m_out_speed_text) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_input_point, VelocityNode.m_out_dummy_float) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_input_point, VelocityNode.m_out_dummy_string) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time, VelocityNode.m_out_speed) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time, VelocityNode.m_out_speed_raw) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time, VelocityNode.m_out_speed_text) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time, VelocityNode.m_out_dummy_float) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time, VelocityNode.m_out_dummy_string) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time_interval, VelocityNode.m_out_speed) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time_interval, VelocityNode.m_out_speed_raw) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time_interval, VelocityNode.m_out_speed_text) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time_interval, VelocityNode.m_out_dummy_float) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time_interval, VelocityNode.m_out_dummy_string) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_frames_per_second, VelocityNode.m_out_speed) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_frames_per_second, VelocityNode.m_out_speed_raw) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_frames_per_second, VelocityNode.m_out_speed_text) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_frames_per_second, VelocityNode.m_out_dummy_float) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_frames_per_second, VelocityNode.m_out_dummy_string) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_text_precision, VelocityNode.m_out_speed_text) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_text_precision, VelocityNode.m_out_dummy_string) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_unit_scale, VelocityNode.m_out_speed) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_unit_scale, VelocityNode.m_out_speed_raw) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_unit_scale, VelocityNode.m_out_speed_text) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_unit_scale, VelocityNode.m_out_dummy_float) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_unit_scale, VelocityNode.m_out_dummy_string) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_display_unit, VelocityNode.m_out_speed) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_display_unit, VelocityNode.m_out_speed_raw) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_display_unit, VelocityNode.m_out_speed_text) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_display_unit, VelocityNode.m_out_dummy_float) OpenMaya.MPxNode.attributeAffects(VelocityNode.m_display_unit, VelocityNode.m_out_dummy_string) return
def parseTypedAttribute(self, name, shortName, attrInfo): """ Given a JSON subsection describing a typed attribute create the attribute and set all of the provided flags/members for it. name = Attribute long name shortName = Attribute short name attrInfo = JSON object containing the main attribute information """ jsonDebug('parseTypedAttribute(%s)' % name) # First convert the list of accepted types into the equivalent Maya # enum type values acceptedTypeEnums = [] acceptedNumericEnums = [] acceptedPluginTypes = [] hasNumeric = False # Plugin data types are identified by name at runtime, they take # precedence. if JsonKeys.kKeyAcceptedPluginTypes in attrInfo: jsonDebug('...getting accepted plugin types %s' % attrInfo[JsonKeys.kKeyAcceptedPluginTypes]) for pluginId in attrInfo[JsonKeys.kKeyAcceptedPluginTypes]: pId = omAPI.MTypeId() acceptedPluginTypes.append(pId.create(int(pluginId))) if JsonKeys.kKeyAcceptedTypes in attrInfo: if 'any' in attrInfo[JsonKeys.kKeyAcceptedTypes]: acceptedTypeEnums.append(omAPI.MFnData.kAny) else: for typeName in attrInfo[JsonKeys.kKeyAcceptedTypes]: if typeName == 'numeric': hasNumeric = True acceptedTypeEnums.append( JsonKeys.kGenericTypes[typeName]) elif typeName in JsonKeys.kGenericTypes: jsonDebug('...getting accepted generic %s' % JsonKeys.kGenericTypes[typeName]) acceptedTypeEnums.append( JsonKeys.kGenericTypes[typeName]) else: self.reportError('Bad type name specification: "%s"' % str(typeName)) if JsonKeys.kKeyAcceptedNumericTypes in attrInfo: for typeName in attrInfo[JsonKeys.kKeyAcceptedNumericTypes]: if typeName in JsonKeys.kNumericTypes: jsonDebug('...getting accepted numeric %s' % JsonKeys.kNumericTypes[typeName]) acceptedNumericEnums.append( JsonKeys.kNumericTypes[typeName]) else: self.reportError( 'Bad numeric type name specification: "%s"' % str(typeName)) # Numeric types have to be generic, it's just how the attributes are if len(acceptedTypeEnums) == 0 and len( acceptedNumericEnums) == 0 and len(acceptedPluginTypes) == 0: self.reportError('Need at least one accepted type') # Only one data type means it can be an MFnTypedAttribute, except for # numeric type which for some reason is not supported in the API elif len(acceptedTypeEnums) == 1 and len( acceptedNumericEnums) == 0 and len( acceptedPluginTypes) == 0 and not hasNumeric: jsonDebug('--- Accepts only one type : %s' % acceptedTypeEnums[0]) tAttr = omAPI.MFnTypedAttribute() attr = tAttr.create(name, shortName, acceptedTypeEnums[0]) jsonDebug('--- created') # One plugin type has a special MFnTypedAttribute constructor elif len(acceptedTypeEnums) == 0 and len( acceptedNumericEnums) == 0 and len(acceptedPluginTypes) == 1: jsonDebug('--- Accepts only one plugin : %s' % acceptedPluginTypes[0]) tAttr = omAPI.MFnTypedAttribute() attr = tAttr.create(name, shortName, acceptedPluginTypes[0]) jsonDebug('--- created') # Every other combination forces a generic attribute else: jsonDebug('--- Accepts multiple or base numeric types') tAttr = omAPI.MFnGenericAttribute() attr = tAttr.create(name, shortName) for typeEnum in acceptedTypeEnums: jsonDebug('--> add data type %s' % typeEnum) tAttr.addDataType(typeEnum) for numericEnum in acceptedNumericEnums: jsonDebug('--> add numeric type %s' % numericEnum) tAttr.addNumericType(numericEnum) for pluginId in acceptedPluginTypes: jsonDebug('--> add plugin type %s' % pluginId) tAttr.addTypeId(pluginId) jsonDebug('--- created') return attr
def initialize(): numericAttr = om.MFnNumericAttribute() compoundAttr = om.MFnCompoundAttribute() genericAttr = om.MFnGenericAttribute() matrixAttr = om.MFnMatrixAttribute() # output prKeepOut.output = numericAttr.createPoint('output', 'output') numericAttr.array = True numericAttr.usesArrayDataBuilder = True numericAttr.writable = False prKeepOut.addAttribute(prKeepOut.output) # input prKeepOut.enabled = numericAttr.create('enabled', 'enabled', om.MFnNumericData.kBoolean, True) numericAttr.keyable = True prKeepOut.addAttribute(prKeepOut.enabled) prKeepOut.attributeAffects(prKeepOut.enabled, prKeepOut.output) prKeepOut.offset = numericAttr.create('offset', 'offset', om.MFnNumericData.kFloat, 0.0) numericAttr.keyable = True prKeepOut.addAttribute(prKeepOut.offset) prKeepOut.attributeAffects(prKeepOut.offset, prKeepOut.output) prKeepOut.offsetExtendsPosition = numericAttr.create( 'offsetExtendsPosition', 'offsetExtendsPosition', om.MFnNumericData.kBoolean, True) numericAttr.keyable = True prKeepOut.addAttribute(prKeepOut.offsetExtendsPosition) prKeepOut.attributeAffects(prKeepOut.offsetExtendsPosition, prKeepOut.output) prKeepOut.inputGeometry = genericAttr.create('inputGeometry', 'inputGeometry') genericAttr.addDataType(om.MFnMeshData.kMesh) genericAttr.addDataType(om.MFnNurbsSurfaceData.kNurbsSurface) genericAttr.array = True prKeepOut.addAttribute(prKeepOut.inputGeometry) prKeepOut.attributeAffects(prKeepOut.inputGeometry, prKeepOut.output) prKeepOut.enabledExtra = numericAttr.create('enabledExtra', 'enabledExtra', om.MFnNumericData.kBoolean, True) numericAttr.keyable = True prKeepOut.offsetExtra = numericAttr.create('offsetExtra', 'offsetExtra', om.MFnNumericData.kFloat, 0.0) numericAttr.keyable = True prKeepOut.position1 = numericAttr.createPoint('position1', 'position1') numericAttr.keyable = True prKeepOut.position2 = numericAttr.createPoint('position2', 'position2') numericAttr.keyable = True prKeepOut.parentInverseMatrix = matrixAttr.create( 'parentInverseMatrix', 'parentInverseMatrix', type=matrixAttr.kFloat) matrixAttr.keyable = True prKeepOut.input = compoundAttr.create('input', 'input') compoundAttr.addChild(prKeepOut.enabledExtra) compoundAttr.addChild(prKeepOut.offsetExtra) compoundAttr.addChild(prKeepOut.position1) compoundAttr.addChild(prKeepOut.position2) compoundAttr.addChild(prKeepOut.parentInverseMatrix) compoundAttr.array = True prKeepOut.addAttribute(prKeepOut.input) prKeepOut.attributeAffects(prKeepOut.enabledExtra, prKeepOut.output) prKeepOut.attributeAffects(prKeepOut.offsetExtra, prKeepOut.output) prKeepOut.attributeAffects(prKeepOut.position1, prKeepOut.output) prKeepOut.attributeAffects(prKeepOut.position2, prKeepOut.output) prKeepOut.attributeAffects(prKeepOut.parentInverseMatrix, prKeepOut.output)
def initialize(cls): print('initialize') nData = ompy.MFnNumericData() cData = ompy.MFnNurbsCurveData() mData = ompy.MFnMeshData() sData = ompy.MFnStringData() nAttr = ompy.MFnNumericAttribute() eAttr = ompy.MFnEnumAttribute() mAttr = ompy.MFnMatrixAttribute() gAttr = ompy.MFnGenericAttribute() tAttr = ompy.MFnTypedAttribute() sAttr = ompy.MFnTypedAttribute() cls.inAttrs = [] # OUT ATTR cls.inAttrs.append(mAttr.create('camMatrix', 'camMatrix', nData.kFloat)) drawPlaneMode_choices = ['none', 'foreground', 'background'] cls.inAttrs.append(eAttr.create('drawPlaneMode', 'drawPlaneMode', 0)) for i in range(0, len(drawPlaneMode_choices)): eAttr.addField(drawPlaneMode_choices[i], i) eAttr.channelBox = True cls.inAttrs.append(nAttr.create('shapes', 'shapes', nData.kInt, 0)) nAttr.array = True #nAttr.dynamic = True nAttr.usesArrayDataBuilder = True cls.inAttrs.append(nAttr.createPoint('coords', 'coords')) nAttr.array = True #nAttr.dynamic = True nAttr.usesArrayDataBuilder = True cls.inAttrs.append( nAttr.createPoint('screenSpaceOffsets', 'screenSpaceOffsets')) nAttr.array = True #nAttr.dynamic = True nAttr.usesArrayDataBuilder = True cls.inAttrs.append(nAttr.create('sizes', 'sizes', nData.kFloat, 1.0)) nAttr.array = True #nAttr.dynamic = True nAttr.usesArrayDataBuilder = True cls.inAttrs.append( nAttr.create('thicknesses', 'thicknesses', nData.kFloat, 1.0)) nAttr.array = True #nAttr.dynamic = True nAttr.usesArrayDataBuilder = True cls.inAttrs.append(nAttr.createPoint('colors', 'colors')) nAttr.array = True #nAttr.dynamic = True nAttr.usesArrayDataBuilder = True cls.inAttrs.append(tAttr.create('names', 'names', sData.kString)) tAttr.array = True #nAttr.dynamic = True tAttr.usesArrayDataBuilder = True ''' cls.attrOutTrig = nAttr.create( 'outTrig', 'outTrig' , nData.kFloat ) nAttr.setReadable(True) nAttr.setStorable(True) nAttr.setConnectable(True) ''' for i in range(0, len(cls.inAttrs)): cls.addAttribute(cls.inAttrs[i]) #INFLUENCE '''