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

Run a script when file is loaded? (C++)

Anonymous
Not applicable
Hello,

My goal is to open a pln file, and to run a script from my addon after my file is loded.

What I want to do is to open bunch of files by an external program, automatically process each on them with my addon.

Thanks a lot!
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Ralph Wessel
Mentor
Tomer1 wrote:
The activation point is after the file is loaded.
Example of the wanted process:
1. File.pln is opened on a computer with my addon
2. After the file done loading, the addon executes some scripts
Assuming that when you say, "File.pln is opened", that means even if the user opens the project:
1) When the add-on Initialise function is called (when it's loaded), call ACAPI_Notify_CatchProjectEvent so Archicad notifies you when project events occur, e.g. opening/saving/closing etc.

2) When Archicad invokes the callback with a project event, check the event type is APINotify_Open

3) You could immediately run whatever process is required on receiving APINotify_Open, but it's safer to ask Archicad to notify your add-on as soon as it's safe for all kinds of activity (some actions can otherwise cause a crash or be ignored). We do this if we want to display some UI component to the user (e.g. show a palette), validate project content or ensure add-on preferences are loaded/valid.

4) To delay processing until an appropriate moment, you can request a callback from Archicad using ACAPI_Command_CallFromEventLoop. The documentation for this function has a code example you can use. Your callback handler can implement whatever process you need to action on the project. If you intend to modify the project, don't forget to fold your process into ACAPI_CallUndoableCommand
Ralph Wessel BArch
Software Engineer Speckle Systems

View solution in original post

7 REPLIES 7
Ralph Wessel
Mentor
GS has introduced Python and JSON development features that are primarily supporting external apps driving Archicad. Do you think they might support the actions you intend to perform on the open project?
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Ralph wrote:
GS has introduced Python and JSON development features that are primarily supporting external apps driving Archicad. Do you think they might support the actions you intend to perform on the open project?
I didn’t check the python api because I know it doesn’t have all the feature that the c++ api provide.
I practically really Prefer to only use the c++ api for everything, including what I’m asking here. I have a large and complicated addon with more than 20 classes..
Isn’t it possible to do it with the c++ api?
Ralph Wessel
Mentor
Tomer1 wrote:
I didn’t check the python api because I know it doesn’t have all the feature that the c++ api provide.
I practically really Prefer to only use the c++ api for everything, including what I’m asking here. I have a large and complicated addon with more than 20 classes..
Isn’t it possible to do it with the c++ api?
Yes, it's certainly possible with the C++ API - and has the potential to be lot better too. I just wanted to be certain the alternatives had been considered.

First, what is the intended activation point for your process, i.e. does it need to be triggered by an external application or can it be started within Archicad and then query an external application for the intended process parameters?
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Ralph wrote:
Tomer1 wrote:
I didn’t check the python api because I know it doesn’t have all the feature that the c++ api provide.
I practically really Prefer to only use the c++ api for everything, including what I’m asking here. I have a large and complicated addon with more than 20 classes..
Isn’t it possible to do it with the c++ api?
Yes, it's certainly possible with the C++ API - and has the potential to be lot better too. I just wanted to be certain the alternatives had been considered.

First, what is the intended activation point for your process, i.e. does it need to be triggered by an external application or can it be started within Archicad and then query an external application for the intended process parameters?
The activation point is after the file is loaded.
Example of the wanted process:
1. File.pln is opened on a computer with my addon
2. After the file done loading, the addon executes some scripts
3. Done
Solution
Ralph Wessel
Mentor
Tomer1 wrote:
The activation point is after the file is loaded.
Example of the wanted process:
1. File.pln is opened on a computer with my addon
2. After the file done loading, the addon executes some scripts
Assuming that when you say, "File.pln is opened", that means even if the user opens the project:
1) When the add-on Initialise function is called (when it's loaded), call ACAPI_Notify_CatchProjectEvent so Archicad notifies you when project events occur, e.g. opening/saving/closing etc.

2) When Archicad invokes the callback with a project event, check the event type is APINotify_Open

3) You could immediately run whatever process is required on receiving APINotify_Open, but it's safer to ask Archicad to notify your add-on as soon as it's safe for all kinds of activity (some actions can otherwise cause a crash or be ignored). We do this if we want to display some UI component to the user (e.g. show a palette), validate project content or ensure add-on preferences are loaded/valid.

4) To delay processing until an appropriate moment, you can request a callback from Archicad using ACAPI_Command_CallFromEventLoop. The documentation for this function has a code example you can use. Your callback handler can implement whatever process you need to action on the project. If you intend to modify the project, don't forget to fold your process into ACAPI_CallUndoableCommand
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Ralph wrote:
Tomer1 wrote:
The activation point is after the file is loaded.
Example of the wanted process:
1. File.pln is opened on a computer with my addon
2. After the file done loading, the addon executes some scripts
Assuming that when you say, "File.pln is opened", that means even if the user opens the project:
1) When the add-on Initialise function is called (when it's loaded), call ACAPI_Notify_CatchProjectEvent so Archicad notifies you when project events occur, e.g. opening/saving/closing etc.

2) When Archicad invokes the callback with a project event, check the event type is APINotify_Open

3) You could immediately run whatever process is required on receiving APINotify_Open, but it's safer to ask Archicad to notify your add-on as soon as it's safe for all kinds of activity (some actions can otherwise cause a crash or be ignored). We do this if we want to display some UI component to the user (e.g. show a palette), validate project content or ensure add-on preferences are loaded/valid.

4) To delay processing until an appropriate moment, you can request a callback from Archicad using ACAPI_Command_CallFromEventLoop. The documentation for this function has a code example you can use. Your callback handler can implement whatever process you need to action on the project. If you intend to modify the project, don't forget to fold your process into ACAPI_CallUndoableCommand
File.pln is opened means that I opened AC file (Archicad was closed and I double clicked a pln file). Will it work?

Edit:
Worked after setting the addon to preload
Thanks!!
Ralph Wessel
Mentor
Tomer1 wrote:
File.pln is opened means that I opened AC file (Archicad was closed and I double clicked a pln file). Will it work?
Yes, the notification works for any action that opens a project.
Ralph Wessel BArch
Software Engineer Speckle Systems