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

How to call ACAPI_Automate(APIDo_SaveID) inside ACAPI_CallUndoableCommand scope?

Anonymous
Not applicable
Hello guys,

I call a function in ACAPI_CallUndoableCommand scope and inside this function I call ACAPI_Automate(APIDo_SaveID) and ACAPI_Automate is not working:

ACAPI_CallUndoableCommand("Import Files", [&]() -> GSErrCode { ImportFiles(); return (0); });

void ImportFiles()
{
        ...
        ACAPI_Automate(APIDo_SaveID);
}
Is there a way to get out of this scope or I have to call it outside ImportFiles?
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

APIDo_SaveID is not allowed to be called inside ACAPI_CallUndoableCommand scope.
Sorry, you have to call it outside.

Regards,
Tibor

View solution in original post

4 REPLIES 4
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

APIDo_SaveID is not allowed to be called inside ACAPI_CallUndoableCommand scope.
Sorry, you have to call it outside.

Regards,
Tibor
Anonymous
Not applicable
In order not to open a new topic for these automated functions, how can I open a new project with the "rectangle area" in the center? I open a new project using the example and don't have it:

        API_NewProjectPars npp;

	BNZeroMemory(&npp, sizeof(API_NewProjectPars));
	npp.newAndReset = true;
	npp.enableSaveAlert = false;

	GSErrCode err = ACAPI_Automate(APIDo_NewProjectID, &npp);
	
If I manually open a new project, ARCHICAD 23 Template.tpl is choosen and everything is OK.

How can I choose this template with the automated function?
MOREH Tamas
Graphisoft
Graphisoft
Hi!
You are right it is currently not possible.
I register it in our issue tracking database and we will implement as soon as we can.
Thank you for the report.

Tibor,

If I understand this correctly, this prevents me from creating a custom menu [AC23] with a choice that updates all drawings and saves.  I understand I have to reserve before I can save a Teamwork file.  However, I am the only one working in a non-Teamwork .pln file.  I am using Do_Save_Plan() found in the AC23 Examples Automate_Functions.cpp file.

 

It would also be unclear to me if I cannot call this from inside the ACAPI_CallUndoableCommand scope of MenuCommandHandler(), how exactly would I execute my update instructions and save my work?

Currently, when I try this, I get err = -2130312312

GSErrCode __ACENV_CALL MenuCommandHandler (const API_MenuParams *params)
{
 return ACAPI_CallUndoableCommand("JHP_BatchPdf Menu Command", [&]() -> GSErrCode {
  switch (params->menuItemRef.menuResID)
  {
   case JHP_BATCHPDF_MENU_STRINGSID: {
    switch (params->menuItemRef.itemIndex)
    {
     case 1: {
      ACAPI_WriteReport("Refresh", true);
      RefreshAllLayoutBooks();
      break;
     }
     case 2: {
      ACAPI_WriteReport("Save project", true);
      Do_Save_Plan();
      break;
     }
     case 3: {
      ACAPI_WriteReport("Save PDF", true);
      Do_Save_PdfFile();
      break;
     }
    }
   }
  }
  return NoError;
 });
}



// -----------------------------------------------------------------------------
// Save the current project
// -----------------------------------------------------------------------------

static void Do_Save_Plan(void)
{
 GSErrCode err;

 err = ACAPI_Automate(APIDo_SaveID);
 if (err != NoError)
  // ACAPI_WriteReport("Error in APIDo_SaveID: %s", true, ErrID_To_Name(err));
  ACAPI_WriteReport("Error in APIDo_SaveID: %d", true, err);

 return;
} // Do_Save_Plan

 

Thanks for any hint you can provide,

Chris

 

Chris Gilmer
Intel i9-12950HX CPU @ 2.30GHz, 16 cores
NVIDIA GeForce RTX 3080
48.0 GB RAM
Windows 10 Pro 64-bit