We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

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

[SOLVED] Is there File chooser dialog class or method

Anonymous
Not applicable
Hi there

I would like to know is there a class or method to open file chooser dialog ?

Thanks in advance!
2 REPLIES 2
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

Yes, you can use DG::FileDialog for opening or saving files.
Here is an example code for you (copied from Communication_Manager example Add-On):
static bool	GetOpenFile (IO::Location*	dloc, const char* fileExtensions, const GS::UniString& filterText) 
{ 
	FTM::TypeID	retID; 
	FTM::FileTypeManager	ftman ("MyManager"); 
	FTM::FileType			type (NULL, 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);	// Force it on mac... 
	dlg.SetFilterText (i, filterText); 
 
	if (dlg.Invoke ()) { 
		*dloc = dlg.GetSelectedFile (); 
		return (true); 
	} else 
		return (false); 
} 
 
// ----------------------------------------------------------------------------- 
 
// Using: 
	IO::Location dwgFileLoc; 
	if (!GetOpenFile (&dwgFileLoc, "dwg", "*.dwg")) 
		return; 
 
	IO::Name	dwgName; 
	dwgFileLoc.GetLastLocalName (&dwgName);

Note that the type of the FileDialog could be the followings: (see in DGFileDialog.hpp)
	enum Type { 
		OpenFile, 
		OpenMultiFile, 
		OpenFolder, 
		OpenMultiFolder, 
		Save 
	};

Regards,
Tibor
Anonymous
Not applicable
Hi.

Thank you for the quick response.