We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2023-09-11 07:04 PM - last edited on 2024-09-17 01:00 PM by Doreena Deng
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.
- - cannot be called in the demo version
- - cannot be called neither during undoable operations nor during non-undoable commands
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
2023-09-13 04:25 PM
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.