Digital Art Zone

 
     
Adding file content overlays by script
Posted: 12 September 2013 03:13 PM   [ Ignore ]
Administrator
Avatar
RankRankRankRank
Total Posts:  14829
Joined  2003-10-09

I have a script that writes a loader script for each native file in a destination tree and places it, with an optional dummy pz2 file, in a chosen location - the idea being to allow users (me) to rearrange their content, in the form of the loader scripts, without breaking the CMS, on the original, unmoved files. It seems to be working but now I’m wondering if I can write a script to match the loader with the original file (which should be possible by parsing it if nothing else), get the content type from the database, and associate it with the loader or the dummy pz2 so that i get the type overlay in the Content Library - without having to give the file all of the CMS entries for the original (it would be a pain if noth the real file and the loader appeared in the Smart Content pane.

So, is it possible (without Rob’s having to write an essay in his copious spare time) to get a file’s type from the CMS, and to give a file without an entry in the CMS enough information to show the type overlay without appearing in the same searches as the source file, using scripting?

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile
 
 
Posted: 12 September 2013 11:48 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRank
Total Posts:  348
Joined  2003-10-09
// The absolute path of the source file
var sSourceFileAbsPath "";

// The absolute path of the loader file
var sLoaderFileAbsPath "";

// Create a db content instance object
var oContentInstance = new DzDBContentInstanceTable();
// Fetch db content instance objects for the source file
var oDBObjectList oContentInstance.fetchByPathsSourceFileAbsPath );
// If there are any instances
if( oDBObjectList.length ){
 
// Get the first one
 
oContentInstance oDBObjectList.at);
 
// Get the content object that this is an instance of
 
var oContent oContentInstance.getContent();
 
// Fetch the record
 
oContent.fetch();
 
// Get the content type id
 
var nTypeId oContent.contentType;
 
 
// Create the instance record for the loader file; creates the content record if needed
 
oContentInstance oContentInstance.createFromPathsLoaderFileAbsPath );
 
// If we have a database object; the CMS is running
 
if( oContentInstance ){
  
// Get the content object that this is an instance of
  
oContent oContentInstance.getContent();
  
// Set the type on the file
  
oContent.contentType nTypeId;
  
// Notify everything that is listening of updates
  
oContent.update();
 
}

-Rob

NOTE: You will need to refresh the Content Library Asset View to see the change.

 Signature 

- Documentation Center
- Install Manager
- DAZ Studio 4.x
- DSON Importer
- DSON File Format Specification

Profile
 
 
Posted: 13 September 2013 08:04 AM   [ Ignore ]   [ # 2 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  14829
Joined  2003-10-09

Thank you, I was expecting it to be much more complex.

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile
 
 
Posted: 17 September 2013 01:40 PM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  14829
Joined  2003-10-09

OK, that works - but as feared from having to feed in the absolute paths, it works only if the content is in the content folder I installed to, which it isn’t a I install to a working folder, make sure everything is working, and then move to the real folder (the intent being to keep relative paths intact). That’s a bit of a pain, though for myself I could live with uninstalling and reinstalling after testing (assuming there were no bugs I needed to fix, at least) but that’s a bit of a performance to make available to others. If I add the original absolute path to my loader script, so that the script for copying the overlay has both the original, stored in the DB path and the current, obtained from DzContentMgr via the relative path, locations is there a way to update the record for the main file so that it points to the current location and not to the temp install folder? That is

Given:
install content directory
current content directory
relative path

Can I:
update CMS to use current content directory/relative path instead of install content directory/relative path without breaking the rest of the CMS record?

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile
 
 
Posted: 19 September 2013 01:39 AM   [ Ignore ]   [ # 4 ]
Administrator
Avatar
RankRank
Total Posts:  348
Joined  2003-10-09
// The original base path of the file(s)
var sSourceBasePath "";
// The new base path of the file(s)
var sTargetBasePath "";

// Create a db content folders object
var oDBContentFolder = new DzDBContentFoldersTable();
// Get a content folder for the source base path; don't create it if it doesn't exist
var oDBSourceContentFolder oDBContentFolder.findContentFolder(sSourceBasePathfalse);
// Get a content folder for the target base path; don't create it if it doesn't exist
var oDBTargetContentFolder oDBContentFolder.findContentFolder(sTargetBasePathfalse);
// If we've got a source content folder and a target content folder
if( oDBSourceContentFolder && oDBTargetContentFolder ){
 
// Replace all occurances of the source base path with the target base path
 
oDBContentFolder.replaceAllMatchingBasePaths(oDBSourceContentFolder.basePathIDsTargetBasePath.basePathID);

This is equivalent to navigating to a Category or Product in the Content Library pane, right clicking in the Asset View and choosing Database > Edit Base Path(s)...

-Rob

 Signature 

- Documentation Center
- Install Manager
- DAZ Studio 4.x
- DSON Importer
- DSON File Format Specification

Profile
 
 
Posted: 19 September 2013 05:27 AM   [ Ignore ]   [ # 5 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  14829
Joined  2003-10-09

OK, thank you, that should help - though it does appear that it will be a universal replace, which would work OK for me but might not be for other users.

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile
 
 
Posted: 19 September 2013 09:09 AM   [ Ignore ]   [ # 6 ]
Administrator
Avatar
RankRank
Total Posts:  348
Joined  2003-10-09

The question prompted me to look at the DzDB* wrapper classes. I noticed that the DzDBContentFoldersTable wrapper was missing a few more recent functions that provide individual file/directory access.  I’ve added those functions to the wrapper, but you being able to access them obviously requires a new build.  Right now that means it won’t be available until a build after the 4.6.1.14 Release Candidate transitions to General Release. As the additions pose very little risk, IF we end up needing to address any show-stopper bugs in the RC, I’ll merge them into the 4.6.1.x branch for the build… otherwise you’ll have to wait for the next release cycle. Obviously, once you have that build and you use said function(s), the users of your script must be running the version [or later] that provides the access… which means you should guard against an earlier version; see this example.

-Rob

 Signature 

- Documentation Center
- Install Manager
- DAZ Studio 4.x
- DSON Importer
- DSON File Format Specification

Profile
 
 
Posted: 19 September 2013 12:58 PM   [ Ignore ]   [ # 7 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  14829
Joined  2003-10-09

Thanks Rob - I was wondering the other day how to get a human-friendly version number from the raw value.

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile