cancel
Showing results for 
Search instead for 
Did you mean: 
EN
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Getting the directory of the current Archicad file?

Hello

Is there a way to get the directory of the current Archicad file we are working on?

Thanks in advance!
1 Solution

Accepted Solutions
I don't have a working code sample to hand, but something roughly along the following lines should work;
API_ProjectInfo projectInfo;
ACAPI_Environment(APIEnv_ProjectID, &projectInfo, 0);
if (projectInfo.location != nullptr) {
	IO::Path path;
	projectInfo.location->ToPath(&path);
}
The variable path will hold the whole pathname.
Ralph Wessel BArch
Central Innovation

Go to post

7 Replies 7
Hello,

Are you talking about a teamwork project and its libraries ?
What's your aim ?
Christophe - FRANCE
Formateur Archicad indépendant à NANTES
Archicad 15 to 29 FRA FULL
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
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;
}
Anonymous
Not applicable
This is quite straight forward. You just use ACAPI_Enviroment function. API_SpecFolderID is a struct with different key locations to choose form. I'm not sure how it works in Teamwork but I assume that It might be the same since IO:: Location handles both local and net locations.

	IO::Location folderLoc;
	API_SpecFolderID specID = API_ApplicationFolderID;
	ACAPI_Environment(APIEnv_GetSpecFolderID, &specID, &folderLoc);
Anonymous
Not applicable
Tibor wrote:
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;
}
Tried, it gave a bunch of numbers instead of path..
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;
}
I don't have a working code sample to hand, but something roughly along the following lines should work;
API_ProjectInfo projectInfo;
ACAPI_Environment(APIEnv_ProjectID, &projectInfo, 0);
if (projectInfo.location != nullptr) {
	IO::Path path;
	projectInfo.location->ToPath(&path);
}
The variable path will hold the whole pathname.
Ralph Wessel BArch
Central Innovation
Anonymous
Not applicable
Tomer1 wrote:
. It doesn’t print it
Your code is fine. What probably caused a problem is ACAPI_WriteReport. You can print GS::String and UniString directly without %s
		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:
working code sample
Tested. This code works.
Anonymous
Not applicable
It’s just doesn’t print, I use the same code as you do.
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!

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!