Problems saving figure/prop asset via script [partially solved]
I am trying to save a figure/prop asset using the sample (http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/file_io/save_dsf_figure_prop_support/start) but am getting errors I cannot understand at the point that the save happens, immediately after the file save dialog has appeared and I have specified a path and file name:
general\dzscript.cpp(658): Unhandled error while executing script.
QScriptEngine::popContext() doesn't match with pushContext()
I have made only necessary changes to the sample:
- hard-coded the 'product name' and 'item name' in the call to setSupportPathOptions() at line 359
- replaced sClassName in the second argument to compile the value sFile at line 411 with a string to produce the file path I want to save to (matching the path I choose in the save dialog).
- removed lines 370-380 - see further explanation for this below.
The reason for wanting to get this working is that executing the figure/prop asset save through the UI causes DS to crash immediately after entering a file name in the file save dialog. I have reported this as a bug but support have not offered any answers (yet). Google is less informative on the second line of the above error than I expected.
I am using DS 4.10.
Regarding change 3 above, as I read these lines 370-380, they are intended to cause an options dialog to be displayed when the variable bShowOptions is set to true. However, the function getOptions of the DzAssetIOFilter object (actually inherited from DzFileIO) produces an ugly error in this scenario.
Executing Script...
general\dzcontentmgr.cpp(4082): Empty path passed to DzContentMgr::getMappedPath()
general\dzscript.cpp(658): Unhandled error while executing script.
QScriptEngine::popContext() doesn't match with pushContext()
The documentation for this function doesn't explain what the 'empty' path (third argument to the getOptions() function, a string) should be set to - obviously a path, but a path to what? I haven't been able to guess a value that prevents this error appearing.
So, no problem I thought, I'm happy not to have the options dialog displayed, so I'll settle for bShowOptions set to false - by not pressing the Ctrl key, or by explicitly setting it to false in the script. But there is still a problem, because the getOptions function is called and it appears to set all the options back to the unhelpful defaults that you start with, i.e. you lose the vendor name, product name and item name, plus also the ContentType and Category. This is obvious from the debug statements.
Any suggestions as to how to get this to work appreciated. Perhaps someone knows what would be a valid path as the third argument to getOptions()? I've tried paths that exist, but none works so far.
Comments
What is 2. meaning? sClassName isn't a filename
When the sample script goes to do the save, it does this:
The name of the file to save to - sFile - is constructed from a directory path - sBasePath - and this sClassName string as the name of the file, appending " Test" for good measure. sClassName is initialised earlier in the script like this:
Hence, unless you change this, the name of the file you save to will always be this odd name that bears no relation to the asset you are saving. I've simply replaced it in the call to doSaveWithOptions with a string that describes the prop, without the " Test' appendix. sClassName is also used to derive the index of the asset filter we need, but I have not altered that.
I wonder if the doSave() function on the DzAssetIOFilter class that is being passed as the first argument to doSaveWithOptions() might work. Worth a try, though I would not surprise if it threw the same error.
sClassname is also passed to the oAssetIOMgr.findFilter function, for which its format is important - the other string is just being generated to record what type of preset it is, you should probably compeletely rewrite that rather than altering the sClassName object.
I finally managed to get a modified version of the example script to save a figure/prop asset, which allows me to work around the crash that DS does if I use the menus.
I had to hardcode a number of values in the script including various paths to avoid the 'popContext() does not match pushContext()' problem. It will still not allow the options dialog to be displayed by holding the Ctrl key, which the code suggests was intended - it continues to crash with the error quoted above about an 'Empty path...'. Also, although the saved file does load the figure into a scene, there are some issues with the figure's rigging. This may not be a result of any issue with the saving of the file as such, so I will start another thread on that.