object_count = 0 even though there are objects in the asset

   2436   2   2
User Avatar
Member
7 posts
Joined: June 2018
Offline
Hi,

I need some help with getting the objects from a digital asset. I have loaded the
attached .hda file (ladder.hda) and am now trying to get the composed object list of the
asset with the following code:

HAPI_Result status_code;
HAPI_AssetLibraryId library_id;

status_code = HAPI_LoadAssetLibraryFromFile(ref session, file_path,
true, out library_id);
processStatusCode(status_code);

int asset_count = 0;
status_code = status_code = HAPI_GetAvailableAssetCount(ref session,
library_id, out asset_count);
processStatusCode(status_code);

int[] asset_names_sh = new int[asset_count];
status_code = HAPI_GetAvailableAssets(ref session, library_id, asset_names_sh, asset_count);
processStatusCode(status_code);

string[] asset_names = new string[asset_count];
for (int i = 0; i < asset_count; ++i)
{
asset_names[i] = getString(asset_names_sh[i]);
Console.WriteLine( asset_names[ i ] );
}

HAPI_NodeId node_id = -1;
string first_asset_name = asset_names[0];
bool cook_on_load = false;
status_code = HAPI_CreateNode(
ref session, -1, first_asset_name, "", cook_on_load, out node_id);
processStatusCode(status_code);

HAPI_CookOptions cook_options = getCookOptions();
HAPI_Result status_code = HAPI_CookNode(ref session, node_id, ref cook_options );
processStatusCode( status_code );

int object_count;
status_code = HAPI_ComposeObjectList(ref session, node_id, "", out object_count);
processStatusCode( status_code );

HAPI_ObjectInfo[] object_infos = new HAPI_ObjectInfo[object_count];
status_code = HAPI_GetComposedObjectList(ref session, node_id, object_infos, 0, object_count);
processStatusCode( status_code );

object_count becomes 0 but when opening the .hda file in Houdini it says that I have “1 objects”.
It works with the working_box.hda which I find strange. Is there something wrong I did when creating the asset?
Or why does it not work with the ladder?
Edited by MsOddball - July 4, 2018 03:55:45

Attachments:
ladder.hda (51.1 KB)
working_box.hda (12.3 KB)

User Avatar
Member
7 posts
Joined: June 2018
Offline
Is there no one that knows what I am doing wrong?
User Avatar
Member
571 posts
Joined: May 2017
Offline
The object_count is 0 when there are no child objects. Instead, your asset is simply the object itself. Therefore in your code, you can presume that there is a single object, and access it this way:

if (objectCount <= 0)
{
	// Since this asset is an object type and has 0 object as children, we use the object itself

	objectInfos = new HAPI_ObjectInfo[1];
	if (!HAPI_GetObjectInfo(ref session, node_id, ref objectInfos[0]))
	{
		return false;
	}

	// Identity transform will be used for single object assets, so not querying transform
	objectTransforms = new HAPI_Transform[1];
	objectTransforms[0] = new HAPI_Transform(true);
}
Edited by seelan - July 20, 2018 15:54:24
  • Quick Links