<commit_before>#include "AssetSubCommandLoadAsset.h"

#include <maya/MFileObject.h>
#include <maya/MGlobal.h>
#include <maya/MPlug.h>
#include <maya/MPxCommand.h>

#include "AssetNode.h"
#include "AssetSubCommandSync.h"
#include "util.h"

AssetSubCommandLoadAsset::AssetSubCommandLoadAsset(
        const MString &otlFilePath,
        const MString &assetName
        ) :
    myOTLFilePath(otlFilePath),
    myAssetName(assetName),
    myAssetSubCommandSync(NULL)
{
}

AssetSubCommandLoadAsset::~AssetSubCommandLoadAsset()
{
}

MStatus
AssetSubCommandLoadAsset::doIt()
{
    MStatus status;

    // create houdiniAsset node
    MObject assetNode = myDagModifier.createNode(AssetNode::typeId, MObject::kNullObj, &status);
    CHECK_MSTATUS_AND_RETURN_IT(status);

    // rename houdiniAsset node
    status = myDagModifier.renameNode(assetNode, myAssetName);
    CHECK_MSTATUS_AND_RETURN_IT(status);

    // set otl file attribute
    {
        MPlug plug(assetNode, AssetNode::otlFilePath);
        status = myDagModifier.newPlugValueString(plug, myOTLFilePath);
        CHECK_MSTATUS_AND_RETURN_IT(status);
    }

    // set asset name attribute
    {
        MPlug plug(assetNode, AssetNode::assetName);
        status = myDagModifier.newPlugValueString(plug, myAssetName);
        CHECK_MSTATUS_AND_RETURN_IT(status);
    }

    // time1.outTime -> houdiniAsset.inTime
    {
        MObject srcNode = Util::findNodeByName("time1");
        MPlug srcPlug = MFnDependencyNode(srcNode).findPlug("outTime");
        MPlug dstPlug(assetNode, AssetNode::inTime);

        status = myDagModifier.connect(srcPlug, dstPlug);
        CHECK_MSTATUS_AND_RETURN_IT(status);
    }

    // cannot simply call redoIt, because when we use AssetSubCommandSync, we
    // need to distinguish between doIt and redoIt
    status = myDagModifier.doIt();
    CHECK_MSTATUS_AND_RETURN_IT(status);

    myAssetSubCommandSync = new AssetSubCommandSync(assetNode);
    myAssetSubCommandSync->doIt();

    MFnDependencyNode assetNodeFn(assetNode);

    // select the node
    MGlobal::select(assetNode);

    // set result
    MPxCommand::setResult(assetNodeFn.name());

    return MStatus::kSuccess;
}

MStatus
AssetSubCommandLoadAsset::redoIt()
{
    MStatus status;

    status = myDagModifier.doIt();<commit_msg>Avoid repeated error about not being able to instantiate asset<commit_after>#include "AssetSubCommandLoadAsset.h"

#include <maya/MFileObject.h>
#include <maya/MGlobal.h>
#include <maya/MPlug.h>
#include <maya/MPxCommand.h>

#include "AssetNode.h"
#include "AssetSubCommandSync.h"
#include "util.h"

AssetSubCommandLoadAsset::AssetSubCommandLoadAsset(
        const MString &otlFilePath,
        const MString &assetName
        ) :
    myOTLFilePath(otlFilePath),
    myAssetName(assetName),
    myAssetSubCommandSync(NULL)
{
}

AssetSubCommandLoadAsset::~AssetSubCommandLoadAsset()
{
}

MStatus
AssetSubCommandLoadAsset::doIt()
{
    MStatus status;

    // create houdiniAsset node
    MObject assetNode = myDagModifier.createNode(AssetNode::typeId, MObject::kNullObj, &status);
    CHECK_MSTATUS_AND_RETURN_IT(status);

    // rename houdiniAsset node
    status = myDagModifier.renameNode(assetNode, myAssetName);
    CHECK_MSTATUS_AND_RETURN_IT(status);

    // set otl file attribute
    {
        MPlug plug(assetNode, AssetNode::otlFilePath);
        status = myDagModifier.newPlugValueString(plug, myOTLFilePath);
        CHECK_MSTATUS_AND_RETURN_IT(status);
    }

    // set asset name attribute
    {
        MPlug plug(assetNode, AssetNode::assetName);
        status = myDagModifier.newPlugValueString(plug, myAssetName);
        CHECK_MSTATUS_AND_RETURN_IT(status);
    }

    // time1.outTime -> houdiniAsset.inTime
    {
        MObject srcNode = Util::findNodeByName("time1");
        MPlug srcPlug = MFnDependencyNode(srcNode).findPlug("outTime");
        MPlug dstPlug(assetNode, AssetNode::inTime);

        status = myDagModifier.connect(srcPlug, dstPlug);
        CHECK_MSTATUS_AND_RETURN_IT(status);
    }

    // cannot simply call redoIt, because when we use AssetSubCommandSync, we
    // need to distinguish between doIt and redoIt
    status = myDagModifier.doIt();
    CHECK_MSTATUS_AND_RETURN_IT(status);

    MFnDependencyNode assetNodeFn(assetNode);

    // select the node
    MGlobal::select(assetNode);

    // set result
    MPxCommand::setResult(assetNodeFn.name());

    // The asset should have been instantiated by now. If we couldn't
    // instantiate the asset, then don't operate on the asset any further. This
    // avoids generating repeated errors.
    {
        AssetNode* assetNode = dynamic_cast<AssetNode*>(assetNodeFn.userNode());
        if(!assetNode->getAsset())
        {
            // If we couldn't instantiate the asset, then an error message
            // should have displayed already. No need to display error here.
            return MStatus::kFailure;
        }
    }

    myAssetSubCommandSync = new AssetSubCommandSync(assetNode);
    myAssetSubCommandSync->doIt();

    return MStatus::kSuccess;
}

MStatus
AssetSubCommandLoadAsset::redoIt()
{
    MStatus status;

    status = myDagModifier.doIt();
{'fraction_non_alphanumeric': 0.09938008523827974, 'fraction_numerical': 0.0007748934521503294, 'mean_word_length': 3.6555455365193867, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5293344', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1611, 'n_words': 313}