Thanks a lot for that, works perfectly. Can't thank you guys enough for
sharing your knowledge like this!

Cheers,
Simon


2012/11/4 Nathan Rusch <nathan_ru...@hotmail.com>

>   Right, good call on the recursive knobChanged limitation Ivan. That
> slipped my mind for some reason.
>
> I would agree that just calling whatever import function you define
> directly from your PyScript knob is the simplest and most elegant solution.
> Depending on whether you’re after a persistent GUI, you may want to throw
> in a call to hide your dialog as well.
>
> -Nathan
>
>
>  *From:* Ivan Busquets <ivanbusqu...@gmail.com>
> *Sent:* Sunday, November 04, 2012 2:28 PM
> *To:* Nuke Python discussion <nuke-python@support.thefoundry.co.uk>
> *Subject:* Re: [Nuke-python] Import fbx via PythonPanel
>
> The problem with the knobChanged approach is that you're preventing other
> knobChanged callbacks to be executed.
> The fbx_take_name and fbx_node_name both have knobChanged callbacks to set
> the values for other knobs. But if you're already setting them WITHIN a
> knobChanged callback, they will not be executed (knobChanged callbacks are
> not called recursively)
>
> Since you're already using a PyScript knob, I think the easiest would be
> to just use your camera creation routine/function as the knob's value,
> rather than in a knobChanged event:
>
>
> As in:
>
>  class import_camera(nukescripts.PythonPanel):
>     def __init__(self):
>         nukescripts.PythonPanel.__init__(self, 'import camera')
>         self.import_camera = nuke.PyScript_Knob("import_camera", "import
> camera")
>         self.addKnob(self.import_camera)
>         self.import_camera.setValue("test()")
>
> import_camera().show()
>
> def test():
>
>     filepath = "C:/Users/Simon/Desktop/A018_C001_05075H_baked.fbx"
>     cam_name = "Camera_A018_C001_05075H"
>     c = nuke.createNode('Camera2', 'file "%s"  read_from_file True'  %
> filepath)
>     c.forceValidate()
>     c["fbx_take_name"].setValue("Take 001")
>     c["fbx_node_name"].setValue(cam_name)
>
>
> Otherwise, if you must go with the knobChanged approach, you could use the
> "hack" of temporarily enabling the KNOB_CHANGED_RECURSIVE flag on the
> fbx_node_name knob, like so:
>
> # Set the take knob
>
> c["fbx_take_name"].setValue("Take 001")
>
>
>
> # Set the KNOB_CHANGED_RECURSIVE flag
>
> c["fbx_node_name"].setFlag(nuke.KNOB_CHANGED_RECURSIVE)
>
>
>
> #Set the node name value. This should now trigger any knob-changed events
> associated with this knob
>
> c["fbx_node_name"].setValue(cam_name)
>
>
>
> # Clear the KNOB_CHANGED_RECURSIVE flag
>
> c["fbx_node_name"].clearFlag(nuke.KNOB_CHANGED_RECURSIVE)
>
>
> Hope that helps.
>
> Cheers,
> Ivan
>
> On Sun, Nov 4, 2012 at 2:04 PM, Simon Björk <bjork.si...@gmail.com> wrote:
>
>> Ah, yes, I re-read your last mail a couple of times and finally got it
>> :). It actually does work to do it that way, but that leaves me with the
>> default ok/cancel buttons and showModalDialog() instead of show(), correct?
>> Still seems strange that it gives different results.
>>
>> Thanks Nathan!
>>
>> Cheers,
>> Simon
>>
>> 2012/11/4 Nathan Rusch <nathan_ru...@hotmail.com>
>>
>>>   Sorry, I probably should have been a little more clear. What I meant
>>> is basically using the GUI itself as a front-end for user input and
>>> confirmation only, and then gathering its values after the fact. Very
>>> simple example:
>>>
>>> class ImportCameraDialog(nukescripts.PythonPanel):
>>>     def __init__(self):
>>>         super(ImportCameraDialog, self).__init__('import camera')
>>>         self.fbxFile = ''
>>>         self.fbxFileKnob = nuke.File_Knob('fbx_path', 'fbx path')
>>>         self.addKnob(self.fbxFileKnob)
>>>
>>>     def knobChanged(self, knob):
>>>         if knob is self.fbxFileKnob:
>>>             self.fbxFile = self.fbxFileKnob.value()
>>>
>>>
>>> d = ImportCameraDialog()
>>> if d.showModalDialog():
>>>     fbxPath = d.fbxFile.strip()
>>>     if fbxPath:
>>>         # Validate path, create your node here, etc.
>>>         pass
>>>
>>>
>>> I don’t necessarily know if this will make a difference, but I think
>>> it’s worth a try.
>>>
>>> -Nathan
>>>
>>>
>>>  *From:* Simon Björk <bjork.si...@gmail.com>
>>> *Sent:* Sunday, November 04, 2012 1:35 PM
>>> *To:* Nuke Python discussion <nuke-python@support.thefoundry.co.uk>
>>> *Subject:* Re: [Nuke-python] Import fbx via PythonPanel
>>>
>>>  Hi Nathan,
>>>
>>> thanks for your reply. I'm not really sure I understand how you mean,
>>> but I tried this and got the same results (not working).
>>>
>>>  class import_camera(nukescripts.PythonPanel):
>>>     def __init__(self):
>>>         nukescripts.PythonPanel.__init__(self, 'import camera')
>>>         self.import_camera = nuke.PyScript_Knob("import_camera", "import
>>> camera")
>>>         self.addKnob(self.import_camera)
>>>
>>>     def knobChanged(self, knob):
>>>         if knob is self.import_camera:
>>>             test()
>>>
>>> import_camera().show()
>>>
>>> def test():
>>>
>>>     filepath = "C:/Users/Simon/Desktop/A018_C001_05075H_baked.fbx"
>>>     cam_name = "Camera_A018_C001_05075H"
>>>     c = nuke.createNode('Camera2', 'file "%s"  read_from_file True'  %
>>> filepath)
>>>     c.forceValidate()
>>>     c["fbx_take_name"].setValue("Take 001")
>>>     c["fbx_node_name"].setValue(cam_name)
>>>
>>> Cheers,
>>> Simon
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> 2012/11/4 Nathan Rusch <nathan_ru...@hotmail.com>
>>>
>>>>   Have you tried using your PythonPanel subclass the same way you’re
>>>> using the simple Panel, as opposed to encapsulating your node creation code
>>>> in the class itself?
>>>>
>>>> -Nathan
>>>>
>>>>
>>>>  *From:* Simon Björk <bjork.si...@gmail.com>
>>>> *Sent:* Sunday, November 04, 2012 11:04 AM
>>>> *To:* Nuke Python discussion <nuke-python@support.thefoundry.co.uk>
>>>> *Subject:* [Nuke-python] Import fbx via PythonPanel
>>>>
>>>>   I'm trying to import an fbx file using a PythonPanel, but for some
>>>> reason it doesn't work. Using forceValidate() the camera loads, but it
>>>> doesn't set animation, focal etc. Strange thing is it works perfectly if I
>>>> use a simple panel istead (I don't even have to use forceValidate()).
>>>> Anyone have any idea why this is? I've found old treads where people had
>>>> problems loading an fbx from a terminal session.
>>>>
>>>> *Example code PythonPanel (does not work):*
>>>>
>>>>  class import_camera(nukescripts.PythonPanel):
>>>>     def __init__(self):
>>>>         nukescripts.PythonPanel.__init__(self, 'import camera')
>>>>         self.import_camera = nuke.PyScript_Knob("import_camera",
>>>> "import camera")
>>>>         self.addKnob(self.import_camera)
>>>>
>>>>     def knobChanged(self, knob):
>>>>         if knob is self.import_camera:
>>>>
>>>>             filepath =
>>>> "C:/Users/Simon/Desktop/A018_C001_05075H_baked.fbx"
>>>>             cam_name = "Camera_A018_C001_05075H"
>>>>
>>>>             c = nuke.createNode('Camera2', 'file "%s"  read_from_file
>>>> True'  % filepath)
>>>>             c.forceValidate()
>>>>             c["fbx_take_name"].setValue("Take 001")
>>>>             c["fbx_node_name"].setValue(cam_name)
>>>>
>>>> import_camera().show()
>>>>
>>>> *Example code simple panel (works):*
>>>>
>>>> p = nuke.Panel("import camera")
>>>> result = p.show()
>>>> if result:
>>>>
>>>>     filepath = "C:/Users/Simon/Desktop/A018_C001_05075H_baked.fbx"
>>>>     cam_name = "Camera_A018_C001_05075H"
>>>>
>>>>     c = nuke.createNode('Camera2', 'file "%s"  read_from_file True'  %
>>>> filepath)
>>>>     c["fbx_take_name"].setValue("Take 001")
>>>>     c["fbx_node_name"].setValue(cam_name)
>>>>
>>>> Cheers,
>>>> Simon
>>>> ------------------------------
>>>> _______________________________________________
>>>> Nuke-python mailing list
>>>> Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
>>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>>>
>>>> _______________________________________________
>>>> Nuke-python mailing list
>>>> Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
>>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>>>
>>>>
>>> ------------------------------
>>> _______________________________________________
>>> Nuke-python mailing list
>>> Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>>
>>> _______________________________________________
>>> Nuke-python mailing list
>>> Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>>
>>>
>>
>> _______________________________________________
>> Nuke-python mailing list
>> Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>
>>
>  ------------------------------
> _______________________________________________
> Nuke-python mailing list
> Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
> _______________________________________________
> Nuke-python mailing list
> Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to