Archicad C++ API
About Archicad add-on development using the C++ API.

[SOLVED] Opening text file into add-on

Anonymous
Not applicable
Hi everybody!

I am new to archicad and C++. I am developing the add-on on x-code 8.3.2. The add-on is for my company, which will import materials and build ups from text file. Now I have a struggle and I can't find any method in the API for opening simple file dialog. The closest thing I find is APIIo_​OpenPictureDialogID, but it doesn't suite my needs. Am I missing something here?

All the best, Julian
5 REPLIES 5
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi Julian,
static bool	GetOpenFile (IO::Location*	dloc, const char* fileExtensions, const GS::UniString& filterText) 
{ 
	if (dloc == nullptr) 
		return false; 
 
	FTM::TypeID	retID; 
	FTM::FileTypeManager	ftman ("MyManager"); 
	FTM::FileType			type (nullptr, fileExtensions, 0, 0, 0); 
	FTM::TypeID				id = FTM::FileTypeManager::SearchForType (type); 
	if (id == FTM::UnknownType) 
		id = ftman.AddType (type); 
 
	DG::FileDialog	dlg (DG::FileDialog::OpenFile);						// Open only 1 file 
	UIndex	i = dlg.AddFilter (id, DG::FileDialog::DisplayExtensions); 
	dlg.SetFilterText (i, filterText); 
 
	if (!dlg.Invoke ()) 
		return false; 
 
	*dloc = dlg.GetSelectedFile (); 
	return true; 
} 
 
// ----------------------------------------------------------------------------- 
// Usage: 
IO::Location selectedTextFileLoc; 
if (!GetOpenFile (&selectedTextFileLoc, "Text File", "*.txt")) 
	return;


This simple GetOpenFile function opens a file dialog for you.

Regards,
Tibor
Anonymous
Not applicable
Hey Tibor,

Thank you very much !!
Anonymous
Not applicable
I have another question and I don't want to open a new thread for it. For debugging purposes I want to log some data. I'm opening the report window from File > Info > Session Report. Is this the right way to open it?

Also I'm using WriteReport_Alert() method, but I only get the popup, without logging the data into the report window of archicad. I am using the demo version of Archicad, so is it possible that ACAPI_WriteReport() doesn't work with the demo version of archicad and doesn't want to write to that file?

Thanks in advance, Julian
Akos Somorjai
Graphisoft
Graphisoft
jcimentarov wrote:
I have another question and I don't want to open a new thread for it. For debugging purposes I want to log some data. I'm opening the report window from File > Info > Session Report. Is this the right way to open it?

Also I'm using WriteReport_Alert() method, but I only get the popup, without logging the data into the report window of archicad. I am using the demo version of Archicad, so is it possible that ACAPI_WriteReport() doesn't work with the demo version of archicad and doesn't want to write to that file?

Thanks in advance, Julian
Well, depends on where you want to see the log, I would recommend using a simple DBPrintf () call, which writes to the system.log in Console.

ACAPI_WriteReport shouldn't behave differently in the DEMO version, but you can always order a developer license.

Best, Akos
Anonymous
Not applicable
A DBPrintf () call from my add-on doesn't write anything in the system.log ... Is there anything specific that I need to do in order to make it work ?

All the best, Julian