Remove Product

Anyone knows how we can remove a product correctly using C++?

        DzAssetMgr* assetMgr = dzApp->getAssetMgr();
        DzTopLevelAssetContainer* products = assetMgr ? assetMgr->getProducts() : nullptr;
        if (products)
        {
            DzAbstractAssetContainerList children;
            if (products->getChildContainers(children))
            {
                for (int i = 0; i < children.count(); ++i)
                {
                    DzAbstractAssetContainer* child = children[i];
                    if (child && child->getID().toString() == globalID)
                    {
                        DzAbstractAssetContainer* parent = child->getOwner();
                        if (parent)
                        {
                            parent->removeChildContainer(child);
                        }
                        break;
                    }
                }
            }
        }

 

Comments

  • MehdiZangenehBarMehdiZangenehBar Posts: 139
    edited August 31

    OK, I figure it out how to remove a product, but how we can refresh smart content?
     

        QString globalID = jsonObj.property("globalID").toString();
        if (globalID.isEmpty())
        {
            return;
        }
    
        DzAssetMgr* oAssetMgr = dzApp->getAssetMgr();
        if (!oAssetMgr)
        {
            return;
        }
    
        DzTopLevelAssetContainer* oProductsTop = oAssetMgr->getProducts();
        if (!oProductsTop)
        {
            return;
        }
    
        DzAbstractAssetContainerPtr oIntermediate, oProduct;
    
        int nIntermediates = oProductsTop->getNumChildContainers();
        for (int i = 0; i < nIntermediates; i += 1)
        {
            oIntermediate = oProductsTop->getChildContainer(i);
            if (!oIntermediate)
            {
                continue;
            }
    
            int nProducts = oIntermediate->getNumChildContainers();
            for (int j = 0; j < nProducts; j += 1)
            {
                oProduct = oIntermediate->getChildContainer(j);
                DzProductAssetContainer* product = qobject_cast(oProduct);
                if (!product)
                {
                    continue;
                }
    
                QString guid = product->property("guid").toString();
                if (guid == globalID)
                {
                    oIntermediate->removeChildContainer(product);
                    return;
                }
            }
        }
    
    Post edited by MehdiZangenehBar on
  • what you mean by "AI"? I don't get it?!

  • Richard Haseltine said:

    The AI seems to have drawn pretty thoroughly on http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/metadata/list_products/start

    Did you even undrstand what is my question? I am talking about how to properly REMOVE a product, so what is point of AI here?

     

  • barbultbarbult Posts: 26,156
    I think Richard assumes you used AI to write the script you posted. He is linking to Daz sample script. I think that Richard thinks AI took it from that sample and fed it to you.
  • barbult said:

    I think Richard assumes you used AI to write the script you posted. He is linking to Daz sample script. I think that Richard thinks AI took it from that sample and fed it to you.

    This is offensive to someone who spent several days working on this code to make it workable!

  • Anyway, now my concern is how to refresh panes properly to reflect that update. if someone can talk about that topic, it helps me a lot.

  • Sorry, I was getting this confused with another thread by someone who doid use AI to generate a script. But still, you should provide a proper acknowledgement of the source scripts you useas a reference - that is how theya re licensed. 

  • Richard Haseltine said:

    Sorry, I was getting this confused with another thread by someone who doid use AI to generate a script. But still, you should provide a proper acknowledgement of the source scripts you useas a reference - that is how theya re licensed. 

    OK, no problem,
    This is my style that I send anything I found myself to help everyone here, so we able to inceremantally reach the goal together.
    In this case. I used that sample code for sure without even renaming variables. I translated that dazscript code to C++ to retrive the product and delete it. but problem is SDK and dazscript are not exactly the same. using dazscript we can simply do:
     

    var asset_manager = App.getAssetMgr();
    var product_guid = "f6429d43-7938-4bb8-be76-ace1cb0792c6";
    var product = asset_manager.findProductByGuid(product_guid);
    product.remove()
    

    But problem is, in C++ version Smart Content and Content Library panes will not be updated, so we should do some more codes to update them.

  • Despite my intentions I have never engaged with the SDK so I am of little use. In this case you are already doing what I would try, looking for parallels with the scripting engine.

  • vectorinusvectorinus Posts: 138
    I recently turned to AI for help, trying to solve a certain geometric problem using MaxScript. It is an original complex problem, and I knew that AI would not be able to provide me with a complete solution, since the necessary information is not available anywhere on the Internet (I checked). However, AI helped me a lot in many small areas of MaxScript related to my main task. All the information it provided me is freely available in the online help of Autodesk Company. And I used this help before. But the AI's answers, as it turned out, are much better structured, compact and at the same time more comprehensive. If it were not for AI, I would probably have solved my problem five times longer. And during this time, my brain would have become tired due to the waste of energy on solving numerous small subproblems. In my case, AI acted not as a solver, but as a very qualified assistant. Previously, I had to crawl through online help and related forums on the internet like a turtle.
Sign In or Register to comment.