Assign category to file

rannar22rannar22 Posts: 6

I am trying to assign a set category to a spesifc file using a script.

unfortenetly so far i have only figured out how to read the categoris.

Post edited by rannar22 on

Comments

  • I assume you are aware of this sample, since you say you have managed to read categories. In any event, the DzAsset object http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/asset_dz has an addToCategories() method which shoudl be what you are looking for.

  • unforteently this is where i get stuck

    aAssets = oAssetMgr.findAssetsForFile(relPath, true, true);

    if(aAssets.length== 0){

    //i know i need to add addToCategories here 

    //aAssets.addToCategories(catName); 

    }

  • aAssets is an array, so you need a loop to go through the array one asset at a time (if you start you loop at 0 and check that the current value is less than aAssets.length then it will not need the if you have as it will just loop 0 times). You then, for each one, use an array of categories  to add that asset to one or more categories -

    for ( var n = 0 ; n < aAssets.length ; n++ ) {	aAssets[ n ].addToCategories( [ catName ] ); }

    for example.

  • i am sorry i wasn't clear before.
    I am trying to add a category to a specific file (based on relative path)
    that file has no assets at all, so obviously the aAssets[ 0 ] will not be defined when i try to use it.

  • Richard HaseltineRichard Haseltine Posts: 100,882
    edited December 2018

    You cannot categorise soemthing that is not an asset in the database - there'd be nothing to hang the category on. First you need to set the item as an asset, then you can categorise.

    Post edited by Richard Haseltine on
  • ok, and how can i do that?

Sign In or Register to comment.