Retrieve product preview image from DzProductAssetContainer instance

Hi,

I'm creating a simple script that would be an alternate "assets explorer", a sort of mix between the "Smart Content" tab and the "Content Library" panel.

Basing on the doc example (http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/metadata/list_product_files/start), I can retrieve each user owned product, and some of it's datas, but I can't find a simple way to locate the product preview image...

I tried several ways, but still no results, please help me! I need an img path, or a Pixmap, or anything that I can handle (path would be the best).

Each idea will be welcome, thanks!

Comments

  • PraxisPraxis Posts: 252
    edited March 2020

    Hi,

    I'm creating a simple script that would be an alternate "assets explorer", a sort of mix between the "Smart Content" tab and the "Content Library" panel.

    Basing on the doc example (http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/metadata/list_product_files/start), I can retrieve each user owned product, and some of it's datas, but I can't find a simple way to locate the product preview image...

    I tried several ways, but still no results, please help me! I need an img path, or a Pixmap, or anything that I can handle (path would be the best).

    Each idea will be welcome, thanks!

    I have not yet found a way to get the Path or Pixmap directly, but this clunky method does work:

    // Extract a copy of the image to your own disk file:var myFileSpec = '/test.png';App.getAssetMgr().findProductByStoreToken( 'DAZ 3D', '42071' ).getAssets()[0].icon.toImage().save( myFileSpec );

    It outputs this image:

    test.png
    91 x 91 - 7K
    Post edited by Praxis on
  • MCphylyss_2MCphylyss_2 Posts: 48
    edited March 2020

    Cool, thanks a lot for the quick answer! Not exactly what I wanted because it gives me the [0] asset icon, not the main product icon, but that will be enough for me to go on!

    Thanks again!

    Edit : "I have not yet found a way to get the Path or Pixmap directly" --> icon is thhe pixmap. So :

    App.getAssetMgr().findProductByStoreToken( 'DAZ 3D', '42071' ).getAssets()[0].icon

    gives me the pixmap. Real Thanks!

     

    Post edited by MCphylyss_2 on
  • PraxisPraxis Posts: 252
     

    Edit : "I have not yet found a way to get the Path or Pixmap directly" --> icon is thhe pixmap. So :

    App.getAssetMgr().findProductByStoreToken( 'DAZ 3D', '42071' ).getAssets()[0].icon

    gives me the pixmap. Real Thanks!

     

    Ahh... Thanks for that!

    I was wrong-footed because the following snippet says that .icon.className() is  'QPixmapWrapper' (not 'Pixmap'):

    print( App.getAssetMgr().findProductByStoreToken( 'DAZ 3D', '42071' ).getAssets()[0].icon.className() );

    It seems they are in fact the same thing - the DAZ docs for Pixmap say: "DAZScript wrapper for QPixmap".

    Happy coding...

     

     

  • MCphylyss_2MCphylyss_2 Posts: 48
    edited March 2020

    I'm a bit lost in the middle of nowhere...

    DzProductAssetContainer class has an attribute named "icon". But I don't know how to use it.

    When I print it, Daz says it's a Qvariant(icon) object, not a pixmap. I don't know how to convert it...

    When I print (JSON.stringify(oProduct.icon)), it displays an empty object {}

    When I try looping over its attributes/methods, the object seems to be empty.

    When I try something like : myDzLabel.pixmap = oProduct.icon; it does nothing...

    When I try oProduct.icon.toPixmap(), I get an "undefined" error (the Qt doc says that Qvariant icon objects should have a toPixmap() method)

    I tried a lot of things like these, but nothing works... Shouldn't there be a simple way to get the product icon?? I can get the icon size by oProduct.getIconSize(), but not the icon itself?

    Am I doing something wrong?

    For now, I found a dirty way : oProduct.getMetadataXMLPath() gives me the relative path of the product metadata file. Product Icon seems to have the exact same path (except for the extension), so I can load the image, but I still have to find the absolute path acording to multiple user daz Libs + Cloud installed products wich have a particular path management etc... plus it seems that oProduct.getMetadataXMLPath() gives sometimes wrong paths...

    Here's the code if someone is interested :

     

    // Defining available Daz lib pathsvar lib_paths = {'E:/10 - Daz resources':1}// var clouds = loadfile('clouds');/* clouds is a var that holds each cloud installed products folder name, foreach available daz lib.   It looks like : var clouds = {'E:/10 - Daz resources' : ["1_18717", "1_18741", "1_18910", ...]};   We could list each "data/cloud" folders in real time, but it's really slow, so it's better to precalculate that var...*/// Checks if a file existsfunction isfile(path){return new DzFileInfo(path).isFile();}// Searches a file in each "Daz_lib/runtime" and "Daz_lib/data/cloud/xxx/runtime" folder, by its relative pathfunction find_file(relative_path){	for (lib in lib_paths){		if (isfile(lib+relative_path)) return lib+relative_path;		else {			for (var nfolder=0; nfolder<clouds[lib].length; nfolder++){				var path = lib+'/data/cloud/'+clouds[lib][nfolder]+relative_path;				if(isfile(path)) return path;}}}	return "None";}// Searches product preview imagefunction find_product_icon(oProduct){	var pixmap = "None";	var metafile_path = oProduct.getMetadataXMLPath(); 	var relative_img_path = metafile_path.replace('.dsx','').replace('.dsa','');	var absolute_img_path = find_file(relative_img_path+'.jpg');	if (absolute_img_path=="None") absolute_img_path = find_file(relative_img_path+'.png');	if (absolute_img_path=="None") return oProduct.getAssets()[0].icon;	return new Pixmap(absolute_img_path);}

     

    But that method is uggly, freakin slow, and so complicated for a simple request that just should looks like : oProduct.getIcon() !!

    If someone has a better way, please tell me!

    Post edited by MCphylyss_2 on
  • PraxisPraxis Posts: 252
    edited March 2020

    DzProductAssetContainer class has an attribute named "icon". But I don't know how to use it.

    How do you want to use it?

    icon.toImage().save() lets you export the image.

    Here is an example of how to display the icon:

    var wDlg = new DzDialog( MainWindow );var wLayout = new DzHBoxLayout( wDlg );wLayout.autoAdd = true;var wGrp = new DzHGroupBox( wDlg );wGrp.insideMargin  = 2;wGrp.insideSpacing = 5;var wListView = new DzListView( wGrp );wListView.minWidth = 200;wListView.minHeight = 100;      // Corrected 2020-03-21var oProduct = App.getAssetMgr().findProductByStoreToken( 'DAZ 3D', '42071' );    // Genesis 8 Starter Essentialsif( oProduct ) {  wGrp.title = oProduct.title + '  ( '+oProduct.store+': '+oProduct.token+' )';  wListView.addColumn( 'Asset Icon' );    // Column 0  wListView.addColumn( 'Asset Name' );    // Column 1  wListView.addColumn( 'URL' );           // Column 2  var aAssets = oProduct.getAssets();  if( aAssets ) {    for( var J = 0; J < aAssets.length; J++ ) {      var oAsset = aAssets[ J ];      var wItem = new DzListViewItem( wListView, -1 );     // ID = default = -1      // !!! This works as expected, except that a seemingly random set of the Assets display the      //  default "Exclamation Mark" Icon.  That set changes at each execution.      wItem.setPixmap( 0, oAsset.icon );      wItem.setText( 1, oAsset.displayName );      wItem.setText( 2, oAsset.url );    }  }}wDlg.exec();

     

    dsa
    dsa
    ViewAssets.dsa
    1K
    Post edited by Praxis on
  • Thanks for the perfect example! I will learn a lot from this in the use of GUI... but my problem is for the product icon, not the asset one... It might be a bug in Daz API, since oAsset.icon can't be used the same way as oProduct.icon... I'm using Daz 4.10, I'll try on newer and older versions, but that's a real problem for me : I'm using other Daz functions that can be broken according to the Daz version (like the DAE silent exporter...)

    Your exemple works perfectly on my PC, but if I replace "oAsset.icon" by "oProduct.icon", it crashes because oProduct.icon exists, but seems to be an empty Qvariant object.

    In any case, thanks again for your help!

  • PraxisPraxis Posts: 252
    edited March 2020

    You are welcome.

    For the Product image, use new Pixmap( oProduct.iconPath )

    (I just found this now, by inspection of DzProductAssetContainer keys).

     

    Post edited by Praxis on
  • This doesn'work for me, I'll try it on Daz 4.12 as soon as I could (I'm limited on internet bandwidth right now), but wow, if it works, that's SO COOL! exactly what I was looking for.

    Real thanks, once again^^

  • I just updated to Daz 4.12, and your solution perfectly works!

    I'm happy^^

    Thanks for your time!

Sign In or Register to comment.