[SOLVED] : Can't add new asset to a category

nartoveugenenartoveugene Posts: 8
// get pane managervar oPaneMgr = MainWindow.getPaneMgr();// get the content lib panevar oPane = oPaneMgr.findPane("DzContentLibraryPane");// get selected assetvar aAssets = oPane.getSelectedAssets();// get the path of selected assetvar relPath = aAssets[0].getRelativeFilePath();// get the categories the selected asset is stored invar getCats = aAssets[0].userCategories;// show the categories the selected asset is stored inprint(relPath)var clearGrp = aAssets[0].clearGroup();// set the desired category for the selected assetvar setCat = aAssets[0].addToCategories(["MyCat", "MyCat/Hair", "MyCat/Hair/Bob" ]);

I can't set a category for a newly created asset for some reason. I found out that I can do it just in two cases:
1) If I manually categorize it once and then the script works
2) if I set parameters such as "type" or "audience" in content DB editor for this asset. After that the script works fine.

I can't set content type or audience with script afaik. How can I handle it and categorize my new asset without these two steps I mentioned above?

upd: Probably the problem is that I saving my assets with a script from samples and assets saved in that fashion are not equipped with type data, they don't have the colored badge "pose" in the content library panel. How to force this to mark new assets?

Solution: Mr. Richard gave me a perfect hint. It's better not to use pane flow, and use a relative path instead. This piece of code worked fine. Thanks again!

var oAssetMgr = App.getAssetMgr();aAssets = oAssetMgr.findAssetsForFile("/Animations/Dance/my_file.duf",true,true);aAssets[0].addToCategories(["MyCat", "MyCat/Hair", "MyCat/Hair/Bob" ], true);

 

Post edited by nartoveugene on

Comments

  • DzAsset, as far as I can see, gives most or all of the tools you need to add or remove categories from an asset. Going through the panes is rarely if ever guaranteed to remain the same between versions. Also see http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/start#categories


  • Thanks for your reply, Richard!

    Yeah, I tried to use DzAsset like in my attached code snippet, but the thing is the script won't add my asset to a new directory if it wasn't previously categorized manually, or edited via DB editor. I've attached screenshots for illustrating what I mean ( 1 - https://ibb.co/6WYd4Bt , 2 - https://ibb.co/HXctjb2 ).

    Also, I tried to find the way to specify asset type or category during the saving process performed with script from samples section but found out that there are no such settings for class "DzPoseAssetFilter" and "DzNodeSupportAssetFilter" does have an option to specify category or content type, but it gives no chances to save animated pose.

    Also, I checked the product for asset that can be categorized via script and one that can not. The first asset has 0 products assigned, the second has a product called "LOCAL USER". But I have no idea how to assign product using DzPoseAssetFilter class.

  • So the issue is when the item isn't yet set as an asset, or only when it is an uncategorised asset?

  • As far as I understand, after saving the preset, this item immediately becomes an asset, but it will not be able to be categorized with .addToCategories in the following cases:

    1) When .addToCategories is applied to an object that was retrieved using Pane and .getSelectedAssets()
    2) When the asset has not been manually categorized beforehand or has no additional metadata (e.g. compatibility, product, etc.).

    In my case .addToCategories did its job when I assigned a product .createProductFromAssets and referenced the object retrieved via .findAssetsForFile

Sign In or Register to comment.