Archicad C++ API
About Archicad add-on development using the C++ API.

Hotlink via API was always created at the top most story and with offsets

kristkun
Participant

Hi,

I followed/used the Element_Hotlink.cpp in API version 27 examples for creating hotlinks

 

// -----------------------------------------------------------------------------
// Create a hotlink node and place hotlink element
// -----------------------------------------------------------------------------

GSErrCode	Do_CreateHotlink ()
{
	IO::Location sourceFileLoc;
	API_SpecFolderID specID = API_ApplicationFolderID;
	ACAPI_ProjectSettings_GetSpecFolder (&specID, &sourceFileLoc);
	sourceFileLoc.AppendToLocal (IO::Name ("Archicad Examples"));
	sourceFileLoc.AppendToLocal (IO::Name ("Residential House"));
	sourceFileLoc.AppendToLocal (IO::Name ("Residential House.pln"));

	API_Element element = {};
	element.header.type = API_HotlinkID;
	element.header.layer = APIApplicationLayerAttributeIndex;
	element.hotlink.type = APIHotlink_Module;

	element.hotlink.transformation = CreateTransformation ({10.0, 4.0, 0.0}, PI / 6.0);

	element.hotlink.ignoreTopFloorLinks	= true;
	element.hotlink.relinkWallOpenings	= false;
	element.hotlink.adjustLevelDiffs	= false;

	GSErrCode err = ACAPI_CallUndoableCommand ("Element Test - Create Hotlink Node and Place an Instance", [&] () -> GSErrCode {
		const GS::Optional<API_Guid> hotlinkNodeGuid = CreateHotlinkNode (sourceFileLoc);

		if (hotlinkNodeGuid.IsEmpty ()) {
			return APIERR_GENERAL;
		}

		element.hotlink.hotlinkNodeGuid = hotlinkNodeGuid.Get ();

		return ACAPI_Element_Create (&element, nullptr);
	});

	if (err == NoError) {
		ACAPI_WriteReport ("Hotlink instance is created successfully: {%T}", WriteToSessionReport,
							APIGuidToString (element.header.guid).ToPrintf ());
	} else {
		ACAPI_WriteReport ("Failed to Hotlink instance from: {%T}", WriteToSessionReport,
							sourceFileLoc.ToLogText ().ToPrintf ());
	}

	return err;
}

 

(Though, I modified the transformation values to just have zero figures)

My main concern is that, the newly created hotlink was always placed in my top most story. I was trying to create the hotlink in the ground floor (story index 0).
Aside from that, I'm not sure if it is possible to modify the Additional offset setting under elements settings via api?
I checked the Hotlink API type and it seems there is no existing parameter that correlates to that setting (correct me if im wrong)

kristkun_0-1711481354541.png

 

1 REPLY 1
kristkun
Participant

Figured out that the created hotlink uses the floor setting in the mod file. When i tried creating another mod file with the elements in the ground floor, it was placed in the ground floor as well when created via api.

However, what I need is to add existing hotlink module to any floor that i want via API.
When I checked the debug, when the hotlink (in 4th story) was created via ACAPI_Element_Create(), the story index of the element parameter was set to zero even though it was placed in the 4th story