Patch:

I believe I've sussed the problem, the section:

***********************************************************

# initializer
def nodeInitializer():
nAttr = OpenMaya.MFnNumericAttribute()

# Setup the input attributes

***********************************************************

...requires a full name. I replaced the naming convention of the added  
lines to utilise an underscore to separate the two strings and that seemed  
to fix the issue. The node created without error and the new inputs where  
listed.

Regards,
Russ.






On 28 Aug 2009 00:50, "[email protected]"  
<[email protected]> wrote:
> Hello,



> I'm having a lot of trouble trying to create my own custom plugin. I'm

> modifying the built-in circleNode.py to calculate a position that has

> a scaled offset.

> The error message maya is returning and the edited code for the

> circleNode is as follows:

> (I apologise for the length of the thread).





> Error message:



> // Error: Cannot create UI object: attrFieldSliderGrp5 //

> // Error: TPSdatabase::createAddControlUI: could not create control

> for attribute loc x //

> // Error: Cannot create UI object: attrFieldSliderGrp5 //

> // Error: TPSdatabase::createAddControlUI: could not create control

> for attribute loc y //

> // Error: Cannot create UI object: attrFieldSliderGrp5 //

> // Error: TPSdatabase::createAddControlUI: could not create control

> for attribute loc z //

> // Error: Cannot create UI object: attrFieldSliderGrp5 //

> // Error: TPSdatabase::createAddControlUI: could not create control

> for attribute Pacc FPS //

> // Error: Cannot create UI object: attrFieldSliderGrp5 //

> // Error: TPSdatabase::createAddControlUI: could not create control

> for attribute loc no //

> // Error: Cannot create UI object: attrFieldSliderGrp5 //

> // Error: TPSdatabase::createAddControlUI: could not create control

> for attribute init angle //

> // Error: Cannot create UI object: attrFieldSliderGrp5 //

> // Error: TPSdatabase::createAddControlUI: could not create control

> for attribute scale factor //





> The edited code for the circle node is as follows:



> *************************************************************************************************************************************

> *************************************************************************************************************************************

> *************************************************************************************************************************************



> import math, sys



> import maya.OpenMaya as OpenMaya

> import maya.OpenMayaMPx as OpenMayaMPx



> kPluginNodeTypeName = "paccCircle" # ---- changed ---- name

> kPluginNodeId = OpenMaya.MTypeId(0x87777) # ---- changed ---- memory

> location





> # Node definition

> class circle(OpenMayaMPx.MPxNode):

> # class variables

> aInput = OpenMaya.MObject()

> aScale = OpenMaya.MObject()

> aFrames = OpenMaya.MObject()

> aLocx = OpenMaya.MObject() # ---- added

> aLocy = OpenMaya.MObject() # ---- added

> aLocz = OpenMaya.MObject() # ---- added

> aFPS = OpenMaya.MObject() # ---- added

> aLocNo = OpenMaya.MObject() # ---- added

> aInitialAngle = OpenMaya.MObject() # ---- added

> aSfactor = OpenMaya.MObject() # ---- added

> aSOutput = OpenMaya.MObject()

> aCOutput = OpenMaya.MObject()





> def __init__(self):

> OpenMayaMPx.MPxNode.__init__(self)





> def compute(self, plug, data):

> # Check that the requested recompute is one of the output values

> if (plug == circle.aSOutput or plug == circle.aCOutput):

> # Read the input values

> inputData = data.inputValue(circle.aInput) # ---- currentFrame

> scaleData = data.inputValue(circle.aScale) # ---- radius

> framesData = data.inputValue(circle.aFrames)

> circlelocx = data.inputValue(circle.aLocx) # ---- added - circle

> centre Xcord

> circlelocy = data.inputValue(circle.aLocy) # ---- added - circle

> centre Ycord

> circlelocz = data.inputValue(circle.aLocz) # ---- added - circle

> centre Zcord

> locfps = data.inputValue(circle.aFPS) # ---- added - fps value of

> the first circle

> locno = data.inputValue(circle.aLocNo) # ---- added - circle

> number, used for calculating the factor.

> initangle = data.inputValue(circle.aInitialAngle) # ---- added -

> initial angle used to calculate the start position.

> sfactor = data.inputValue(circle.aSfactor) # ---- added - scale

> factor of the circles if there are more than 1.



> # Compute the output values

> currentFrame = inputData.asFloat()

> radius = scaleData.asFloat() # ---- changed naming

> framesPerCircle = framesData.asFloat()



> xval = circlelocx.asFloat() # ---- added

> yval = circlelocy.asFloat() # ---- added

> zval = circlelocz.asFloat() # ---- added

> fpsval = locfps.asFloat() # ---- added

> locnoval = locno.asFloat() # ---- added

> initangleval = initangle.asFloat() # ---- added

> sfactorval = sfactor.asFloat() # ---- added



> # ---- calculate the fps for the circle

> cfps = (((fpsval - (fpsval / locnoval)) * (1 - sfactorval)) +

> (fpsval / locnoval)) # ---- added



> # ---- calculate the angle

> angle = 6.2831853 * (currentFrame/cfps) # ---- changed fps varibles

> over

> angle2 = angle + initangleval



> # ---- calculate the (x, z) cords.

> sinResult = math.sin(angle2) * radius # ---- tweeked

> cosResult = math.cos(angle2) * radius # ---- tweeked



> # ---- amend the cords with the circle centre cord info.

> sinNum = sinResult + xval # ---- added

> cosNum = cosResult + zval # ---- added



> # Store them on the output plugs

> sinHandle = data.outputValue(circle.aSOutput)

> cosHandle = data.outputValue(circle.aCOutput)

> sinHandle.setFloat(sinNum) # ---- tweeked

> cosHandle.setFloat(cosNum) # ---- tweeked

> data.setClean(plug)

> else:

> return OpenMaya.MStatus.kUnknownParameter



> return OpenMaya.MStatus.kSuccess





> # creator

> def nodeCreator():

> return OpenMayaMPx.asMPxPtr( circle() )





> # initializer

> def nodeInitializer():

> nAttr = OpenMaya.MFnNumericAttribute()



> # Setup the input attributes

> circle.aInput = nAttr.create("input", "in",

> OpenMaya.MFnNumericData.kFloat, 0.0)

> nAttr.setStorable(True)



> circle.aScale = nAttr.create("scale", "sc",

> OpenMaya.MFnNumericData.kFloat, 1.0)

> nAttr.setStorable(True)



> circle.aFrames = nAttr.create("frames", "fr",

> OpenMaya.MFnNumericData.kFloat, 25.0)

> nAttr.setStorable(True)



> circle.aLocx = nAttr.create("loc x", "x",

> OpenMaya.MFnNumericData.kFloat, 0.0) # ---- added

> nAttr.setStorable(True)



> circle.aLocy = nAttr.create("loc y", "y",

> OpenMaya.MFnNumericData.kFloat, 0.0) # ---- added

> nAttr.setStorable(True)



> circle.aLocz = nAttr.create("loc z", "z",

> OpenMaya.MFnNumericData.kFloat, 0.0) # ---- added

> nAttr.setStorable(True)



> circle.aFPS = nAttr.create("Pacc FPS", "fps",

> OpenMaya.MFnNumericData.kFloat, 25.0) # ---- added

> nAttr.setStorable(True)



> circle.aLocNo = nAttr.create("loc no", "lno",

> OpenMaya.MFnNumericData.kFloat, 0.0) # ---- added

> nAttr.setStorable(True)



> circle.aInitialAngle = nAttr.create("init angle", "inita",

> OpenMaya.MFnNumericData.kFloat, 0.0) # ---- added

> nAttr.setStorable(True)



> circle.aSfactor = nAttr.create("scale factor", "sf",

> OpenMaya.MFnNumericData.kFloat, 25.0) # ---- added

> nAttr.setStorable(True)





> # Setup the output attributes

> circle.aSOutput = nAttr.create("sineOutput", "so",

> OpenMaya.MFnNumericData.kFloat, 0.0)

> nAttr.setWritable(False)

> nAttr.setStorable(False)



> circle.aCOutput = nAttr.create("cosineOutput", "co",

> OpenMaya.MFnNumericData.kFloat, 0.0,)

> nAttr.setWritable(False)

> nAttr.setStorable(False)



> # Add the attributes to the node

> circle.addAttribute(circle.aInput)

> circle.addAttribute(circle.aScale)

> circle.addAttribute(circle.aFrames)

> circle.addAttribute(circle.aLocx) # ---- added

> circle.addAttribute(circle.aLocy) # ---- added

> circle.addAttribute(circle.aLocz) # ---- added

> circle.addAttribute(circle.aFPS) # ---- added

> circle.addAttribute(circle.aLocNo) # ---- added

> circle.addAttribute(circle.aInitialAngle) # ---- added

> circle.addAttribute(circle.aSfactor) # ---- added

> circle.addAttribute(circle.aSOutput)

> circle.addAttribute(circle.aCOutput)



> # Set the attribute dependencies

> circle.attributeAffects(circle.aInput, circle.aSOutput)

> circle.attributeAffects(circle.aInput, circle.aCOutput)

> circle.attributeAffects(circle.aScale, circle.aSOutput)

> circle.attributeAffects(circle.aScale, circle.aCOutput)

> circle.attributeAffects(circle.aFrames, circle.aSOutput)

> circle.attributeAffects(circle.aFrames, circle.aCOutput)

> circle.attributeAffects(circle.aLocx, circle.aSOutput) # ---- added

> circle.attributeAffects(circle.aLocx, circle.aCOutput) # ---- added

> circle.attributeAffects(circle.aLocy, circle.aSOutput) # ---- added

> circle.attributeAffects(circle.aLocy, circle.aCOutput) # ---- added

> circle.attributeAffects(circle.aLocz, circle.aSOutput) # ---- added

> circle.attributeAffects(circle.aLocz, circle.aCOutput) # ---- added

> circle.attributeAffects(circle.aFPS, circle.aSOutput) # ---- added

> circle.attributeAffects(circle.aFPS, circle.aCOutput) # ---- added

> circle.attributeAffects(circle.aLocNo, circle.aSOutput) # ---- added

> circle.attributeAffects(circle.aLocNo, circle.aCOutput) # ---- added

> circle.attributeAffects(circle.aInitialAngle, circle.aSOutput) # ----

> added

> circle.attributeAffects(circle.aInitialAngle, circle.aCOutput) # ----

> added

> circle.attributeAffects(circle.aSfactor, circle.aSOutput) # ----

> added

> circle.attributeAffects(circle.aSfactor, circle.aCOutput) # ----

> added





> # initialize the script plug-in

> def initializePlugin(mobject):

> mplugin = OpenMayaMPx.MFnPlugin(mobject, "Autodesk", "1.0", "Any")

> try:

> mplugin.registerNode( kPluginNodeTypeName, kPluginNodeId,

> nodeCreator, nodeInitializer )

> except:

> sys.stderr.write( "Failed to register node: %s" %

> kPluginNodeTypeName )

> raise





> # uninitialize the script plug-in

> def uninitializePlugin(mobject):

> mplugin = OpenMayaMPx.MFnPlugin(mobject)

> try:

> mplugin.deregisterNode( kPluginNodeId )

> except:

> sys.stderr.write( "Failed to deregister node: %s" %

> kPluginNodeTypeName )

> raise



> *************************************************************************************************************************************

> *************************************************************************************************************************************

> *************************************************************************************************************************************




--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to