State:Closed|icon_bug|icon_katana|database:public|TargetRelease:4.5v2|Resolution:None|BugID:59923|
Problem summary
When loading new Katana projects through a Shelf script, if a UI4 or QtGui window us used as part of the script, it causes runtime errors with the undoStack.py.
This is due to the UndoStack.Clear() function breaking, as it cannot be ran from inside an open undo group.
This runtime error prevents modules that would normally run in folders known to Katana in KATANA_RESOURCES to not run at all, in this case specifically to UIPlugins.
This can be an issue when expecting a 'scriptLoad' callback after launch.
Running the same launch script within the Python tab (reproduction steps test 2), does not throw the runtime issue.
Customer reported version
katana.2.5v7
Customer reported platform
centos7
Steps to reproduce
Test 1:
1) Setup Callback script for testing
A) Navigate to '.katana/UIPlugins' (Create folder if it does not exist)
B) Create a Python script file and open it within a IDE editor.
C) Copy the following into the script:
from Katana import Callbacks
import logging
def on_sceneload(**kwargs):
log = logging.getLogger("undoStackClear Example")
log.info("on_scene_load callback running")
log = logging.getLogger("undoStackClear Example")
log.info("Registering onSceneLoad callback...")
Callbacks.addCallback(Callbacks.Type.onSceneLoad, on_sceneload)
D) Save the script.
2) Add the shelve script for testing
A) Navigate to '.katana/Shelves/Test_Shelves' (Create folder if it does not exist)
B) Create a Python script file and open it within a IDE editor.
C) Copy the following into the script:
"""
NAME: Load_Shelve_Project
ICON: Icons/LiveGroup/Group256.png
Load specific project file with asset file browser
"""
import os
from Katana import KatanaFile
def LoadProject():
filename = UI4.Util.AssetId.BrowseForAsset('','Select Project File',False,{'fileTypes':'katana *.livegroup'})
if filename is not None:
KatanaFile.Load(filename)
LoadProject()
D) Save the script.
3) Test the shelve script
A) Open Katana
B) Select your new Shelve option from within the Shelves
C ) Select any .katana file and press Ok.
D) Open your Terminal window
Result: The Katana project will load correctly, but the terminal will throw a runtime error and not print the callback command.
Test 2:
1) Follow the first step from test 1 (Copy the callback script into the '.katana/UIPlugins' location)
2) Copy the following into the Python tab within Katana:
def LoadProject():
filename = UI4.Util.AssetId.BrowseForAsset('','Select Project File',False,{'fileTypes':'katana *.livegroup'})
if filename is not None:
KatanaFile.Load(filename)
LoadProject()
2) Select any .katana file and press Ok.
Result: The Katana project will load correctly, and the callback print statement will appear in the Python tab
Workaround
A workaround is to temporarily disable the undo stack when loading a new Katana project, then re-enable the undo stack using a callback.
Temporarily disable the undo stack using Utils.UndoStack.DisableCapture(). The code below modifies the shelf item script example to disable the undo stack.
"""
NAME: Load_Shelve_Project
ICON: Icons/LiveGroup/Group256.png
Load specific project file with asset file browser
"""
import os
from Katana import KatanaFile
def LoadProject():
Utils.UndoStack.DisableCapture()
filename = UI4.Util.AssetId.BrowseForAsset('','Select Project File',False,{'fileTypes':'katana *.livegroup'})
if filename is not None:
KatanaFile.Load(filename)
LoadProject()
Likewise, the undo stack can be re-enabled with Utils.UndoStack.EnableCapture(). The code below modifies the callback example to enable the undo stack. Be sure to import Utils in the callback function.
from Katana import Callbacks
import logging
def on_sceneload(**kwargs): from Katana import Utils log = logging.getLogger("undoStackClear Example") log.info("on_scene_load callback running") Utils.UndoStack.EnableCapture()log = logging.getLogger("undoStackClear Example")log.info("Registering onSceneLoad callback...")Callbacks.addCallback(Callbacks.Type.onSceneLoad, on_sceneload)
The Katana project should now load as intended without the UndoStack.Clear() error.
Reproduced by support
This bug has been reproduced in:
Earliest version tested
- This issue appears to be in all versions of the product
Expected behaviour
External callbacks should not run into runtime errors when launching shelve script.
Actual behaviour
Runtime errors are stopping scripts from working.
We're sorry to hear that
Please tell us why