SOLVED!
Line Error in AddOn

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-04-27
03:13 AM
- last edited on
2021-09-14
09:39 AM
by
Noemi Balogh
2021-04-27
03:13 AM
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:
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 11 - Visual Studio 2022; ArchiCAD 27
Windows 11 - Visual Studio 2022; ArchiCAD 27
Solved! Go to Solution.
Labels:
- Labels:
-
Add-On (C++)
1 ACCEPTED SOLUTION
Accepted Solutions
Solution

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-04-27 04:18 PM
2021-04-27
04:18 PM
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.
3 REPLIES 3

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-04-27 09:05 AM
2021-04-27
09:05 AM
It's strange. Could you please share the code where you wrap the function with ACAPI_CallUndoableCommand?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-04-27 12:40 PM
2021-04-27
12:40 PM
Here's the code -- standard copied code.
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
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 11 - Visual Studio 2022; ArchiCAD 27
Windows 11 - Visual Studio 2022; ArchiCAD 27
Solution

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-04-27 04:18 PM
2021-04-27
04:18 PM
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.