How to get DzAsset via Filename?
mikek
Posts: 195
How can one get a DzAsset object from a filename (prefered absolute but can be relative)?
According to another post it should work with AssetMgr but I haven't manged to figure out how.
I have tried "getProductsForFiles", "findProductsForFile" and "findAssetsForFile" but they always return a empty array for booth absolute and relative filenames.
var oAssetMgr=App.getAssetMgr();var list=[];list.push(sFilename);//var oAssets=oAssetMgr.getProductsForFiles(list);var oAssets=oAssetMgr.findProductsForFile(list);//var oAssets = oAssetMgr.findAssetsForFile( list, false, true );print(oAssets.length);//print(oAssets.products.length);
Comments
So is your sample file part of a product as defined in your local database?
Yes but I figured now out it does work when using a duf file path from the first content folder but not if it's in the second.
So the question is now how can I get a DzAsset from a full filename if the duf file isn't in the first content folder?
Hmm, that sounds very odd - and not the behaviour I would have thought was intended, unless a base path for the search is being set.
Some samples touchin on this area http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/metadata/asset_categories/start
Thanks, it has the same issue. When using with this code something from the default content folder in daz studio like the included shader:
It works and will find it.
But if searching for a duf file in a different content folder the return array is always empty. My guess is daz possible uses a database for each content folder with the asset manager from App.getAssetMgr(); working (at least per default) only on the first database.
No, the database stores onbly relative paths and the system should check each content directory in turn until it finds a match (or runs out of content directories).
The script will specifically find all products that contain an asset with a given relative path in the database, it will then iterate over each product the assets were found in to build a full list, then iterate over each asset in those products and dump information about any asset with the same relative path in the context of that product. If you read the code and the comments you should be able to follow what it is doing.
You could also use DzAssetMgr::findAssetsForFile() if you prefer to come at it from the other direction, yielding an array of database results - the context of the product a given asset belongs to is still important to understanding where a given piece of metadata came from.
DzAssetMgr is for working with database records while DzContentMgr is for working with paths on disc. The former will help only to find assets for files that have been added to the database.
Ok, thanks I see now. I assumed adding in daz studio a new content directory would have the content added to the database but it doesn't. So the functions won't find the files if they are only added via content directory.