Quantcast
Channel: Daz Script Developer Discussion - Daz 3D Forums
Viewing all articles
Browse latest Browse all 1067

How to use DzAssetMgr.searchForAssets()?

$
0
0

Hello all,

I am trying to use DzAssetMgr.searchForAssets() this is my code.

// DAZ Studio version 4.21.0.5 filetype DAZ Script
var assetManager = App.getAssetMgr();

var searchResult = assetManager.searchForAssets(
  'lazair', // filteText:
  search string ['/Default/Scenes'], // categories: Array of categories paths
  ['/Genesis 8', '/Genesis 8.1'], // compatibilityBases: compatibility bases Array
  ['scene'], // contentTypes: content types Array
  1 // Sort by name
);

var assetsCount = searchResult.getNumAssets();
print("Assets found: " + assetsCount);

var containersCount = searchResult.getNumChildContainers();
print("Child containers found: " + containersCount);

This is the output.

Executing Script...
Assets found: 0
Child containers found: 0
Result: 
Script executed in 0 secs 2 msecs.

The asset I am attempting to search for is located at "Scenes/moka_lazair_01.duf" relative to one of the Content Library directories I set and "Content Library" pane can find it both in "File" and "Database" search mode using either "moka" or "lazair" as the search string.

For the contentTypes parameter I used either "Scene" and "scene" with the same result.

Categories and Compatibility Bases paths arrays are not invented but obtained with the following two scripts.

// DAZ Studio version 4.21.0.5 filetype DAZ Script
var assetManager = App.getAssetMgr();
var categoriesContainer = assetManager.getCategories();

categoriesContainer.getChildContainers().forEach(
	function (container) {
		print('\tpath: ' + container.getPath());
		print('Child containers count: ' + container.getNumChildContainers());
		
		container.getChildContainers().forEach(
			function (childContainer, index) {
				print('\tPath ' + index + ': ' + childContainer.getPath());
			}
		);
	}
);
// DAZ Studio version 4.21.0.5 filetype DAZ Script
var assetManager = App.getAssetMgr();
var compatibilityBasesContainer = assetManager.getCompatibilityBases();

print('Compatibilily Base container informations');
print('{');
print("\tpath: " + compatibilityBasesContainer.getPath());
print("\tChildren count: " + compatibilityBasesContainer.getNumChildContainers());
print('}');

compatibilityBasesContainer.getChildContainers().forEach(
	function (container) {
		print('\tChild container informations');
		print('\t{');
		print('\t\tpath: ' + container.getPath());
		print('\t}');		
	}
);

Despite this I am not sure of some things.

  1. Since the file is a Scene I created, does it have any Compatibility Base?
  2. If not, what value should I pass ass the compatibilityBases parameter? I attempted to pass null and it is not valid (quite weird behaviour for a JavaScript API); empty Array ([]) is accepted but useless.
  3. I have the same doubts for categories parameter...
  4. One of ['Scene'] or ['scene'] should be ok but: which one is actually correct?

I found the list of types with this script.

var assetManager = App.getAssetMgr();
var types = assetManager.getTypes();

types.forEach(
	function (type) {
		print('Type: ' + type);
	}
);

And it returns "Scene". Though in the "Info" tab at the bottom of the "Content Library" pane displays "scene" as the value of the "type" property of the asset.

P.S. There is something that eats new line characters in <pre><code>...</code></pre> combo in this forum. Database side stored source codes are clearly safe because I can edit them with new line characters untouched therefore I guess it is a render problem. Also the code formatter takes everything as a comment if there is a comment in the beginning of the code.


Viewing all articles
Browse latest Browse all 1067

Trending Articles