What is the DS4.5 script to change content library pane to particular diectory?

DavidGBDavidGB Posts: 565

I'm not a developer, but this appears to be the forum with DS Script questions and answers, so:

What is the line of DS Script that will change the content library pane to a directory specified in the script in DS4.5? I'm looking for this so that (i) I can create custom actions to then have a menu from which I can jump to various Poser and DS content folders in the content library pane, and (ii) can put scripts in certain folders to jump to particular other folders.

In DS 3 I had e.g.

MainWindow.getPaneMgr().findPane("DzLibraryPane").setCurrentFolder("F:/Curious Labs/Poser 6/runtime/libraries/hand/!  V4");

and I'm pretty sure it worked in DS4.0 too. But in DS4.5 I just get an error

WARNING: TypeError: Result of expression 'MainWindow.getPaneMgr().findPane("DzLibraryPane")' [null] is not an object.
WARNING: Stack Trace:
()@:3

I'm not a scripter, don't know how to write scripts, but can sometimes understand and customize or repurpose simple ones. I've tried to look up in the scripting docs, but whereas in the DS 3 scripting docs I can find all the parts of the scipt above including DzLibraryPane, for DS 4.5 the scripting docs aren't up yet, and when i downloaded the 4.5 SDK docs I couldn't find any reference in them to DzLibraryPane, or anything that appears to be a replacement.

Comments

  • Richard HaseltineRichard Haseltine Posts: 96,700
    edited December 1969

    Try
    findPane( "DzContentLibraryPane" )
    that's what works in my FixDuplicateIDs script - the name changed, I think, to reflect that there are now several panes that can be Libraries - Content Library, Smart Content and the perhaps Preset tabs of the parameter and setting panes.

  • DavidGBDavidGB Posts: 565
    edited December 1969

    Executing Script...
    Script Error: Line 3
    TypeError: Result of expression 'MainWindow.getPaneMgr().findPane( "DzContentLibraryPane" ).setCurrentFolder' [undefined] is not a function.
    Stack Trace:
    ()@:3
    Error executing script on line: 3
    Script executed in 0 secs 31 msecs.

    Well, still doesn't work, but appears to get further. Has setCurrentFolder changed in some fashion?

  • Richard HaseltineRichard Haseltine Posts: 96,700
    edited December 1969

    Folder has been replaced with Container, since the pane might be showing a category rather than a folder on disc. Rob's trick for seeing the methods available for an object is

    var paneMgr = MainWindow.getPaneMgr();
    var pane  = paneMgr.findPane( "DzContentLibraryPane" );
    for ( var i in pane ) {
     print( i);
    }

    and using that I can see a way to get the current container, but not to set the current container. Sorry.

  • rbtwhizrbtwhiz Posts: 2,178
    edited December 1969

    Here is an example that I've just posted to the Scripting Samples section on the Documentation Center. It shows how its done for each of the top-level containers.

    -Rob

  • Richard HaseltineRichard Haseltine Posts: 96,700
    edited December 1969

    Thanks Rob.

  • DavidGBDavidGB Posts: 565
    edited December 1969

    Thanks very much, Rob .... I hope, if I can figure this out.

    This is important enough to me that it will hopefully let me continue using DS, as purely the inability to have shortcut scripts to locations in the Poser and DS formats parts of the DS content library has been driving me to look at moving to Poser. Quite apart from all the stuff that means I can't do anything at all with the computer most of the time, I've now developed a thing where, even when I am able to use the computer, for a while now I've had stabbing pains under my wrist every scroll or click. As I don't want to just render portraits of a single figure with just a hair and a material setting, but rather scenes with lots of characters, props etc, having to navigate up and down, up and down, up and down between the Poser and DS format content has become just too painful. Having a menu of actions to shortcut jumps to particular places, and scripts in certain folders to jump to certain other folders should get using the content library usable again for me.

    As a complete non scripter, though, this is a lot more complicated than the one-line script I used to use in DS3 quoted in the first post, where it was obvious what to change for shortcuts to different places (i.e. just the absolute path to the folder wanted).

    Trying to work through this, I'm guessing ....

    // Set the id used by the switches
    var sContainer = sStudioDir;

    leave that for a shortcut to a DS content folder, change sStudioDir to sPoserDir for a Poser format folder.

    And for DS fomat content ...

    sBase = oContentMgr.getContentDirectoryPath( 0 );

    change the number in the brackets for content in different DS format content folders (I have My Library, my DS3 content and my DS2 content) - presumably they number top down as they appear in the content library display, starting at 0 at the top. Then edit the relative path in sRelative = "Scripts/Utilities"; for the actual folder.

    While for a Poser format folder in a pathed runtime ....

    sBase = String("%1/Runtime/Libraries").arg( oContentMgr.getPoserDirectoryPath( 0 ) );

    again change the number for the different runtimes (I have 7), numbered down as they are listed in the content library. Then edit the relative path starting from below runtime:libraries in sRelative = "Character/DAZ People";

    Is that right?

    And just to keep the script sizes down, I suppose one could omit all the 'case's other than the sStudioDir ones in shortcuts to studio format folders, and all but the sPoserDir ones in shortcuts to Poser format folders.

    Assuming that's correct-ish, i should be able to sort out a menu of shortcut scripts, and shortcut links between folders. So that will be great. Thanks again.

    As a suggestion for a Product or freebie from someone, though, a script that would create the shortcut script to the selected folder would be very good. Two tools (or one tool that carried out both functions): one to create shortcut scripts for a favorites menu (or tab); one to create shortcut scripts from one folder to another.

  • DavidGBDavidGB Posts: 565
    edited December 1969

    DavidGB said:
    Assuming that's correct-ish, i should be able to sort out a menu of shortcut scripts, and shortcut links between folders. So that will be great. Thanks again.

    Just in case someone else like me - doesn't actually know how to write these scriipts, but is happy to load them into a text editor and customize them according to simple instructions - ends up reading this, looking to produce shortcut scripts to naviagte round the DS and Poseer format content library folders: what I put above was correct. I now have a working template script to customize as above to jump to DS format folders in the content library pane, and another template script to customize to jump to Poser format folders.

    :-)

    Thanks again, Rob.

    The one thing I still need to try and get my head round ....

    After updates to DAZ Studio, I generally find I need to go to Windows>Workspace>Customize and import the new default Menus, Actions and Toolbars (not layouts, as I want to keep my standard layout) to make sure I get the changes that have come with the update: new menu entries, things changing names or moving from one menu to another, new tools in the toolbars etc. But that then loses me e.g. a custom Favorites menu from the menu bar, and customized toolbars that present the tools i use rather than those I don't or hardly ever use. And it's a bit of a pain having to recreate then.

    I'm sure there must be some way of keeping a custom toolbar and a custom menu so that, after an update and calling up the new defaults, I can e.g. restore a Favorites menu to the menu bar with a click rather than rebuilding it (or simply just keeping it while still getting any changes to the normal menus), or keeping (differently named) custom Input Ouput, Creator Tools etc toolbars to use instead of the default ones, so after seeing the new defaults and whether there are some new entries I should put on my custom ones i can switch back to the custom ones. But I've never quite figured out how. But being sure to get the new stuff and changes has always ment losing my custom menus and toolbars and having to rebuild them from scratch. Well, apart from hand hacking the action. toolbar and menu .dsx files, copying in stuff from old saved versions into the new defaults, which is more of a pain that rebuilding things in the Customize pane. I'm sure I'm missing something.

  • rbtwhizrbtwhiz Posts: 2,178
    edited December 1969

    You're welcome.

    The example is intended to show how each of the top-level containers work within the same script so that you can see the differences/similarities between them. A script that changes the active container for a specific top-level type would be a fraction of that example - the majority of the length is in the comments, newlines for readability and switch statements, which would mostly vanish in a specific script.

    For instance, a much leaner version of the example script where you change to a DAZ Studio formats sub-container... without all the extra stuff used to teach:

    // DAZ Studio version 4.5 filetype DAZ Script
    var oPane = MainWindow.getPaneMgr().findPane( "DzContentLibraryPane" );
    if( oPane ){
     var sBase = App.getContentMgr().getContentDirectoryPath( 0 );
     var aIdPath = [ App.getAssetMgr().getStudioDirID(), sBase ];
     var aRelativeParts = [ "Scripts", "Utilities" ];
     for( var i = 0; i < aRelativeParts.length; i += 1 ){
      aIdPath.push( String("%1/%2").arg( sBase ).arg( aRelativeParts.slice(0, i + 1).join("/") ) );
     }
     oPane.browseToIDPath( aIdPath );
     oPane.updateContainer( aIdPath );
    }

    The script is more complicated because the Content Library pane does a whole lot more than the old Content pane did. Easier for the user typically means harder for the developer. That is simply the nature of the beast.

    BTW, your single-line script has no error checking/reporting to speak of - there are multiple points of potential failure. If something went wrong in a script you would probably be lucky enough to only cause an error... in C++ you could cause a crash. A more complete version of the script above that is closer to production ready, would look something like this...

    function setContentLibraryNativeFormatContainer( sFullPath )
    {
     if( !MainWindow ){
      print( "The Main Window is not defined." );
      return;
     }
     
     var oPaneMgr = MainWindow.getPaneMgr();
     if( !oPaneMgr ){
      print( "The Pane Manager is not defined." );
      return;
     }
     
     var sPaneClass = "DzContentLibraryPane";
     var oPane = oPaneMgr.findPane( sPaneClass );
     if( !oPane ){
      print( String("The \"%1\" class could not be found.").arg( sPaneClass ) );
      return;
     }
     
     var oContentMgr = App.getContentMgr();
     if( !oContentMgr ){
      print( "The Content Manager is not defined." );
      return;
     }
     
     var oBaseFolder = oContentMgr.findBaseDirectory( sFullPath, false );
     if( !oBaseFolder ){
      print( String("A base path for \"%1\" could not be found.").arg( sFullPath ) );
      return;
     }
     
     var sBasePath = oBaseFolder.fullPath;
     
     var sRelPath = oContentMgr.getRelativePath( sFullPath, false );
     if( sRelPath == sFullPath ){
      print( String("A relative path for \"%1\" could not be found.").arg( sFullPath ) );
      return;
     }
     
     if( sRelPath.startsWith( "/" ) ){
       sRelPath = sRelPath.substring( 1, sRelPath.length );
     }
     
     var oAssetMgr = App.getAssetMgr();
     if( !oAssetMgr ){
      print( "The Asset Manager is not defined." );
      return;
     }
     
     var aIdPath = [ oAssetMgr.getStudioDirID(), sBasePath ];
     var aRelParts = sRelPath.split("/");
     for( var i = 0; i < aRelParts.length; i += 1 ){
      aIdPath.push( String("%1/%2").arg( sBasePath ).arg( aRelParts.slice(0, i + 1).join( "/" ) ) );
     }
     
     oPane.browseToIDPath( aIdPath );
     oPane.updateContainer( aIdPath );
    }

    The function above could then be executed with a single line, like so...

    setContentLibraryNativeFormatContainer( "C:/Users/Rob/Documents/DAZ 3D/Studio/My Library/Scripts/Utilities" );

    Taking it a step further, if the function were placed in a file named "dzFavoriteFunctions.dsa" within the "./scripts/support/DAZ/ContentLibrary/" directory of your DAZ Studio 4.5 installation, you would be able to create custom actions/scripts that looked like so...

    var sFavPath = "C:/Users/Rob/Documents/DAZ 3D/Studio/My Library/Scripts/Utilities";
    var sFuncPath = String("%1/support/DAZ/ContentLibrary/dzFavoriteFunctions").arg( App.getScriptsPath() );
    var oScript = new DzScript();
    var sFuncFullPath = oScript.getScriptFile( sFuncPath );
    if( !sFuncFullPath.isEmpty() ){
     include( sFuncFullPath );
     setContentLibraryNativeFormatContainer( sFavPath );
    } else {
     var sMessage = String("A script at \"%1\" could not be found.").arg( sFuncPath );
     MessageBox.information( sMessage, "Resource Error", "&OK;" );
    }

    ... where the only part that needed to change between custom actions would be the string with the path on the first line. The same function script could then be extended to define additional functions for the other container types, and then there would be a total of two lines to change for a generated "favorite" custom action - the first line and the name of the function used in the included function script.

    My point being... there is quite a bit that could be done here, even by just dissecting my examples.

    -Rob

  • rbtwhizrbtwhiz Posts: 2,178
    edited December 1969

    I didn't respond to this earlier because I needed to get back to a few other important matters... but I wanted to say that I agree there is a general issue with menu/toolbar customizations and the ability to keep some while also benefiting from the improvements that have been made to the defaults. Its not an easy nut to crack, but I have been working on something to address it... because I do quite clearly see the need.

    -Rob

  • Richard HaseltineRichard Haseltine Posts: 96,700
    edited December 1969

    That's encouraging. All I had been able to think of, for menus, was something like the way one can export a branch from the Windows Registry - butt hat would still need some constant way of referencing the actions used.

Sign In or Register to comment.