Congratulations! You are a March Madness BONUS BUYER!

Enjoy 10% OFF* ALL PURCHASES STOREWIDE or enjoy 30% OFF items with a SKU number lower than 16000 & 30% OFF items from Runtime DNA.

Buy 2 or more Newly Mad new release and get an EXTRA 30% OFF Newly Mad releases.

Offer valid for intended recipient only
* 10% discount DOES apply to Gift Cards and Memberships. **Items must be in cart simultaneously for discount to apply.
[ collapse ]

Adding file content overlays by script

Richard HaseltineRichard Haseltine Posts: 32,468

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?


  • rbtwhizrbtwhiz Posts: 1,136
    edited September 2013

    // 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.fetchByPath( sSourceFileAbsPath );
    // If there are any instances
    if( oDBObjectList.length > 0 ){
     // Get the first one
     oContentInstance = 0 );
     // Get the content object that this is an instance of
     var oContent = oContentInstance.getContent();
     // Fetch the record
     // 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.createFromPath( sLoaderFileAbsPath );
     // 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


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

    Post edited by rbtwhiz on
  • Richard HaseltineRichard Haseltine Posts: 32,468
    edited December 1969

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

  • Richard HaseltineRichard Haseltine Posts: 32,468
    edited December 1969

    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

    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?

  • rbtwhizrbtwhiz Posts: 1,136
    edited December 1969

    // 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(sSourceBasePath, false);
    // Get a content folder for the target base path; don't create it if it doesn't exist
    var oDBTargetContentFolder = oDBContentFolder.findContentFolder(sTargetBasePath, false);
    // 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.basePathID, sTargetBasePath.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)...


  • Richard HaseltineRichard Haseltine Posts: 32,468
    edited December 1969

    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.

  • rbtwhizrbtwhiz Posts: 1,136
    edited December 1969

    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 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.


  • Richard HaseltineRichard Haseltine Posts: 32,468
    edited December 1969

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

Sign In or Register to comment.