License delivery maintenance is planned for Saturday, July 26, between 12:00 and 20:00 CEST. During this time, you may experience outages or limited availability across our services, including BIMcloud SaaS, License Delivery, Graphisoft ID (for customer and company management), Graphisoft Store, and BIMx Web Viewer. More details…
2024-08-29
06:16 AM
- last edited on
2024-09-05
01:08 PM
by
Laszlo Nagy
Hi,
I have a process want to do:
1. Open File.pln.
2. Check File.pln is opened and save as IFC by "Do_Save_IfcFile".
3. Quit Archicad.
I have followed this topic below and try to save as ifc file inside "APINotify_Open" event.
But "Do_Save_IfcFile" throws error seems the file is not fully opened.
I am using Archicad 26. Any ways I can save as ifc after file is fully opened? Thanks a lot.
https://community.graphisoft.com/t5/Archicad-C-API/Run-a-script-when-file-is-loaded-C/m-p/268283
Solved! Go to Solution.
2024-09-02 04:24 AM
Hi,
Please try the following code to see whether you can save as ifc file:
#include "SaveAndRestoreVariable.hpp"
#include "ResourceIDs.h"
#define SAVEIFC 'SIFC'
// =============================================================================
//
// Main functions
//
// =============================================================================
GSErrCode __ACENV_CALL SaveIFCFunction(GSHandle /* params */, GSPtr /* resultData */, bool /* silentMode */)
{
GSErrCode lastErr = NoError;
ACAPI_KeepInMemory(true);
API_ProjectInfo projectInfo = {};
lastErr = ACAPI_Environment(APIEnv_ProjectID, &projectInfo);
if (lastErr != NoError || projectInfo.untitled)
return APIERR_NOPLAN;
// Set the output IFC file's locations (it's beside the plan file)
IO::Name llName;
projectInfo.location->GetLastLocalName(&llName);
llName.DeleteExtension();
llName.AppendExtension("ifc");
projectInfo.location->SetLastLocalName(llName);
// Get a suitable translator
API_IFCTranslatorIdentifier firstTranslator;
GS::Array<API_IFCTranslatorIdentifier> ifcExportTranslators;
lastErr = ACAPI_IFC_GetIFCExportTranslatorsList (ifcExportTranslators);
if (lastErr != NoError) {
return APIERR_GENERAL;
}
else {
if (DBVERIFY(!ifcExportTranslators.IsEmpty()))
firstTranslator = ifcExportTranslators.GetFirst();
}
// Set the output parameters
API_FileSavePars fileSave = {};
fileSave.fileTypeID = APIFType_IfcFile;
fileSave.file = projectInfo.location;
// Set the output parameters for IFC
API_SavePars_Ifc ifcPars = {};
ifcPars.subType = API_IFC;
ifcPars.elementsToIfcExport = API_EntireProject;
ifcPars.translatorIdentifier = firstTranslator;
ifcPars.elementsSet = nullptr;
lastErr = ACAPI_Automate(APIDo_SaveID, &fileSave, &ifcPars);
return lastErr;
}
static GSErrCode AllInputNotificationHandler(API_NotifyEventID notifID, Int32 /*param*/)
{
if (notifID == APINotify_AllInputFinished) {
API_ModulID mdid = {};
mdid.developerID = MDID_DEVELOPER_ID;
mdid.localID = MDID_LOCAL_ID;
ACAPI_Command_CallFromEventLoop(&mdid, SAVEIFC, 1L, nullptr, false, nullptr);
}
ACAPI_KeepInMemory(true);
return NoError;
}
// =============================================================================
//
// Required functions
//
// =============================================================================
// -----------------------------------------------------------------------------
// Dependency definitions
// -----------------------------------------------------------------------------
API_AddonType __ACENV_CALL CheckEnvironment (API_EnvirParams* envir)
{
RSGetIndString (&envir->addOnInfo.name, ID_ADDON_INFO, 1, ACAPI_GetOwnResModule());
RSGetIndString (&envir->addOnInfo.description, ID_ADDON_INFO, 2, ACAPI_GetOwnResModule());
return APIAddon_Preload;
} // CheckEnvironment
// -----------------------------------------------------------------------------
// Interface definitions
// -----------------------------------------------------------------------------
GSErrCode __ACENV_CALL RegisterInterface (void)
{
GSErrCode err = ACAPI_Register_SupportedService(SAVEIFC, 1L);
return err;
} // RegisterInterface
// -----------------------------------------------------------------------------
// Called when the Add-On has been loaded into memory
// to perform an operation
// -----------------------------------------------------------------------------
GSErrCode __ACENV_CALL Initialize (void)
{
GSErrCode err = ACAPI_Install_ModulCommandHandler(SAVEIFC, 1L, SaveIFCFunction);
err |= ACAPI_Notify_CatchProjectEvent(APINotify_AllInputFinished, AllInputNotificationHandler);
return err;
} // Initialize
// -----------------------------------------------------------------------------
// FreeData
// called when the Add-On is going to be unloaded
// -----------------------------------------------------------------------------
GSErrCode __ACENV_CALL FreeData (void)
{
return NoError;
} // FreeData
HTH.
2024-08-30 04:14 AM
Hi,
I'm afraid you cannot call ifc save function during the file opening operation. I'd suggest you to try APINotify_AllInputFinished.
HTH.
2024-08-30 11:31 AM - edited 2024-08-30 11:32 AM
Thanks for your suggestion. I have tried "APINotify_AllInputFinished" but still fail with "APIERR_BADWINDOW" message.
2024-09-02 04:24 AM
Hi,
Please try the following code to see whether you can save as ifc file:
#include "SaveAndRestoreVariable.hpp"
#include "ResourceIDs.h"
#define SAVEIFC 'SIFC'
// =============================================================================
//
// Main functions
//
// =============================================================================
GSErrCode __ACENV_CALL SaveIFCFunction(GSHandle /* params */, GSPtr /* resultData */, bool /* silentMode */)
{
GSErrCode lastErr = NoError;
ACAPI_KeepInMemory(true);
API_ProjectInfo projectInfo = {};
lastErr = ACAPI_Environment(APIEnv_ProjectID, &projectInfo);
if (lastErr != NoError || projectInfo.untitled)
return APIERR_NOPLAN;
// Set the output IFC file's locations (it's beside the plan file)
IO::Name llName;
projectInfo.location->GetLastLocalName(&llName);
llName.DeleteExtension();
llName.AppendExtension("ifc");
projectInfo.location->SetLastLocalName(llName);
// Get a suitable translator
API_IFCTranslatorIdentifier firstTranslator;
GS::Array<API_IFCTranslatorIdentifier> ifcExportTranslators;
lastErr = ACAPI_IFC_GetIFCExportTranslatorsList (ifcExportTranslators);
if (lastErr != NoError) {
return APIERR_GENERAL;
}
else {
if (DBVERIFY(!ifcExportTranslators.IsEmpty()))
firstTranslator = ifcExportTranslators.GetFirst();
}
// Set the output parameters
API_FileSavePars fileSave = {};
fileSave.fileTypeID = APIFType_IfcFile;
fileSave.file = projectInfo.location;
// Set the output parameters for IFC
API_SavePars_Ifc ifcPars = {};
ifcPars.subType = API_IFC;
ifcPars.elementsToIfcExport = API_EntireProject;
ifcPars.translatorIdentifier = firstTranslator;
ifcPars.elementsSet = nullptr;
lastErr = ACAPI_Automate(APIDo_SaveID, &fileSave, &ifcPars);
return lastErr;
}
static GSErrCode AllInputNotificationHandler(API_NotifyEventID notifID, Int32 /*param*/)
{
if (notifID == APINotify_AllInputFinished) {
API_ModulID mdid = {};
mdid.developerID = MDID_DEVELOPER_ID;
mdid.localID = MDID_LOCAL_ID;
ACAPI_Command_CallFromEventLoop(&mdid, SAVEIFC, 1L, nullptr, false, nullptr);
}
ACAPI_KeepInMemory(true);
return NoError;
}
// =============================================================================
//
// Required functions
//
// =============================================================================
// -----------------------------------------------------------------------------
// Dependency definitions
// -----------------------------------------------------------------------------
API_AddonType __ACENV_CALL CheckEnvironment (API_EnvirParams* envir)
{
RSGetIndString (&envir->addOnInfo.name, ID_ADDON_INFO, 1, ACAPI_GetOwnResModule());
RSGetIndString (&envir->addOnInfo.description, ID_ADDON_INFO, 2, ACAPI_GetOwnResModule());
return APIAddon_Preload;
} // CheckEnvironment
// -----------------------------------------------------------------------------
// Interface definitions
// -----------------------------------------------------------------------------
GSErrCode __ACENV_CALL RegisterInterface (void)
{
GSErrCode err = ACAPI_Register_SupportedService(SAVEIFC, 1L);
return err;
} // RegisterInterface
// -----------------------------------------------------------------------------
// Called when the Add-On has been loaded into memory
// to perform an operation
// -----------------------------------------------------------------------------
GSErrCode __ACENV_CALL Initialize (void)
{
GSErrCode err = ACAPI_Install_ModulCommandHandler(SAVEIFC, 1L, SaveIFCFunction);
err |= ACAPI_Notify_CatchProjectEvent(APINotify_AllInputFinished, AllInputNotificationHandler);
return err;
} // Initialize
// -----------------------------------------------------------------------------
// FreeData
// called when the Add-On is going to be unloaded
// -----------------------------------------------------------------------------
GSErrCode __ACENV_CALL FreeData (void)
{
return NoError;
} // FreeData
HTH.
2024-09-04 12:13 PM
It's work. Thank you so much.