Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

API DevKit sample code Element Test Hotlink struggle

szfri
Participant
Hi everyone!

I'm a newbie here so some of my questions might seem strange and I'm sorry in advance if I'm breaking any rules with my post. I'm trying to learn to understand how to program some addons. I use the API Dev Kit 24.3009. I'm an architect by profession and I have limited programming knowledge in C++.
I'm trying to make the example code Element_Test and particularly the Do_CreateHotlink function work properly, but I have some problems.
First of all it doesn't seem to be an out of the box solution since the pln module file used in the original source code is not included in the example code. So I tried to replace it with an own one. The addon seems to run properly up until the ACAPI_Element_Create function. Then there's no result, no error messages, one can continue to work with Archicad as if nothing happened.
What am I missing? Did I use an improper way of constructing the sourceFileLoc parameter? That is the only part of the code that I changed. Unfortunately the documentation included with the DevKit is not explaining explicitly how to use the ACAPI_Element_Create function to create a hotlink element. Or at least I didn't find that part yet.

Here's the code as a reminder:
GSErrCode	Do_CreateHotlink (void)
{
	API_Guid hotlinkNodeGuid = APINULLGuid;

	IO::Location sourceFileLoc("c:\\Users\\dell7559\\Desktop\\module.pln"); //my way of replacing the default pln file

	API_HotlinkNode hotlinkNode;
	BNZeroMemory (&hotlinkNode, sizeof (API_HotlinkNode));
	hotlinkNode.type = APIHotlink_Module;
	hotlinkNode.storyRangeType = APIHotlink_AllStories;
	hotlinkNode.sourceLocation = &sourceFileLoc;
	hotlinkNode.refFloorInd = 0;
	GS::ucsncpy (hotlinkNode.name, L("Hotlink created by test add-on"), API_UniLongNameLen - 1);

	GSErrCode err = ACAPI_Database (APIDb_CreateHotlinkNodeID, &hotlinkNode);
	if (err == NoError) {
		char guidStr[64];
		hotlinkNodeGuid = hotlinkNode.guid;
		APIGuid2GSGuid (hotlinkNodeGuid).ConvertToString (guidStr);
		WriteReport ("Hotlink node is created successfully: {%s}", guidStr);
		ACAPI_WriteReport(guidStr, true);
	}
	if (err == NoError && hotlinkNodeGuid != APINULLGuid) {
		API_Element element;									// place an instance of this hotlink
		BNZeroMemory (&element, sizeof (API_Element));
		element.header.typeID = API_HotlinkID;
		element.header.layer = 1;
		element.hotlink.hotlinkNodeGuid = hotlinkNodeGuid;

		element.hotlink.type = APIHotlink_Module;
		element.hotlink.transformation.tmx[3] = 10;
		element.hotlink.transformation.tmx[7] = 4;
		double	co = cos (0.52359877556);
		double	si = sin (0.52359877556);
		element.hotlink.transformation.tmx[0] = element.hotlink.transformation.tmx[5] = co;
		element.hotlink.transformation.tmx[1] = -si;
		element.hotlink.transformation.tmx[4] = si;

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

		err = ACAPI_Element_Create (&element, nullptr);
		
		if (err == NoError) {
			char guidStr[64];
			APIGuid2GSGuid (element.header.guid).ConvertToString (guidStr);
			WriteReport ("Hotlink instance is created successfully: {%s}", guidStr);
		}
	}
	return err;
}		// Do_CreateHotlink
I'd really appreciate if anyone could point me into the right direction!
Ferenc Szőke
architect
2 REPLIES 2

szfri
Participant
I found the solution, it was the transformation matrix that caused the problem.

But I have another problem with the same code. I'm trying to use it in a new solution and this part:
GS::ucsncpy(hotlinkNode.name, L("Hotlink created by test add-on"), API_UniLongNameLen - 1);

is giving this error when building the project:

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2019	unresolved external symbol "__declspec(dllimport) unsigned short const * __cdecl GS::DefineConstantUTF16CharacterOrString(wchar_t const *)" (__imp_?DefineConstantUTF16CharacterOrString@GS@@YAPEBGPEB_W@Z) referenced in function "int __cdecl Do_CreateHotlink(class GS::UniString const &,double *)" (?Do_CreateHotlink@@YAHAEBVUniString@GS@@PEAN@Z)	AddOn	d:\programming\archicad\Hotlink Placer\Build\AddOnMain.obj	1	

1>------ Build started: Project: AddOnResources, Configuration: Debug x64 ------
2>------ Build started: Project: AddOn, Configuration: Debug x64 ------
2>AddOnMain.cpp
2>   Creating library D:/programming/archicad/Hotlink Placer/Build/Debug/Hotlink_Placer.lib and object D:/programming/archicad/Hotlink Placer/Build/Debug/Hotlink_Placer.exp
2>AddOnMain.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) unsigned short const * __cdecl GS::DefineConstantUTF16CharacterOrString(wchar_t const *)" (__imp_?DefineConstantUTF16CharacterOrString@GS@@YAPEBGPEB_W@Z) referenced in function "int __cdecl Do_CreateHotlink(class GS::UniString const &,double *)" (?Do_CreateHotlink@@YAHAEBVUniString@GS@@PEAN@Z)
2>D:\programming\archicad\Hotlink Placer\Build\Debug\Hotlink_Placer.apx : fatal error LNK1120: 1 unresolved externals
2>Done building project "AddOn.vcxproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Can anyone help me how to solve this? What's missing, what am I not including in the project?
Any help is appreciated!
Ferenc Szőke
architect

szfri
Participant
I found the setting responsible for this error in Visual Studio, it works fine now.

But of course there is another problem I'd like to get some solution with:

Is there a way to modify the position of an existing hotlink through somehow changing its transformation matrix?
The ACAPI_Element_Change function crashes when used to change the transformation matrix.
Any advice is appreciated!
Ferenc Szőke
architect

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!