How to add attribute in plugin

   2010   4   0
User Avatar
Member
4 posts
Joined: June 2018
Offline
Hi,

I want to add a custom attribute when using landscape as input.
This is what I have tried
bool FHoudiniLandscapeUtils::AddLandscapeStringAttribuete(const HAPI_NodeId& NodeId, const FString& AttributeName, const FString& AttributeValue)
{
	HAPI_AttributeInfo AttributeInfo;
	FMemory::Memzero< HAPI_AttributeInfo >(AttributeInfo);
	AttributeInfo.count = 1;
	AttributeInfo.tupleSize = 1;
	AttributeInfo.exists = true;
	AttributeInfo.owner = HAPI_ATTROWNER_DETAIL;
	AttributeInfo.storage = HAPI_STORAGETYPE_STRING;
	AttributeInfo.originalOwner = HAPI_ATTROWNER_INVALID;


	HOUDINI_CHECK_ERROR_RETURN(FHoudiniApi::AddAttribute(
		FHoudiniEngine::Get().GetSession(), NodeId, 0,
		TCHAR_TO_ANSI(*AttributeName), &AttributeInfo), false);

	TArray< const char * > ValueArray;
	ValueArray.Add(TCHAR_TO_ANSI(*AttributeValue));

	HOUDINI_CHECK_ERROR_RETURN(FHoudiniApi::SetAttributeStringData(
		FHoudiniEngine::Get().GetSession(), NodeId, 0,
		TCHAR_TO_ANSI(*AttributeName),
		&AttributeInfo,
		(const char **)&ValueArray[0],
		0, AttributeInfo.count), false);

	return true;
}

The place I call it
	
FString AttrbuteName("TargetLevelName");
FString TargetLevelName("TestValue");
if (!FHoudiniLandscapeUtils::AddLandscapeStringAttribuete(MergeId, AttrbuteName, TargetLevelName))
{
	check(0);
}

All the function returned true. But when I open the debug scene the attribute not added successfully.
Do I miss something?
User Avatar
Member
4 posts
Joined: June 2018
Offline
Currently,I use an alternative way to achieve the goal by adding a create attribute node to the network through HDK.
I have another question is why the nodes not connected correctly when I open up the debug scene in UE4, but it turns out to works correctly anyway.
User Avatar
Staff
534 posts
Joined: Sept. 2016
Offline
Hi,

The disconnected height-field nodes when debugging the internal Houdini scene is a known bug.
It only happens when debugging, the nodes are actually properly connected in the internal scene when using the plug-in, but for some reason, appears disconnected when saving that internal hip files.

I don't see anything wrong with the code you're using for adding the string attribute.
In what function are you adding that call to FHoudiniLandscapeUtils::AddLandscapeStringAttribuete()?
User Avatar
Member
4 posts
Joined: June 2018
Offline
Hi dpernuit,

I call FHoudiniLandscapeUtils::AddLandscapeStringAttribuete() in FHoudiniEngineUtils::HapiCreateInputNodeForLandscape, right after FHoudiniLandscapeUtils::CreateHeightfieldInputNode which returned a MergeId node I want to add attribute on.
User Avatar
Member
1 posts
Joined: July 2018
Offline
dpernuit
Hi,

The disconnected height-field nodes when debugging the internal Houdini scene is a known bug.
It only happens when debugging, the nodes are actually properly connected in the internal scene when using the plug-in, but for some reason, appears disconnected when saving that internal hip files.

I don't see anything wrong with the code you're using for adding the string attribute.
In what function are you adding that call to FHoudiniLandscapeUtils::AddLandscapeStringAttribuete()?

I have exactly the same problem with jimizhang.
  • Quick Links