BIM Coordinator Program (INT) April 22, 2024
Find the next step in your career as a Graphisoft Certified BIM Coordinator!
Archicad C++ API
About Archicad add-on development using the C++ API.

ACAPI_CallUndoableCommand and menu choice to create a .pdf file

MudratDetector
Enthusiast

WIN 10 / AC24

 

I am trying to create a .pdf file of the current layout sheet by using the Do_Save_PdfFile function found in ..\Examples\Automate_Functions.  Instead of a .pdf file, I get an APIERR_REFUSEDCMD error.  I am trying to figure out how to properly use the code proveded to do this.  

 

Here is my version of the Do_Save_PdfFile function copied from ..\Examples\Automate_Functions:

 

 

 

 

static void		Do_Save_PdfFile(void)
{
	API_FileSavePars	fsp = {};
	GSErrCode			err;

	fsp.fileTypeID = APIFType_PdfFile;

	IO::Location folderLoc;
	API_SpecFolderID specID = API_UserDocumentsFolderID;
	ACAPI_Environment(APIEnv_GetSpecFolderID, &specID, &folderLoc);
	fsp.file = new IO::Location(folderLoc, IO::Name("PDFTest.pdf"));

	err = ACAPI_CallUndoableCommand("Create PDF", [&]() -> GSErrCode {
		return ACAPI_Automate(APIDo_SaveID, &fsp);  // <<<--- ERROR HERE
	});
	ACAPI_Automate(APIDo_SaveID, &fsp);

	if (err != NoError)
		ACAPI_WriteReport("Error in APIDo_SaveID (PDF): %s", true, ErrID_To_Name(err));
	else
		ACAPI_WriteReport("Done.", true);

	//delete fsp.file;

	return;
}		// Do_Save_PdfFile

 

 

 

 

 

Here is my menu call to this function:

 

 

 

 

GSErrCode	__ACENV_CALL	MenuCommandHandler (const API_MenuParams *params)
{
	return ACAPI_CallUndoableCommand("JHP_DrawingUpdate Menu Command", [&]() -> GSErrCode {

		switch (params->menuItemRef.menuResID)
		{
			case JHP_DRAWINGUPDATE_MENU_STRINGSID: {

				switch (params->menuItemRef.itemIndex)
				{
					case 1: {
						Do_ListDatabases(APIDb_GetLayoutDatabasesID, "layout");
						break;
					}
					case 2: {
						Do_Save_PdfFile();
						break;
					}
					case 3: {...

 

 

 

 

 

Graphisoft documentation on APIDo_SaveID indicates a few causes for this error.

- - the function is called from the notification level; the command is refused if other addons are running.

  • Notification level???  I'm not even sure what that is and how I would get myself off of or away from the notification level
  • Is an addon that is a constant event listener/reactor part of "other addons are running"?  I do have that in place.

- - cannot be called in the demo version

  • I am running a fully licensed version and have been since 19.

- - cannot be called neither during undoable operations nor during non-undoable commands

  • I am wrapping my call in ACAPI_CallUndoableCommand, both at the MenuCommandHandler level and the APIDo_SaveID level.  Am I doing this wrong?

 

Or would an API version of Document > Publish with my PDF publisher set be a better approach?

 

Thanks for any insight 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
1 REPLY 1
Viktor Kovacs
Graphisoft
Graphisoft

Have you tried not wrapping it in a ACAPI_CallUndoableCommand? Checking the Automate_Functions example it doesn't wrap it either, and the documentation states that it doesn't needed.

Learn and get certified!