The Global Archicad Community

Stay informed. Get help. Share your knowledge.

Discussions about using GRAPHISOFT's tools (Archicad API, BIMx API, BIMcloud API) for independent software developers

Moderators: ejrolon, Barry Kelly, Karl Ottenstein, LaszloNagy, Gordana Radonic, nbalogh, gkmethy, mnguyen, Viktor Kovacs, Mihály Palenik, Tibor Lorántfy, rmasaki, MOREH Tamas, Akos Somorjai, Ed Brown

#240820
Hi Lukasz,

You can get informations about the project with the ACAPI_Environment (APIEnv_ProjectID, ...) method call.
Code: Select all
API_ProjectInfo		projectInfo; 
GSErrCode			err = ACAPI_Environment (APIEnv_ProjectID, &projectInfo, NULL); 
if (err != NoError) { 
	ErrorBeep ("APIEnv_ProjectID", err); 
	return; 
} 
 
if (projectInfo.untitled) { 
	WriteReport ("Project file has not been saved yet"); 
} else { 
	IO::Path		projectPath; 
	IO::Name		projectName; 
 
	if (!projectInfo.teamwork) { 
		projectInfo.location->ToPath (&projectPath); 
		WriteReport ("Solo Project location: %s", (const char *) projectPath); 
		projectInfo.location->GetLastLocalName (&projectName); 
		WriteReport ("Project Name: %s", (const char *) projectName.ToCStr ()); 
	} else { 
		projectInfo.location_team->ToPath (&projectPath); 
		WriteReport ("Shared Project: %s", (const char *) projectPath); 
		projectInfo.location_team->GetLastLocalName (&projectName); 
		WriteReport ("Project Name: %s", (const char *) projectName.ToCStr ()); 
	} 
 
	if (projectInfo.location != NULL) 
		delete projectInfo.location; 
	if (projectInfo.location_team != NULL) 
		delete projectInfo.location_team; 
}
Regards,
Tibor
By wacim
#287762
Hello Tibor,
First of all i'm new here, i've been tinkering around with archicad API for a few days now (so keep in mind i'm still a noob).

I've been trying to get the project's name, as shown in the picture below, the value testtest.
https://drive.google.com/file/d/11gLYin ... sp=sharing
I set this value (testtest) manually, and saved the file since, closed it, opened it again, value was still there.
When i try to access it from the addon i'm coding (dev kit 21), i keep getting (null).
Here's how i'm attempting to do this:
Code: Select all
API_ProjectInfo		projectInfo;
GSErrCode			err = ACAPI_Environment(APIEnv_ProjectID,  &projectInfo, NULL);
			
if (err != NoError) {
	ErrorBeep("APIEnv_ProjectID", err);
	return;
}
if (projectInfo.untitled) {
	WriteReport("Project file has not been saved yet");
}
else {
	DBPrintf("\n\nprojectname = %s \n\n", projectInfo.projectName);
}
When reading this page: http://archicadapi.graphisoft.com/docum ... rojectinfo
I can't see what i'm doing wrong...

Any help or insights would be much appreciated
Wacim
#287973
Hi Wacim!

Well done, it's nice from a beginner!
The projectName field of the API_ProjectInfo structure is a pointer to a GS::UniString object, which means you can get the "const char*" string from it the following way:
Code: Select all
projectInfo.projectName->ToCStr()->Get()
So instead of this:
wacim wrote: Wed Oct 17, 2018 4:48 pm Here's how i'm attempting to do this:
Code: Select all
API_ProjectInfo		projectInfo;
...
	DBPrintf("\n\nprojectname = %s \n\n", projectInfo.projectName);
Use this:
Code: Select all
API_ProjectInfo     projectInfo;
...
    DBPrintf("\n\nprojectname = %s \n\n", projectInfo.projectName->ToCStr()->Get());
I hope this helps.
Regards,
Tibor