Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

Getting the directory of the current ARCHICAD file?

Anonymous
Not applicable
Hello

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

Thanks in advance!
1 ACCEPTED SOLUTION

Solution
Ralph Wessel
Mentor
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

View solution in original post

7 REPLIES 7

Hello,

Are you talking about a teamwork project and its libraries ?
What's your aim ?
Christophe - FRANCE
Archicad Designer and Teacher
Archicad 15 to 25 FRA FULL

OS 11.6 Big Sur - MacBook Pro 2015 - 16Go RAM
"Quality is never an accident ; it's always the result of an intelligent effort" John Ruskin

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;
}

Solution
Ralph Wessel
Mentor
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

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!

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!