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

[SOLVED] Get Project name in Add-On

Anonymous
Not applicable
Hi

How can I get Project Name or file name in ArchiCAD Add-On?

Thanks

Lukasz
1 ACCEPTED SOLUTION

Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi Lukasz,

You can get informations about the project with the ACAPI_Environment (APIEnv_ProjectID, ...) method call.
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

View solution in original post

5 REPLIES 5

Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi Lukasz,

You can get informations about the project with the ACAPI_Environment (APIEnv_ProjectID, ...) method call.
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

Anonymous
Not applicable
Thanks for your help. It is working

Best Regards
Lukasz

Anonymous
Not applicable
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/11gLYinCXFZuUj9C-o8uiFcHBRlnv9aod/view?usp=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:

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/documentation/api_projectinfo
I can't see what i'm doing wrong...

Any help or insights would be much appreciated
Wacim

Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
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:
projectInfo.projectName->ToCStr()->Get()
So instead of this:
wacim wrote:
Here's how i'm attempting to do this:

API_ProjectInfo		projectInfo;
...
	DBPrintf("\n\nprojectname = %s \n\n", projectInfo.projectName);
Use this:

API_ProjectInfo     projectInfo;
...
    DBPrintf("\n\nprojectname = %s \n\n", projectInfo.projectName->ToCStr()->Get());
I hope this helps.
Regards,
Tibor

Anonymous
Not applicable
Thanks again Tibor
I finally achieved this with APIAny_GetAutoTextKeysID
great example given here:
http://archicadapi.graphisoft.com/documentation/apiany_getautotextkeysid

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!