cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Developer forum
GDL coding questions, Python and add-on development using the API Dev Kit.

Line Error in AddOn

poco2013
Mentor
I am trying to create a simple line in a new Add-On. I copied directly the line create function from the Element.Test Example. Create Line works Ok in Element test but will not work in my new addon -- yes - I did wrap it in the undoable command. my other function in the new addon works ok.

Any thoughts?? Would appreciate some help or any suggestions?

For anyone interested here is the video:



void	Do_CreateLine(API_Guid guid)
	{
		API_Coord			c;
		API_GetLineType		clickInfo;
		API_Element			element;
		GSErrCode			err;

		// input the coordinates
		BNZeroMemory(&clickInfo, sizeof(API_GetLineType));
		if (!ClickAPoint("Click the line start point", &c))
			return;

		CHCopyC("Click the line end point", clickInfo.prompt);

		clickInfo.startCoord.x = c.x;
		clickInfo.startCoord.y = c.y;
		err = ACAPI_Interface(APIIo_GetLineID, &clickInfo, nullptr);
		if (err != NoError) {
			ErrorBeep("APIIo_GetLineID", err);
			return;
		}

		// real work
		BNZeroMemory(&element, sizeof(API_Element));
		element.header.typeID = API_LineID;
		ACAPI_Element_GetDefaults(&element, nullptr);
		if (err != NoError) {
			ErrorBeep("ACAPI_Element_GetDefaults (Line)", err);
			return;
		}

		element.header.renovationStatus = API_DemolishedStatus;
		element.line.begC.x = clickInfo.startCoord.x;
		element.line.begC.y = clickInfo.startCoord.y;
		element.line.endC.x = clickInfo.pos.x;
		element.line.endC.y = clickInfo.pos.y;
		err = ACAPI_Element_Create(&element, nullptr);
		if (err != NoError) {
			ErrorBeep("ACAPI_Element_Create (Line)", err);
			ACAPI_WriteReport("Create Error = %s", true, ErrID_To_Name(err));
			return;
		}
		else
			ACAPI_WriteReport("Create Success - %s", true, "No Error");
			
		

		ACAPI_WriteReport("GUID of the Line: %s", true, APIGuidToString(element.header.guid).ToCStr().Get());
		guid = element.header.guid;		// store it for later use

		ACAPI_KeepInMemory(true);

		return;
	}		// Do_CreateLine

Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 26
1 ACCEPTED SOLUTION
3 REPLIES 3

Viktor Kovacs
Graphisoft Alumni
Graphisoft Alumni
It's strange. Could you please share the code where you wrap the function with ACAPI_CallUndoableCommand?

poco2013
Mentor
Here's the code -- standard copied code.


static GSErrCode MenuCommandHandler (const API_MenuParams *menuParams)
{
	GS::ErrCode err;
	return ACAPI_CallUndoableCommand("Element Test API Function",
		[&]() -> GSErrCode {

		switch (menuParams->menuItemRef.menuResID) {
		case AddOnMenuID:
			switch (menuParams->menuItemRef.itemIndex) {

			case 1:
			{
				err = Do_PlaceKeySymbol("part");
			}
			break;
			case 2:
			{
				Do_CreateLabel();
			}
			break;
			
			case 3:
			{
				Do_CreateLine(APINULLGuid);
			}
			break;
			default: break;
			}	
		}
		return err;
	});
}

Note that the first function that just creates a library Part works OK.

EDIT: I have no idea why this works but your comment caused me to look at the returns. I change the void returns to return a error code and all works now. Very strange because I copied the code one for one from Element_test???

Thanks for the Help!! -- Again
Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 26

Solution
Viktor Kovacs
Graphisoft Alumni
Graphisoft Alumni
It's because your err variable is not initialized, so it will contain some uninitialized value. If the ACAPI_CallUndoableCommand returns anything else than NoError, the whole operation will be aborted. I think this happened in your case.

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!