Set Content Library Container help

I tried this script a year ago and gave up in frustration. But in my current project, I have to continually drill down into a Poser folder to get stuff.

http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/specific_ui/set_content_library_container/start?do=export_code&codeblock=1

Here's what baffles me. I *think* this is the section I need to change, but have no idea how.

// Set the base to the first mapped Poser formats directory			var sBase = String("%1/Runtime/Libraries").arg( oContentMgr.getPoserDirectoryPath( 0 ) ); 			// Set the first value to the id of the top-level container,			// set the second value to the base path within that container			var aIdPath = [ oAssetMgr.getPoserDirID(), sBase ];			// Split the relative path into its individual parts			var aRelativeParts = sPath.split( "/" );			// Iterate over each part in the relative path,			for( var i = 0; i < aRelativeParts.length; i += 1 ){				// Push the full path of the "current" part onto the id path array				aIdPath.push( String("%1/%2")					.arg( sBase )					.arg( aRelativeParts.slice(0, i + 1).join( "/" ) ) );

 

var aIdPath = [ oAssetMgr.getPoserDirID(), sBase to what?

and

var aRelativeParts = sPath.split( "/" ); to what?

Can anyone help out here? I'd certainly appreciate it.

I'd appreciate it even more if we could just right-click a folder and choose 'Add to Favorites' but my feature request for that went nowhere.

Comments

  • sBase would be the relative path to the folder you want to start with - then the rest of the path, to get an absolute path is prepended to that by the oAssetMgr call.

    the split command is breaking the string sPath into an array of folder names - it breaks the string apart at the directory separators ("/").

    Remember that feature requests are assesed by product management and set a priority, based on their prceived need and on the resourced needed to implement. Rob may choose to pick soem up in his own tiem, but that obviously depends on how they are presented (and woudl still be dependent on factors like the tiem needed and the risk of breaking something else).

  • macleanmaclean Posts: 2,438

    I don't really understand any of that, Richard.The path I want is "F:\6 poser\Runtime\libraries\Props\Maclean\Everyday"

    I tried this and get an error.

    var aIdPath = [ oAssetMgr.getPoserDirID(), F:\6 poser ];			// Split the relative path into its individual parts			var aRelativeParts = sPath.split( "Runtime\libraries\Props\Maclean\Everyday" );

    I know I'm thick, but a commented path example in these scripts would avoid idiots like me asking stupid questions.

  • Is that a mapped content directory?

  • macleanmaclean Posts: 2,438

    Yes, it is. These are the only 2 dirs I have. (Btw, I use Tree view, not categories)

     

    mapped.jpg
    462 x 457 - 47K
  • Actually I misread the code, the

    oContentMgr.getPoserDirectoryPath( 0 ) is adding the root to make an absolute path in the initial setting of sBase. The input is the relative path, as I said, but tou end up with the absolute path. In any event it should be using sPath, not a literal string.
  • macleanmaclean Posts: 2,438

    Not sure what that means either. I tried this, but nothing happens.

    			// Set the base to the first mapped Poser formats directory			var sBase = String("%1/Runtime/Libraries").arg( oContentMgr.getPoserDirectoryPath( 0 ) );						// Set the first value to the id of the top-level container,			// set the second value to the base path within that container			var aIdPath = [ oAssetMgr.getPoserDirID(), sBase ];			// Split the relative path into its individual parts			var aRelativeParts = sPath.split( "Props\Maclean\Everyday" );			// Iterate over each part in the relative path,			for( var i = 0; i < aRelativeParts.length; i += 1 ){				// Push the full path of the "current" part onto the id path array				aIdPath.push( String("%1/%2")					.arg( sBase )					.arg( aRelativeParts.slice(0, i + 1).join( "/" ) ) );			}

    Then at the end of the script, I see this, but why is it there?

    // Finalize the function and invoke})( "Character/DAZ People" );

    Should I be changing that too?

  • maclean said:

    Not sure what that means either. I tried this, but nothing happens.

    			// Set the base to the first mapped Poser formats directory			var sBase = String("%1/Runtime/Libraries").arg( oContentMgr.getPoserDirectoryPath( 0 ) );						// Set the first value to the id of the top-level container,			// set the second value to the base path within that container			var aIdPath = [ oAssetMgr.getPoserDirID(), sBase ];			// Split the relative path into its individual parts			var aRelativeParts = sPath.split( "Props\Maclean\Everyday" );			// Iterate over each part in the relative path,			for( var i = 0; i < aRelativeParts.length; i += 1 ){				// Push the full path of the "current" part onto the id path array				aIdPath.push( String("%1/%2")					.arg( sBase )					.arg( aRelativeParts.slice(0, i + 1).join( "/" ) ) );			}

    No - the split( substring ) breaks the main string into pieces, at the location(s) of the substring - you didn't want to change that.

    maclean said:

    Then at the end of the script, I see this, but why is it there?

    // Finalize the function and invoke})( "Character/DAZ People" );

    Should I be changing that too?

    That last bit is the relative path to be used. Sorry, I should have gone to the full script rather than just looking at the bits you were querying.

    Courtesy of Rob:

    /********************************************************************** 	Copyright (C) 2002-2019 Daz 3D, Inc. All Rights Reserved. 	This script is provided as part of the Daz Script Documentation. The	contents of this script, and\or any portion thereof, may only be used	in accordance with the following license: 	Creative Commons Attribution 3.0 Unported (CC BY 3.0)	- http://creativecommons.org/licenses/by/3.0 	To contact Daz 3D or for more information about Daz Script visit the	Daz 3D website: 	- http://www.daz3d.com **********************************************************************/// Source: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/specific_ui/set_content_library_container/start// Define an anonymous function;// serves as our main loop,// limits the scope of variables(function( sPath ){		/*********************************************************************/	// String : A function for retrieving a translation if one exists	function text( sText )	{		// If the version of the application supports qsTr()		if( typeof( qsTr ) != "undefined" ){			// Return the translated (if any) text			return qsTr( sText );		} 		// Return the original text		return sText;	};		/*********************************************************************/	// Get the pane manager	var oPaneMgr = MainWindow.getPaneMgr();	// If the pane manager was not found	if( !oPaneMgr ){		// We are done...		return;	}		// Find the content library pane	var oPane = oPaneMgr.findPane( "DzContentLibraryPane" );	// If the pane was not found	if( !oPane ){		// We are done...		return;	}		// If the app version is 4.8.1.51 or newer	if( App.version64 >= 0x0004000800010033 ){		// Browse to the path		oPane.browseToPoserFolder( sPath );	// Otherwise	} else {		// Attempt to fall back		try {			// Get the asset manager			var oAssetMgr = App.getAssetMgr();						// Get the content manager			var oContentMgr = App.getContentMgr();						// Set the base to the first mapped Poser formats directory			var sBase = String("%1/Runtime/Libraries").arg( oContentMgr.getPoserDirectoryPath( 0 ) );						// Set the first value to the id of the top-level container,			// set the second value to the base path within that container			var aIdPath = [ oAssetMgr.getPoserDirID(), sBase ];			// Split the relative path into its individual parts			var aRelativeParts = sPath.split( "/" );			// Iterate over each part in the relative path,			for( var i = 0; i < aRelativeParts.length; i += 1 ){				// Push the full path of the "current" part onto the id path array				aIdPath.push( String("%1/%2")					.arg( sBase )					.arg( aRelativeParts.slice(0, i + 1).join( "/" ) ) );			}						// Cause the "current" container to change			oPane.browseToIDPath( aIdPath );						// Cause the "current" container to update			oPane.updateContainer( aIdPath );		// Handle errors		} catch( e ){			// Define the strings used to provide feedback			var sTitle = text( "Resource Error" );			var sMessage = text( "A newer version of %1 is required " +				"to execute this script.").arg( App.appName );			var sAccept = text( "&OK" );						// Provide feedback to the user			MessageBox.critical( sMessage, sTitle, sAccept );						// We are done...			return;		}	}	// Finalize the function and invoke})( "Props/Maclean/Everyday" );

     

  • macleanmaclean Posts: 2,438

    Well, I copied/pasted the entire script but it does nothing - and gives no errors either. Tried changing the last line to "Props" - nothing.

    The windows explorer path is "F:\6 poser\Runtime\libraries\Props\Maclean\Everyday" and it's the only mapped Poser directory. Am I doing something wrong? Back/forward slashes? Quotes?

  • Richard HaseltineRichard Haseltine Posts: 100,842
    edited October 2019

    There seems to be an issue, as written, with the simple call for later versins of DS - if I sabotage that by making the line fter getting the Content LIbrary pane

    if( ! App.version64 >= 0x0004000800010033 ){

    (adding a negation) then the script works, using the long method in the later section. I don't know if the method requires a slightly different format, or if the version number is too low and it's a feature added in a later build than 4.12.0.86 - which is what I was trying.

    Post edited by Richard Haseltine on
  • macleanmaclean Posts: 2,438
    /********************************************************************** 	Copyright (C) 2002-2019 Daz 3D, Inc. All Rights Reserved. 	This script is provided as part of the Daz Script Documentation. The	contents of this script, and\or any portion thereof, may only be used	in accordance with the following license: 	Creative Commons Attribution 3.0 Unported (CC BY 3.0)	- http://creativecommons.org/licenses/by/3.0 	To contact Daz 3D or for more information about Daz Script visit the	Daz 3D website: 	- http://www.daz3d.com **********************************************************************/// Source: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/specific_ui/set_content_library_container/start// Define an anonymous function;// serves as our main loop,// limits the scope of variables(function( sPath ){		/*********************************************************************/	// String : A function for retrieving a translation if one exists	function text( sText )	{		// If the version of the application supports qsTr()		if( typeof( qsTr ) != "undefined" ){			// Return the translated (if any) text			return qsTr( sText );		} 		// Return the original text		return sText;	};		/*********************************************************************/	// Get the pane manager	var oPaneMgr = MainWindow.getPaneMgr();	// If the pane manager was not found	if( !oPaneMgr ){		// We are done...		return;	}		// Find the content library pane	var oPane = oPaneMgr.findPane( "DzContentLibraryPane" );	if( ! App.version64 >= 0x0004000800010033 ){	// If the pane was not found	if( !oPane ){		// We are done...		return;	}		// If the app version is 4.8.1.51 or newer	if( App.version64 >= 0x0004000800010033 ){		// Browse to the path		oPane.browseToPoserFolder( sPath );	// Otherwise	} else {		// Attempt to fall back		try {			// Get the asset manager			var oAssetMgr = App.getAssetMgr();						// Get the content manager			var oContentMgr = App.getContentMgr();						// Set the base to the first mapped Poser formats directory			var sBase = String("%1/Runtime/Libraries").arg( oContentMgr.getPoserDirectoryPath( 0 ) );						// Set the first value to the id of the top-level container,			// set the second value to the base path within that container			var aIdPath = [ oAssetMgr.getPoserDirID(), sBase ];			// Split the relative path into its individual parts			var aRelativeParts = sPath.split( "/" );			// Iterate over each part in the relative path,			for( var i = 0; i < aRelativeParts.length; i += 1 ){				// Push the full path of the "current" part onto the id path array				aIdPath.push( String("%1/%2")					.arg( sBase )					.arg( aRelativeParts.slice(0, i + 1).join( "/" ) ) );			}						// Cause the "current" container to change			oPane.browseToIDPath( aIdPath );						// Cause the "current" container to update			oPane.updateContainer( aIdPath );		// Handle errors		} catch( e ){			// Define the strings used to provide feedback			var sTitle = text( "Resource Error" );			var sMessage = text( "A newer version of %1 is required " +				"to execute this script.").arg( App.appName );			var sAccept = text( "&OK" );						// Provide feedback to the user			MessageBox.critical( sMessage, sTitle, sAccept );						// We are done...			return;		}	}	// Finalize the function and invoke})( "Props/Maclean/Everyday" );

     

    I tried this (not sure if I put your addition in the right place), but it gives me an error on line 109 - ie the path - })( "Props/Maclean/Everyday" );

    Then I tried it with Rob's default path - })( "Character/DAZ People" ); - but that doesn't work, so I'm not sure what's happening.

  • maclean said:
    /********************************************************************** 	Copyright (C) 2002-2019 Daz 3D, Inc. All Rights Reserved. 	This script is provided as part of the Daz Script Documentation. The	contents of this script, and\or any portion thereof, may only be used	in accordance with the following license: 	Creative Commons Attribution 3.0 Unported (CC BY 3.0)	- http://creativecommons.org/licenses/by/3.0 	To contact Daz 3D or for more information about Daz Script visit the	Daz 3D website: 	- http://www.daz3d.com **********************************************************************/// Source: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/specific_ui/set_content_library_container/start// Define an anonymous function;// serves as our main loop,// limits the scope of variables(function( sPath ){		/*********************************************************************/	// String : A function for retrieving a translation if one exists	function text( sText )	{		// If the version of the application supports qsTr()		if( typeof( qsTr ) != "undefined" ){			// Return the translated (if any) text			return qsTr( sText );		} 		// Return the original text		return sText;	};		/*********************************************************************/	// Get the pane manager	var oPaneMgr = MainWindow.getPaneMgr();	// If the pane manager was not found	if( !oPaneMgr ){		// We are done...		return;	}		// Find the content library pane	var oPane = oPaneMgr.findPane( "DzContentLibraryPane" );	if( ! App.version64 >= 0x0004000800010033 ){	// If the pane was not found	if( !oPane ){		// We are done...		return;	}		// If the app version is 4.8.1.51 or newer	if( App.version64 >= 0x0004000800010033 ){		// Browse to the path		oPane.browseToPoserFolder( sPath );	// Otherwise	} else {		// Attempt to fall back		try {			// Get the asset manager			var oAssetMgr = App.getAssetMgr();						// Get the content manager			var oContentMgr = App.getContentMgr();						// Set the base to the first mapped Poser formats directory			var sBase = String("%1/Runtime/Libraries").arg( oContentMgr.getPoserDirectoryPath( 0 ) );						// Set the first value to the id of the top-level container,			// set the second value to the base path within that container			var aIdPath = [ oAssetMgr.getPoserDirID(), sBase ];			// Split the relative path into its individual parts			var aRelativeParts = sPath.split( "/" );			// Iterate over each part in the relative path,			for( var i = 0; i < aRelativeParts.length; i += 1 ){				// Push the full path of the "current" part onto the id path array				aIdPath.push( String("%1/%2")					.arg( sBase )					.arg( aRelativeParts.slice(0, i + 1).join( "/" ) ) );			}						// Cause the "current" container to change			oPane.browseToIDPath( aIdPath );						// Cause the "current" container to update			oPane.updateContainer( aIdPath );		// Handle errors		} catch( e ){			// Define the strings used to provide feedback			var sTitle = text( "Resource Error" );			var sMessage = text( "A newer version of %1 is required " +				"to execute this script.").arg( App.appName );			var sAccept = text( "&OK" );						// Provide feedback to the user			MessageBox.critical( sMessage, sTitle, sAccept );						// We are done...			return;		}	}	// Finalize the function and invoke})( "Props/Maclean/Everyday" );

     

    I tried this (not sure if I put your addition in the right place), but it gives me an error on line 109 - ie the path - })( "Props/Maclean/Everyday" );

    Then I tried it with Rob's default path - })( "Character/DAZ People" ); - but that doesn't work, so I'm not sure what's happening.

    You've deleted the stuff that would be run with the later app version, and in the process lost a } so the brackets no longer match. But I wasn't offering this as a fix, if you ran the script with the ! in an older DS it would try using the new one-step method (since the version number would not be greater than) and would error out, I was just saying that it seems to be an issue there in the latest DS (unfortyunately I never remember to keep the older versions to see if the last general release would work).

     

  • macleanmaclean Posts: 2,438

    Oh well, it doesn't seem it'll work for now, so I give up. I can't believe that after 3-4 days and all these posts a fairly basic concept (like bookmarks in a browser) is such an issue. I understand the reasons and glitches, but the whole scripting thing in DS just doesn't happen for me. I'm no code monkey, so I can only rely on the dev team or people like yourself, Richard. Unfortunately, these little things in DS can make my working life easier or more awkward. But hey, I get there in the end.

    Thanks for taking the time to help out.

  • Richard HaseltineRichard Haseltine Posts: 100,842
    edited October 2019

    Well, the script with the adapted input came from Rob. This issue, whether it's an error in the script or in DS or us, affects the plain vanilla version too - I'm guessing it's showing up a bug, or a change (remember thatb these pane methods are not documented and are use at your own risk), or possibly a slip as to which version number is required for it to work.

    Post edited by Richard Haseltine on
  • macleanmaclean Posts: 2,438

    Well, if Rob knows about it, I'm sure he'll get round to dealing with it at some point. It's a pretty minor issue, so I don't expect him to go right at it. No doubt it'll go on his list somewhere.

  • Rob has in fact updated the sample, and I can confirm it is now working in 4.12.0.86, so download that and change just the parameter passed on the last line (as above).

  • macleanmaclean Posts: 2,438

    Wowwww!!!! Got it working now. I downloaded the DS one too, just in case of changes, and it works too.

    THANK YOU, ROB!!! And you too, Richard!

    Happy Bunny!

Sign In or Register to comment.