Retrieve product preview image from DzProductAssetContainer instance
MCphylyss_2
Posts: 48
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
I have not yet found a way to get the Path or Pixmap directly, but this clunky method does work:
It outputs this image:
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 :
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'):
It seems they are in fact the same thing - the DAZ docs for Pixmap say: "DAZScript wrapper for QPixmap".
Happy coding...
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 :
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!
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:
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!
You are welcome.
For the Product image, use new Pixmap( oProduct.iconPath )
(I just found this now, by inspection of DzProductAssetContainer keys).
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!