예제 #1
0
	def test( self ) :

		n = nuke.nodes.RadialDistort()
		k = n.knob( "scale" )

		self.assertEqual( IECoreNuke.getKnobValue( k ), imath.V3f( 1 ) )
		self.assertEqual( IECoreNuke.getKnobValue( k, resultType=imath.V3d ), imath.V3d( 1 ) )
예제 #2
0
	def testIeCoreFileSequence( self ) :

		self.assertEqual( IECoreNuke.ieCoreFileSequence( "/tmp/test.dpx" ), "/tmp/test.dpx" )
		self.assertEqual( IECoreNuke.ieCoreFileSequence( "/tmp/test.%d.dpx" ), "/tmp/test.#.dpx" )
		self.assertEqual( IECoreNuke.ieCoreFileSequence( "/tmp/test.%02d.dpx" ), "/tmp/test.##.dpx" )
		self.assertEqual( IECoreNuke.ieCoreFileSequence( "/tmp/test_%09d_test.dpx" ), "/tmp/test_#########_test.dpx" )
		self.assertRaises( RuntimeError, IECoreNuke.ieCoreFileSequence, "/tmp/test.%2d.dpx" )
예제 #3
0
	def testUndo( self ) :

		# check our custom knob undoes in the same way as
		# standard knobs

		n = nuke.createNode( "ieObject" )
		n2 = nuke.createNode( "Blur" )

		self.assertEqual( n.knob( "object" ).getValue(), None )
		self.assertEqual( n2.knob( "size" ).getValue(), 0 )

		self.assertEqual( nuke.Undo.disabled(), True )

		with IECoreNuke.UndoEnabled() :

			self.assertEqual( nuke.Undo.disabled(), False )

			with IECoreNuke.UndoBlock() :

				n.knob( "object" ).setValue( IECore.IntData( 10 ) )
				self.assertEqual( n.knob( "object" ).getValue(), IECore.IntData( 10 ) )

				n2.knob( "size" ).setValue( 10 )
				self.assertEqual( n2.knob( "size" ).getValue(), 10 )

		self.assertEqual( nuke.Undo.disabled(), True )

		self.assertEqual( n.knob( "object" ).getValue(), IECore.IntData( 10 ) )
		self.assertEqual( n2.knob( "size" ).getValue(), 10 )

		nuke.undo()

		self.assertEqual( n2.knob( "size" ).getValue(), 0 )
		self.assertEqual( n.knob( "object" ).getValue(), None )
예제 #4
0
	def test( self ) :

		n = nuke.nodes.Axis()

		f = IECoreNuke.FnAxis( n )
		self.assertEqual( f.getLocalMatrix(), imath.M44f() )

		IECoreNuke.setKnobValue( n.knob( "translate" ), imath.V3f( 1, 2, 3 ) )
		self.assertEqual( f.getLocalMatrix(), imath.M44f().translate( imath.V3f( 1, 2, 3 ) ) )
예제 #5
0
    def test(self):

        n = nuke.nodes.Axis()

        f = IECoreNuke.FnAxis(n)
        self.assertEqual(f.getLocalMatrix(), imath.M44f())

        IECoreNuke.setKnobValue(n.knob("translate"), imath.V3f(1, 2, 3))
        self.assertEqual(f.getLocalMatrix(),
                         imath.M44f().translate(imath.V3f(1, 2, 3)))
예제 #6
0
    def testNukeFileSequence(self):

        self.assertEqual(IECoreNuke.nukeFileSequence("/tmp/test.dpx"),
                         "/tmp/test.dpx")
        self.assertEqual(IECoreNuke.nukeFileSequence("/tmp/test.#.dpx"),
                         "/tmp/test.%d.dpx")
        self.assertEqual(IECoreNuke.nukeFileSequence("/tmp/test.##.dpx"),
                         "/tmp/test.%02d.dpx")
        self.assertEqual(
            IECoreNuke.nukeFileSequence("/tmp/test_#########_test.dpx"),
            "/tmp/test_%09d_test.dpx")
예제 #7
0
    def testIeCoreFileSequence(self):

        self.assertEqual(IECoreNuke.ieCoreFileSequence("/tmp/test.dpx"),
                         "/tmp/test.dpx")
        self.assertEqual(IECoreNuke.ieCoreFileSequence("/tmp/test.%d.dpx"),
                         "/tmp/test.#.dpx")
        self.assertEqual(IECoreNuke.ieCoreFileSequence("/tmp/test.%02d.dpx"),
                         "/tmp/test.##.dpx")
        self.assertEqual(
            IECoreNuke.ieCoreFileSequence("/tmp/test_%09d_test.dpx"),
            "/tmp/test_#########_test.dpx")
        self.assertRaises(RuntimeError, IECoreNuke.ieCoreFileSequence,
                          "/tmp/test.%2d.dpx")
예제 #8
0
    def testDefaultExpression(self):

        # create opholder and check the default expression we asked for works

        fnOH = IECoreNuke.FnOpHolder.create("op", "add", 1)
        self.assertEqual(fnOH.node().knob("parm_a").toScript(),
                         '{"frame * 2"}')
        self.failUnless(fnOH.node().knob("parm_a").isAnimated())

        self.assertEqual(nuke.frame(), 1)
        self.assertEqual(fnOH.node().knob("parm_a").getValue(), 2)

        # remove the expression, cut and paste the node, and make sure
        # it doesn't reappear

        fnOH.node().knob("parm_a").clearAnimated()
        self.failIf(fnOH.node().knob("parm_a").isAnimated())

        nuke.nodeCopy("test/IECoreNuke/parameterisedHolder.nk")

        nuke.scriptClear()

        n = nuke.nodePaste("test/IECoreNuke/parameterisedHolder.nk")

        fnOH = IECoreNuke.FnOpHolder(n)
        self.assertEqual(fnOH.node().knob("parm_a").toScript(), "2")
예제 #9
0
	def testKnobCreation( self ) :
		knobHolder = KnobConvertersTest.KnobHolder()
		IECoreNuke.createKnobsFromParameter( knobHolder, KnobConvertersTest.__parameters() )
		knobs = knobHolder.knobs()
		self.assertEqual( knobs["parm_A"].getValue(), 1 )
		self.assertEqual( knobs["parm_B_C"].getValue(), 2.0 )
		self.assertEqual( knobs["parm_B_D"].getValue(), 3.0 )
		self.assertEqual( knobs["parm_E"].getText(), "4" )
		self.assertEqual( knobs["parm_F_G"].getText(), "5.0 6.0 7.0" )
		self.assertEqual( knobs["parm_F_H"].getText(), "8" )
		self.assertEqual( knobs["parm_F_I"].getText(), "" )
		self.assertEqual( knobs["parm_J"].getText(), "10\n11\n12" )
		self.assertEqual( knobs["parm_K"].getText(), "/tmp/test.dpx" )
		self.assertEqual( knobs["parm_L"].getText(), "/tmp" )
		self.assertEqual( knobs["parm_M"].getText(), "/tmp/test.%04d.dpx" )
		self.assertEqual( knobs["parm_N"].getValue(), True )
		self.assertEqual( knobs["parm_O"].value(), "preset0" )
예제 #10
0
 def testKnobCreation(self):
     knobHolder = KnobConvertersTest.KnobHolder()
     IECoreNuke.createKnobsFromParameter(knobHolder,
                                         KnobConvertersTest.__parameters())
     knobs = knobHolder.knobs()
     self.assertEqual(knobs["parm_A"].getValue(), 1)
     self.assertEqual(knobs["parm_B_C"].getValue(), 2.0)
     self.assertEqual(knobs["parm_B_D"].getValue(), 3.0)
     self.assertEqual(knobs["parm_E"].getText(), "4")
     self.assertEqual(knobs["parm_F_G"].getText(), "5.0 6.0 7.0")
     self.assertEqual(knobs["parm_F_H"].getText(), "8")
     self.assertEqual(knobs["parm_F_I"].getText(), "")
     self.assertEqual(knobs["parm_J"].getText(), "10\n11\n12")
     self.assertEqual(knobs["parm_K"].getText(), "/tmp/test.dpx")
     self.assertEqual(knobs["parm_L"].getText(), "/tmp")
     self.assertEqual(knobs["parm_M"].getText(), "/tmp/test.%04d.dpx")
     self.assertEqual(knobs["parm_N"].getValue(), True)
     self.assertEqual(knobs["parm_O"].value(), "preset0")
예제 #11
0
	def testSettingKnobValues( self ) :

		params = KnobConvertersTest.__parameters()
		knobHolder = KnobConvertersTest.KnobHolder()
		IECoreNuke.createKnobsFromParameter( knobHolder, params )
		# modify parameters
		params[ 'A' ] = 2
		params[ 'F' ][ 'G' ] = IECore.FloatVectorData()
		params[ 'F' ][ 'I' ] = IECore.DoubleVectorData( [ 9 ] )
		params[ 'M' ] = "/tmp/anotherTest.%d.dpx"
		params[ 'N' ] = False
		params[ 'O' ] = IECore.TransformationMatrixfData(IECore.TransformationMatrixf(imath.V3f(1), imath.Eulerf(), imath.V3f(3)))
		IECoreNuke.setKnobsFromParameter( knobHolder, params )
		knobs = knobHolder.knobs()
		self.assertEqual( knobs["parm_A"].getValue(), 2 )
		self.assertEqual( knobs["parm_F_G"].getText(), "" )
		self.assertEqual( knobs["parm_F_I"].getText(), "9.0" )
		self.assertEqual( knobs["parm_M"].getText(), "/tmp/anotherTest.%d.dpx" )
		self.assertEqual( knobs["parm_N"].getValue(), False )
		self.assertEqual( knobs["parm_O"].value(), "preset2" )
예제 #12
0
    def testSettingKnobValues(self):

        params = KnobConvertersTest.__parameters()
        knobHolder = KnobConvertersTest.KnobHolder()
        IECoreNuke.createKnobsFromParameter(knobHolder, params)
        # modify parameters
        params['A'] = 2
        params['F']['G'] = IECore.FloatVectorData()
        params['F']['I'] = IECore.DoubleVectorData([9])
        params['M'] = "/tmp/anotherTest.%d.dpx"
        params['N'] = False
        params['O'] = IECore.TransformationMatrixfData(
            IECore.TransformationMatrixf(IECore.V3f(1), IECore.Eulerf(),
                                         IECore.V3f(3)))
        IECoreNuke.setKnobsFromParameter(knobHolder, params)
        knobs = knobHolder.knobs()
        self.assertEqual(knobs["parm_A"].getValue(), 2)
        self.assertEqual(knobs["parm_F_G"].getText(), "")
        self.assertEqual(knobs["parm_F_I"].getText(), "9.0")
        self.assertEqual(knobs["parm_M"].getText(), "/tmp/anotherTest.%d.dpx")
        self.assertEqual(knobs["parm_N"].getValue(), False)
        self.assertEqual(knobs["parm_O"].value(), "preset2")
예제 #13
0
    def __checkParameterKnobs(self,
                              parameter,
                              node,
                              knobName=None,
                              parameterPath=None,
                              ignore=set()):

        if knobName is None:
            knobName = "parm"

        if parameterPath in ignore:
            return

        if isinstance(parameter, IECore.CompoundParameter):
            for k in parameter.keys():
                childKnobName = knobName + "_" + parameter[k].name
                if not parameterPath:
                    childParameterPath = k
                else:
                    childParameterPath = parameterPath + "." + k
                self.__checkParameterKnobs(parameter[k], node, childKnobName,
                                           childParameterPath, ignore)
        else:

            knob = node.knob(knobName)
            self.failUnless(knob is not None)

            if isinstance(knob, nuke.Enumeration_Knob):
                self.assertEqual(knob.value(),
                                 parameter.getCurrentPresetName())
            else:

                knobValue = None
                try:
                    knobValue = IECoreNuke.getKnobValue(knob)
                    if isinstance(parameter, IECore.V2dParameter):
                        # getKnobValue defaults to V2f
                        knobValue = IECore.V2d(knobValue[0], knobValue[1])
                    elif isinstance(parameter, IECore.V3dParameter):
                        knobValue = IECore.V3d(knobValue[0], knobValue[1],
                                               knobValue[2])
                except:
                    # not all knob types have accessors yet. some of the numeric
                    # knobs don't have them because nuke has bugs and returns those
                    # knobs as the wrong type. try to get the value another way.
                    knobValue = knob.getValue()

                self.assertEqual(parameter.getValue().value, knobValue)
예제 #14
0
    def testCopyPaste(self):

        fnPH = IECoreNuke.FnProceduralHolder.create("procedural", "read", 1)

        nuke.nodeCopy("test/IECoreNuke/parameterisedHolder.nk")

        nuke.scriptClear()

        n = nuke.nodePaste("test/IECoreNuke/parameterisedHolder.nk")

        fnPH = IECoreNuke.FnProceduralHolder(n)

        p = fnPH.getParameterised()

        self.assertEqual(p[1], "read")
        self.failUnless(isinstance(p[2], int))
        self.assertEqual(p[2], 1)
        self.assertEqual(p[3], "IECORE_PROCEDURAL_PATHS")
예제 #15
0
    def testGettingKnobValues(self):

        params = KnobConvertersTest.__parameters()
        knobHolder = KnobConvertersTest.KnobHolder()
        IECoreNuke.createKnobsFromParameter(knobHolder, params)
        knobs = knobHolder.knobs()
        IECoreNuke.setParameterFromKnobs(knobHolder, params)
        self.assertEqual(params["A"].getNumericValue(), 1)
        self.assertEqual(params["B"]["C"].getNumericValue(), 2.0)
        self.assertEqual(params["B"]["D"].getNumericValue(), 3.0)

        knobs["parm_A"].setValue(10)
        knobs["parm_B_C"].setValue(20.0)
        knobs["parm_B_D"].setValue(30.0)
        knobs["parm_E"].setValue("40")
        knobs["parm_F_G"].setValue("50 60 70")
        knobs["parm_F_H"].setValue("80")
        knobs["parm_F_I"].setValue("90")
        knobs["parm_J"].setValue("100\n110\n120")
        knobs["parm_K"].setValue("/tmp2/test.dpx")
        knobs["parm_L"].setValue("/tmp2")
        knobs["parm_M"].setValue("/tmp2/test.%02d.dpx")
        knobs["parm_N"].setValue(False)
        knobs["parm_O"].setValue("preset3")
        IECoreNuke.setParameterFromKnobs(knobHolder, params)

        self.assertEqual(params["A"].getNumericValue(), 10)
        self.assertEqual(params["B"]["C"].getNumericValue(), 20.0)
        self.assertEqual(params["B"]["D"].getNumericValue(), 30.0)
        self.assertEqual(params["E"].getTypedValue(), "40")
        self.assertEqual(params["F"]["G"].getValue(),
                         IECore.FloatVectorData([50, 60, 70]))
        self.assertEqual(params["F"]["H"].getValue(),
                         IECore.IntVectorData([80]))
        self.assertEqual(params["F"]["I"].getValue(),
                         IECore.DoubleVectorData([90]))
        self.assertEqual(params["J"].getValue(),
                         IECore.StringVectorData(["100", "110", "120"]))
        self.assertEqual(params["K"].getTypedValue(), "/tmp2/test.dpx")
        self.assertEqual(params["L"].getTypedValue(), "/tmp2")
        self.assertEqual(params["M"].getTypedValue(), "/tmp2/test.##.dpx")
        self.assertEqual(params["N"].getTypedValue(), False)
        self.assertEqual(
            params["O"].getValue(),
            IECore.TransformationMatrixfData(
                IECore.TransformationMatrixf(IECore.V3f(1), IECore.Eulerf(),
                                             IECore.V3f(4))))
        # raises exception when trying to convert an invalid file sequence syntax
        knobs["parm_M"].setValue("/tmp2/test.%2d.dpx")
        self.assertRaises(RuntimeError, IECoreNuke.setParameterFromKnobs,
                          knobHolder, params)
예제 #16
0
    def testModifyParametersAndUndo(self):

        fnOH = IECoreNuke.FnOpHolder.create("mult", "maths/multiply", 2)

        self.assertEqual(fnOH.node().knob("parm_a").getValue(), 1)
        self.assertEqual(fnOH.node().knob("parm_b").getValue(), 2)

        with IECoreNuke.UndoEnabled():

            with fnOH.parameterModificationContext() as parameters:

                parameters["a"].setNumericValue(10)
                parameters["b"].setNumericValue(20)

            self.assertEqual(fnOH.node().knob("parm_a").getValue(), 10)
            self.assertEqual(fnOH.node().knob("parm_b").getValue(), 20)

        nuke.undo()

        self.assertEqual(fnOH.node().knob("parm_a").getValue(), 1)
        self.assertEqual(fnOH.node().knob("parm_b").getValue(), 2)
예제 #17
0
	def __checkParameterKnobs( self, parameter, node, knobName=None, parameterPath=None, ignore=set() ) :

		if knobName is None :
			knobName = "parm"

		if parameterPath in ignore :
			return

		if isinstance( parameter, IECore.CompoundParameter ) :
			for k in parameter.keys() :
				childKnobName = knobName + "_" + parameter[k].name
				if not parameterPath :
					childParameterPath = k
				else :
					childParameterPath = parameterPath + "." + k
				self.__checkParameterKnobs( parameter[k], node, childKnobName, childParameterPath, ignore )
		else :

			knob = node.knob( knobName )
			self.failUnless( knob is not None )

			if isinstance( knob, nuke.Enumeration_Knob ) :
				self.assertEqual( knob.value(), parameter.getCurrentPresetName() )
			else :

				knobValue = None
				try :
					knobValue = IECoreNuke.getKnobValue( knob )
					if isinstance( parameter, IECore.V2dParameter ) :
						# getKnobValue defaults to V2f
						knobValue = imath.V2d( knobValue[0], knobValue[1] )
					elif isinstance( parameter, IECore.V3dParameter ) :
						knobValue = imath.V3d( knobValue[0], knobValue[1], knobValue[2] )
				except :
					# not all knob types have accessors yet. some of the numeric
					# knobs don't have them because nuke has bugs and returns those
					# knobs as the wrong type. try to get the value another way.
					knobValue = knob.getValue()

				self.assertEqual( parameter.getValue().value, knobValue )
예제 #18
0
    def testGettingKnobValues(self):

        params = KnobConvertersTest.__parameters()
        knobHolder = KnobConvertersTest.KnobHolder()
        IECoreNuke.createKnobsFromParameter(knobHolder, params)
        knobs = knobHolder.knobs()
        IECoreNuke.setParameterFromKnobs(knobHolder, params)
        self.assertEqual(params["A"].getNumericValue(), 1)
        self.assertEqual(params["B"]["C"].getNumericValue(), 2.0)
        self.assertEqual(params["B"]["D"].getNumericValue(), 3.0)

        knobs["parm_A"].setValue(10)
        knobs["parm_B_C"].setValue(20.0)
        knobs["parm_B_D"].setValue(30.0)
        knobs["parm_E"].setValue("40")
        knobs["parm_F_G"].setValue("50 60 70")
        knobs["parm_F_H"].setValue("80")
        knobs["parm_F_I"].setValue("90")
        knobs["parm_J"].setValue("100\n110\n120")
        knobs["parm_K"].setValue("/tmp2/test.dpx")
        knobs["parm_L"].setValue("/tmp2")
        knobs["parm_M"].setValue("/tmp2/test.%02d.dpx")
        knobs["parm_N"].setValue(False)
        knobs["parm_O"].setValue("preset3")
        IECoreNuke.setParameterFromKnobs(knobHolder, params)

        self.assertEqual(params["A"].getNumericValue(), 10)
        self.assertEqual(params["B"]["C"].getNumericValue(), 20.0)
        self.assertEqual(params["B"]["D"].getNumericValue(), 30.0)
        self.assertEqual(params["E"].getTypedValue(), "40")
        self.assertEqual(params["F"]["G"].getValue(), IECore.FloatVectorData([50, 60, 70]))
        self.assertEqual(params["F"]["H"].getValue(), IECore.IntVectorData([80]))
        self.assertEqual(params["F"]["I"].getValue(), IECore.DoubleVectorData([90]))
        self.assertEqual(params["J"].getValue(), IECore.StringVectorData(["100", "110", "120"]))
        self.assertEqual(params["K"].getTypedValue(), "/tmp2/test.dpx")
        self.assertEqual(params["L"].getTypedValue(), "/tmp2")
        self.assertEqual(params["M"].getTypedValue(), "/tmp2/test.##.dpx")
        self.assertEqual(params["N"].getTypedValue(), False)
        self.assertEqual(
            params["O"].getValue(),
            IECore.TransformationMatrixfData(
                IECore.TransformationMatrixf(IECore.V3f(1), IECore.Eulerf(), IECore.V3f(4))
            ),
        )
        # raises exception when trying to convert an invalid file sequence syntax
        knobs["parm_M"].setValue("/tmp2/test.%2d.dpx")
        self.assertRaises(RuntimeError, IECoreNuke.setParameterFromKnobs, knobHolder, params)
예제 #19
0
    def testClassParameterSetClassAndValues(self):

        fnOH = IECoreNuke.FnOpHolder.create("test", "classParameterTest", 1)

        with fnOH.parameterModificationContext() as parameterised:

            parameterised["cp"].setClass("maths/multiply", 2)
            parameterised["cp"]["a"].setNumericValue(10)
            parameterised["cp"]["a"].setNumericValue(20)

        self.__checkParameterKnobs(parameterised.parameters(), fnOH.node())

        nuke.nodeCopy("test/IECoreNuke/parameterisedHolder.nk")

        nuke.scriptClear()

        n = nuke.nodePaste("test/IECoreNuke/parameterisedHolder.nk")

        fnOH = IECoreNuke.FnOpHolder(n)

        parameterised2 = fnOH.getParameterised()[0]

        self.assertEqual(parameterised.parameters().getValue(),
                         parameterised2.parameters().getValue())
예제 #20
0
	def testNukeFileSequence( self ) :

		self.assertEqual( IECoreNuke.nukeFileSequence( "/tmp/test.dpx" ), "/tmp/test.dpx" )
		self.assertEqual( IECoreNuke.nukeFileSequence( "/tmp/test.#.dpx" ), "/tmp/test.%d.dpx" )
		self.assertEqual( IECoreNuke.nukeFileSequence( "/tmp/test.##.dpx" ), "/tmp/test.%02d.dpx" )
		self.assertEqual( IECoreNuke.nukeFileSequence( "/tmp/test_#########_test.dpx" ), "/tmp/test_%09d_test.dpx" )