Silencing Interactive Messages while Running a Script

I'm trying to silence messages that call for interaction from the user while my script is running. The script is supposed to run unattended, so I can't have it stopping to ask the user a question if it runs into an error. I want my script to handle the errors, alerting the user of them once the entire process is complete.

Searching the forums, I found someone asking for something similar at https://www.daz3d.com/forums/discussion/521766/batch-scripting-silent-non-interactive-mode, which in turn points to another discussion, all of which hopes to find the answer in something called DzCore, but nothing about how or whether it will actually work. I can find no object called DzCore in the documentation.

Does anyone know how to do this? I'm starting to suspect that it is not possible; that Studio does not allow the script to take this level of control.

Comments

  • Richard HaseltineRichard Haseltine Posts: 101,113

    What are the messages that you wish to suppress?

  • The first one that comes up on my list is an error message that says, "An error occurred while reading the file, see the log file for more details." This occurs if the user selected an inappropriate file for the the content manager to open; for example a pose preset instead of a scene file. Like in this snippet:

    var aSceneFile = FileDialog.doFileDialog(true, "Select a scene file.", "", "DAZ Files (*.duf *.dsf)");
    var oContentMgr = App.getContentMgr();
    oContentMgr.openFile(aSceneFile, false);
    
  • Richard HaseltineRichard Haseltine Posts: 101,113

    Well, you could try querying the CMS to make sure the file is an appropriate type (or even use dzGZFile to open the file, JSONise it, and check the type member  in case it isn't in the CMS) before loading.

  • Thank you for the suggestions. I'm not sure how to implement these. For querying the CMS, is that a method for the DzContentMgr object? I don't see anything that gives a file type. For the DzGZFile object, that seems to be about zip files, so I'm not seeing how that helps. I don't know what it means to JSONise a file.

    On a more general note, the fact that you are suggesting ways to prevent the error in the first place suggests to me that it may not be possible to silence and then handle the errors myself. If that's true, then preventing the errors in tyhe first place is of course the only option. Actually, perventing the errors, if I can understand how to do it, is a good idea in any case, so I really thank you for that. It does, however, mean that I will need to find different solutions for each case where calling for human interaction will prevent me from making a script that can run unattended.

  • Richard HaseltineRichard Haseltine Posts: 101,113

    I think DzAsset.contentType will give the type http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/asset_dz#a_1ab2b2a5577c93f69a6b42cf7796dae9a5

    Many presets will be compressed, using DzGZFile will let you open them and read their content whether or not they are compressed (DzFile will just give the compressed data literally).

    You open the file and read the whole thing into a string, then pass that to the JSON.parse() method to get an actual data object from which you can obtain values (such as the file type recorded there). http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/json

  • I worked with a friend of mine and found that the answer to my original question about preventing error messages from requiring interaction from the user is to put things into try and catch blocks. 

    On querying the CMS, the intended files to open are user created scene files, so none of them will be in the CMS.

    I did try using DzFile, but it seems to have the problems you mention. I find it confusing that the files are considered "compressed" because they can be read by text editors on my system without issue. I'll try using DzGZFile and see how that goes.

  • Well that was quick. DzGZFile worked. I just put it in where I had DzFile before and that was it. I tried saving a scene without comression just to check, and yes, DzFile handled that one just fine, and so did DzGZFile. Since the they appear identical to my text editior, I'm mystified as to why one is so much larger than the other.

    Thanks for helping.

  • Richard HaseltineRichard Haseltine Posts: 101,113

    Your text editor must be decompressing them on load - which is a nice feature, mine doesn't do that (so editing compressed files requires decompressing first).

  • Neil ClennanNeil Clennan Posts: 45
    edited July 2023

    That was it. I tried a different text editor and saw that the compressed file was all binary stuff. BBEdit appears to decompress and recompress on the fly. Thanks. 

    Post edited by Neil Clennan on
Sign In or Register to comment.