1038 {
1039 const char* hdaFile = "";
1040
1041 HAPI_Session session;
1042
1043 HAPI_ThriftServerOptions serverOptions{ 0 };
1044 serverOptions.autoClose = true;
1045 serverOptions.timeoutMs = 3000.0f;
1046
1047 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions,
"hapi",
nullptr,
nullptr))
1048
1049 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
1050 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
1051
1052 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
1053 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr))
1054
1055 HAPI_AssetLibraryId assetLibId;
1056 HE_CHECK(HAPI_LoadAssetLibraryFromFile(&session, hdaFile, true, &assetLibId))
1057
1058 int assetCount;
1059 HE_CHECK(HAPI_GetAvailableAssetCount(&session, assetLibId, &assetCount))
1060
1061 if (assetCount > 1)
1062 {
1063 std::cout << "Should only be loading 1 asset here" << std::endl;
1064 }
1065
1066 HAPI_StringHandle assetSh;
1067 HE_CHECK(HAPI_GetAvailableAssets(&session, assetLibId, &assetSh, assetCount))
1068
1069 std::string assetName =
GetString(session, assetSh);
1070
1071 HAPI_NodeId editableNetworkId;
1072 HE_CHECK(HAPI_CreateNode(&session, -1, assetName.c_str(),
"FourShape",
false, &editableNetworkId))
1073
1074 HE_CHECK(HAPI_CookNode(&session, editableNetworkId, &cookOptions))
1075
1076 int cookStatus;
1077 HAPI_Result cookResult;
1078
1079 do
1080 {
1081 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
1082 }
1083 while(cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
1084
1087
1088 int childCount;
1089 HE_CHECK(HAPI_ComposeChildNodeList(&session, editableNetworkId, HAPI_NODETYPE_ANY, HAPI_NODEFLAGS_ANY,
false, &childCount))
1090
1091 std::cout << "Editable Node Network Child Count: " << childCount << std::endl;
1092
1093 std::vector<HAPI_NodeId> childNodeIds(childCount);
1094 HE_CHECK(HAPI_GetComposedChildNodeList(&session, editableNetworkId, &childNodeIds.front(), childCount))
1095
1097
1098 HAPI_NodeId anotherBoxNode;
1099 HE_CHECK(HAPI_CreateNode(&session, editableNetworkId,
"geo",
"ProgrammaticBox",
false, &anotherBoxNode))
1100
1101 HE_CHECK(HAPI_ConnectNodeInput(&session, anotherBoxNode, 0, childNodeIds[0], 0))
1102 HE_CHECK(HAPI_CookNode(&session, anotherBoxNode, &cookOptions))
1103
1104 int boxCookStatus;
1105 HAPI_Result boxCookResult;
1106
1107 do
1108 {
1109 boxCookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &boxCookStatus);
1110 }
1111 while (boxCookStatus > HAPI_STATE_MAX_READY_STATE && boxCookResult == HAPI_RESULT_SUCCESS);
1112
1115
1116 HAPI_NodeId connectedNodeId;
1117 HE_CHECK(HAPI_QueryNodeInput(&session, anotherBoxNode, 0, &connectedNodeId))
1118
1119 if (connectedNodeId != childNodeIds[0])
1120 {
1121 std::cout << "The connected node id is" << connectedNodeId << " When it should be " << editableNetworkId << std::endl;
1122 }
1123
1124 HE_CHECK(HAPI_ComposeChildNodeList(&session, editableNetworkId, HAPI_NODETYPE_ANY, HAPI_NODEFLAGS_ANY,
false, &childCount))
1125
1126 std::vector<HAPI_NodeId> newChildNodes(childCount);
1127 HE_CHECK(HAPI_GetComposedChildNodeList(&session, editableNetworkId, &newChildNodes.front(), childCount))
1128
1129 std::cout << "After CONNECT NODE" << std::endl;
1131
1132 HE_CHECK(HAPI_SaveHIPFile(&session,
"",
false))
1133 HE_CHECK(HAPI_DisconnectNodeInput(&session, anotherBoxNode, 0))
1134 HE_CHECK(HAPI_DeleteNode(&session, anotherBoxNode))
1135
1136 std::cout << "After DELETING NODE" <<
std::endl;
1137
1138 HE_CHECK(HAPI_ComposeChildNodeList(&session, editableNetworkId, HAPI_NODETYPE_ANY, HAPI_NODEFLAGS_ANY, false, &childCount))
1139
1140 std::vector<HAPI_NodeId> finalChildList(childCount);
1141 HE_CHECK(HAPI_GetComposedChildNodeList(&session, editableNetworkId, &finalChildList.front(), childCount))
1142 PrintChildNodeInfo(session, finalChildList);
1143
1145 }
#define HE_CHECK_COOK(expr)
HoudiniEngine Check Cook macro. Verify HoudiniEngine Cook API Effectiveness.
#define HE_CHECK(expr)
HoudiniEngine Check macro. Verify HoudiniEngine API Effectiveness.
static std::string GetString(HAPI_Session &session, HAPI_StringHandle stringHandle)
static void PrintChildNodeInfo(HAPI_Session &session, std::vector< HAPI_NodeId > &childrenNodes)