Get assets of certain type from Content Library

morkmork Posts: 278

Greetings!

I try to fetch all Expressions of Genesis 3 from the Content Library.

I use the DzContentMgr to try to locate those expression packages, but it seems like I'm operating on the file level, whereas I'd like to operate on the "Content Library" level, since things there are not mapped 1:1 to directories, at least for the cloud content.

Two and a half questions:

1. I assume cloud content can be encrypted, there is no way for me to process the raw files then? If so, I will need to ignore cloud content completely, unfortunately.
    1b. Can I detect if something is encrypted? I then could at least provide functionality for the unencrypted content.
2. How do I find products within the Genesis 3 Female Expressions folder? From the content library, not filesystem.

I have this right now:

var contentManager             = App.getContentMgr();
var folderExpressionNative = contentManager.findFile("data/DAZ 3D/Genesis 3/Female/Morphs/", DzContentMgr.NativeDirs);


This kind of works, but it is not what I'm looking for. It will return me all the morphs, and I have no way (that I know of) to tell which ones are expressions.
It'd be easier if I could navigate on the Content Library level, where those products are mapped to a known directory structure.
Any idea how I can do that? :)

Thank you very much!
-mork

 

Edit 1:

As for question 2, I made a little bit of progess - I think.
I use this example here to fetch the Products from the AssetMgr:
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/metadata/list_products/start

Now I need to filter them by Expressions. I try this right now using

oProduct.getCategories();

but this works for the very first item only, everything else throws an error like

dzpostgresqlobjectdatabase.cpp(37): db fetch error: No results fetching tblCategories with id: 2198

I try to bite myself through it, but any help is much appreciated. :)

Post edited by mork on

Comments

  • morkmork Posts: 278
    edited July 2017

    To whom it may concern, here is a brute force approach.

    It takes about 7 seconds for a product library with 29 items. I expect it to take a couple of minutes on a full blown product library, at least. That is way too long for such a simple task. A simple DB query should return the same in a couple of miliseconds.

    But that's all I got so far. The problem with it all is not coding it, problem is to understand how it all connects together first, find out about undocumented features and find out the DAZ way to do things. I'm progressing slowly but steadily. Be afraid, be very afraid. :-D

    Edit:

    It's actual 38 products, the 29 is the amount of folders returned by oProductsTop.getNumChildContainers()
    I'll update the script with some other fixes and improvements at a later time.
     

    // DAZ Studio version 4.9.4.117 filetype DAZ Script(function(){    var aExpressions;    wDlg = new DzDialog();    wDlg.caption = "Search Asset BruteForce";    wDlg.width   = 800;    wDlg.height  = 600;    // LEFT COLUMN    wLyt1 = new DzHBoxLayout(wDlg);    wLyt1.autoAdd = true;    wLyt1.margin  = 8    wLyt1.spacing = 8;    wLyt1.columns = 2;        // left column - source selection. add another HGroup        wLytLeft = new DzVGroupBox(wDlg);        // add text above listbox        var sLabelFoundExpressions  = new DzLabel(wLytLeft);        sLabelFoundExpressions.text = "Found G3 Expressions:";        // add listbox        wList = new DzListBox(wLytLeft);        // make entries in the left list clickable        // -1 if nothing clicked, index otherwise.        // index maps to aExpressions, populated by findExpressions() below.        connect(wList, "clicked(int)", convertExpression);    // EO LEFT COLUMN    // RIGHT COLUMN    wLyt2 = new DzVGroupBox(wDlg);    wLyt2.autoAdd = true;    wLyt2.margin = 8    wLyt2.spacing = 8;    wLyt2.rows = 2;        // Buttons (ok, cancel)        bOk = DzPushButton(wLyt2);        bOk.text = "Ok";        connect(bOk, "clicked()", function()  {            MessageBox.information("Depending on your library size, this can take quite a while!", "", "");            // lock ok button            bOk.enabled = false;            aExpressions = findExpressions();            populatePanels(aExpressions);            // unlock ok button            bOk.enabled = true;        });        bCancel = DzPushButton(wLyt2);        bCancel.text = "Close";        connect(bCancel, "clicked()", function()  {            //MessageBox.information("Abort!", "", "");            wDlg.close();        });        // Label above log        var sLabelLog   = new DzLabel(wLyt2);        sLabelLog.text = "Log-Output:";        // Add log box        var oLogListBox           = new DzListBox(wLyt2);        oLogListBox.selectionMode = oLogListBox.NoSelection;    // EO LEFT COLUMN    // Fire up our new GUI!    wDlg.exec();    /*======================================================    =            HELPER FUNCTIONS/METHODS BELOW            =    ======================================================*/    /*----------  Write something to the logbox  ----------*/    function log(str)  {        if (str.length == 0) return;        oLogListBox.insertItem(str);    };    /*----------  Populate the left panel with expression products we found  ----------*/    function populatePanels(aData)  {        // clear panels        wList.clear();        if (!aData.length) return false;        // populate        for (var i=0; i<aData.length; ++i)  {            wList.insertItem(aData[i].title);        }    }    /*----------  Convert an expression, clicked in left panel  ----------*/    function convertExpression()  {        if (arguments[0] == -1) return false;        if (arguments[0] >= aExpressions.length)            return false;        log(aExpressions[ arguments[0] ].title);        // magic be here    }    /*----------  Try to determine by checking some strings  ----------*/    function isExpression(aAssetData)  {        if( Object.prototype.toString.call( aAssetData ) === '[object Array]')  {            //log("Is an array");            var r;            for (var i=0; i<aAssetData.length; ++i)  {                r = isExpression(aAssetData[i]);                if (r) return true;            }            return false;        } else {            //log("Is not an array "+(typeof aAssetData));        }        // verify that it is a G3 Female expression        if (aAssetData.originalPath.indexOf('Genesis 3 Female') == -1)  {            return false;        }        // originalPath        if (aAssetData.originalPath.indexOf('Expressions') != -1)  {            return true;        }        // categories        if (aAssetData.categories.length)  {            for (i=0; i<aAssetData.categories.length; ++i)  {                if (aAssetData.categories[i].indexOf('Expressions') != -1)                    return true;            }        }        // auto keywords        if (aAssetData.autoKeywords.length)  {            for (i=0; i<aAssetData.autoKeywords.length; ++i)  {                if (aAssetData.autoKeywords[i].indexOf('Expressions') != -1)                    return true;            }        }        return false;    }    /*----------  Locating of G3F Expressions - BruteForceStyle ----------*/    function findExpressions()  {        var aProductsExpression = [];        // Get the asset manager        var oAssetMgr = App.getAssetMgr();        // If the pane was not found        if ( !oAssetMgr ){            // We're done...            log("! No asset manager context");            return;        }        // Get the top level asset container for products        var oProductsTop = oAssetMgr.getProducts();        // If we do not have the products container        if( !oProductsTop ){            log("! No products found at top level");            // We're done...            return;        }        var bInstalled = true; // locate installed products only?        var oIntermediate, oProduct;        var nProducts;        var nIntermediates = oProductsTop.getNumChildContainers();        // show the user the progress, using one of these undocumented API features        startProgress( "Searching expressions within "+nIntermediates+" products.\nPlease wait...", nIntermediates, true, true );        for( var i = 0; i < nIntermediates; i += 1 )  {            // Get the 'current' intermediate container            oIntermediate = oProductsTop.getChildContainer( i );            // Get the number of product containers within the intermediate            nProducts = oIntermediate.getNumChildContainers();            // Iterate over all product containers            for( var j = 0; j < nProducts; j += 1 )  {                // Get the 'current' product container                oProduct = oIntermediate.getChildContainer( j );                // If we only care about installed products,                // and the 'current' one isn't                if( bInstalled && !oProduct.isInstalled ){                    // Next!!                    continue;                }                // Get the assets in the product                // Note that DAZs own content usually has no assets                var aAssets = oProduct.getAssets();                if (aAssets.length == 0)  {                    // skip DAZ content                    log("Skipping: "+oProduct.title);                    continue;                }                if (!isExpression(aAssets))  {                    continue;                }                // add to array that we return upon finish                aProductsExpression.push(oProduct);                // let the user know we found something                App.statusLine("Found: "+oProduct.title, false );            }            // increment status bar            stepProgress( 1 );        }        // close status bar        finishProgress();        return aProductsExpression;    }// Finalize the function and invoke})();

     

    Post edited by mork on
  • morkmork Posts: 278
    edited July 2017

    For some odd reason, oAssetMgr.getProducts() only returns me the products of 2 content library paths, where I have three:

    1. Daz Connect Data (works)
    2. DAZ Studio Formats
       a) myuser/Documents/DAZ 3D/Studio/My Library/ (works)
       b) Public/Documents/My DAZ 3D Library/  ( does not work )

    Any idea? I already restarted Studio, I can see the content in the Content library, but the asset manager does not know about it for some odd reason?

     

    Edit:
    It does search that path, but for some reason it insist that the product is not installed. I installed it via DIM (as I do most of the time), I also re-installed it, restarted database, restarted DAZ, but it insists that the product is not installed. But it is, or, should I say, it should be.


    Edit2:
    Not sure what happened, but I reimported the content database and it fixed it. Hopefuly this was only a hickup, no clue what I can do if that happens to someone else.

    Post edited by mork on
Sign In or Register to comment.