Getting the directory of the current Archicad file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-07-25
11:36 AM
- last edited on
2022-10-05
01:23 PM
by
Daniel Kassai

Is there a way to get the directory of the current Archicad file we are working on?
Thanks in advance!
Solved! Go to Solution.
- Labels:
-
Add-On (C++)
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-07-25 11:21 PM
API_ProjectInfo projectInfo; ACAPI_Environment(APIEnv_ProjectID, &projectInfo, 0); if (projectInfo.location != nullptr) { IO::Path path; projectInfo.location->ToPath(&path); }The variable
Central Innovation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-07-25 11:42 AM
Are you talking about a teamwork project and its libraries ?
What's your aim ?
Archicad Designer and Teacher
Archicad 15 to 28 FRA FULL
OS 13 Ventura - MacBook Pro M2 max- 32Go RAM
"Quality is never an accident ; it's always the result of an intelligent effort" John Ruskin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-07-25 12:31 PM
API_ProjectInfo projectInfo = {}; GSErrCode err = ACAPI_Environment (APIEnv_ProjectID, &projectInfo); if (err != NoError) return GS::EmptyUniString; if (projectInfo.untitled) // not saved yet return GS::EmptyUniString; if (!projectInfo.teamwork) { GS::UniString directoryOfTheProjectStr; IO::Location projectLocation = *projectInfo.location; projectLocation.DeleteLastLocalName (); projectLocation.ToPath (&directoryOfTheProjectStr); return directoryOfTheProjectStr; }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-07-25 12:32 PM
IO::Location folderLoc; API_SpecFolderID specID = API_ApplicationFolderID; ACAPI_Environment(APIEnv_GetSpecFolderID, &specID, &folderLoc);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-07-25 02:32 PM
Tibor wrote:Tried, it gave a bunch of numbers instead of path..
You can use APIEnv_ProjectID method to get the current project info.API_ProjectInfo projectInfo = {}; GSErrCode err = ACAPI_Environment (APIEnv_ProjectID, &projectInfo); if (err != NoError) return GS::EmptyUniString; if (projectInfo.untitled) // not saved yet return GS::EmptyUniString; if (!projectInfo.teamwork) { GS::UniString directoryOfTheProjectStr; IO::Location projectLocation = *projectInfo.location; projectLocation.DeleteLastLocalName (); projectLocation.ToPath (&directoryOfTheProjectStr); return directoryOfTheProjectStr; }
I think that projectinfo.projectpath should do it for me maybe?
Update:
I am unable to get projectpath from some reason. It doesn’t print it and I don’t know how to cast it to string.
My aim is to get the path of the current ARCHICAD file I’m working on as a string..
My code (seems not to work):
GS::UniString GetCurDir(){ API_ProjectInfo pj={}; ACAPI_Environment(APIEnv_ProjectID, &pj); GS::UniString p=*pj.projectPath; ACAPI_WriteReport(“%s”,true,p); return p; }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-07-25 11:21 PM
API_ProjectInfo projectInfo; ACAPI_Environment(APIEnv_ProjectID, &projectInfo, 0); if (projectInfo.location != nullptr) { IO::Path path; projectInfo.location->ToPath(&path); }The variable
Central Innovation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-07-26 10:27 AM
Tomer1 wrote:Your code is fine. What probably caused a problem is ACAPI_WriteReport. You can print GS::String and UniString directly without %s
. It doesn’t print it
API_ProjectInfo pj = {}; ACAPI_Environment(APIEnv_ProjectID, &pj); GS::UniString p = *pj.projectPath; GS::UniString n = *pj.projectName; ACAPI_WriteReport(p, true); ACAPI_WriteReport(n, true);
Ralph wrote:Tested. This code works.
working code sample

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-07-28 09:24 AM
Windows 10, ARCHICAD 21.
Update:
It finally worked with Ralph’s great code!
But I’m unable to get a sub string with substr (want to remove the name of the file)
Update 2: succeed to remove the name when using the projectName from location (getlaslocalname).
Thanks everyone!
