Announcement

Collapse
No announcement yet.

Python callback fails when VRay doesn't load in time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Python callback fails when VRay doesn't load in time

    So we've created a pipeline tool (as a plugin) where we have a Python callback (om.MSceneMessage.kAfterNew) set up to trigger a function every time a new scene file is created. The main goal with this is to set up the new scene with the same default variables across all workstations, like using VRay as the current renderer and have the default resolution and other settings configured.

    Let's say we fire up Maya (2016) and at the end of the startup it creates a new, empty, scene. This will trigger the callback function and all is good until we get to the last part where we have the VRay specific code. Here it produces the following error message:
    Code:
    // Error: line 1: The renderer vray is not registered yet. //
    However; afterwards when I do a manual "File -> New Scene" it works perfectly. This implies to me that the VRay plugin hasn't finished loading when the new scene is created by Maya - so my first thought was to add a delay loop to give it time to finish loading. To avoid waiting too long we check for VRay availability every second.

    I've tried different ways to test, here are the main ones:
    Code:
    mel.eval('pluginInfo -q -l "vrayformaya"') # will always say True since VRay are marked as active - even though it hasn't finished loading yet
    cmds.renderer( 'vray', exists = True ) # always returns False even though we check every second for 4 minutes before giving up. This should be plenty of time.
    I've also tried the different commands as mel - even doing "rehash;" before each new run-through of the loop. Splitting out the code to a separate Python module and doing import/reload didn't help either.

    I've also skipped the delay loop check entirely and done a "pause" for 30 seconds en then tried to run my commands, but that doesn't help either.

    My working theory is that all scripts/plugins triggered by the startup sequence in Maya (userSetup.mel) only have access to a snapshot of the Maya internals - and that this snapshot doesn't get updated until after we have finished loading Maya and all startup scripts - which makes it too late to do what we need to do. I may very well be wrong about this, but every test I have done so far fails and I'm not sure about what to try next. I've even tried the ugly hack of having my script create another new scene (after the first one) - but this fails as well.

    Any suggestions or ideas are greatly appreciated!

    Cheers!
    -atle

  • #2
    loadPlugin -addCallback?
    V-Ray/PhoenixFD for Maya developer

    Comment


    • #3
      No, the callback is added to the Maya new scene command like so:
      Code:
      import maya.OpenMaya as om
      import maya.cmds as cmds
      stNewSceneCallback = om.MSceneMessage.addCallback(om.MSceneMessage.kAfterNew, studioToolsNewScene)
      where studioToolsNewScene is the function being triggered. This is added through our studioTools plugin.

      I don't think we need to add a callback to the VRay plugin itself. The Maya script editor shows that the VRay plugin previously has been loaded, but I'm guessing it really keeps loading everything in the background and in paralell. Thats why we can't query the status of the plugin itself in maya - as I mentioned in my previous post.

      Comment


      • #4
        Ok, but the plugin may be not loaded at this point, so you can't do V-Ray related thing there . I can't tell you how Maya loads the plugins. I doubt it's in parallel, since Maya itself is rarely working properly outside its main thread. But it delays the plugin loading to make you feel it starts faster. If the -addCallback callback is not executed yet, you can skip doing your stuff in the new callback, and do it in -addCallback. Another method may be to check if vray is registered. But again, you must have a separate callback to check this regularly, and when done, do your stuff.
        V-Ray/PhoenixFD for Maya developer

        Comment


        • #5
          Ah, I see I think I can make something that works by splitting my code up - but it's not going to be pretty

          Thanks!

          Comment


          • #6
            Finally got the callback code to work, but according to the log the callback get's executed right after the plugin has been set to load in userSetup.mel. It seems VRay tells Maya it has finished loading and keeps loading in the background instead.

            Any other suggestions on how to proceed?

            Cheers!

            Comment


            • #7
              Did you try "evalDeferred(lowestPriority=1)"? It usually makes your stuff run after everything else has finished.

              Comment


              • #8
                Thanks for the tip, I didn't know about evalDeferred. Solved the issue and allows for much cleaner code as well.

                Comment


                • #9
                  V-Ray doesn't load anything in the background, evalDeferred is really good work-around if it works
                  V-Ray/PhoenixFD for Maya developer

                  Comment


                  • #10
                    Which it did Thanks!

                    Comment

                    Working...
                    X