cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
2024 Technology Preview Program

2024 Technology Preview Program:
Master powerful new features and shape the latest BIM-enabled innovations

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

How to filter open file type with DG Openfile?

Newbie
Participant

Is there anyone know with this DG::GetOpenFile() function, how to set its filter to be able to open only .pln or .pla type?

 

3 REPLIES 3
Joel Buehler
Enthusiast

mmmh i can't find the GetOpenFile function in the documentation and neither in the DG_Test example. 

are you maybe speaking of the Open File Dialog? Something like this:

 

JoelBuehler_0-1689200694077.png

 

When yes, the filter system for this dialog ist quite simple:

 

	//OPEN DIALOG UNISTRINGS SETTINGS
	const GS::UniString input = "Open Button... =)";
	const GS::UniString inputFilter = "Excel Files";
	const char* fileExtensions = "xls";

	//FILE TYPE MANAGER SETTINGS
	FTM::TypeID	retID;
	FTM::FileTypeManager ftman("xls");
	FTM::FileType type(nullptr, fileExtensions, 0, 0, 0);
	FTM::TypeID  id = FTM::FileTypeManager::SearchForType(type);
	if (id == FTM::UnknownType)
		id = ftman.AddType(type);

	//FILE DIALOG SETTINGS
	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, inputFilter);

	//INIT OF IO LOCATION
	IO::Location location;
	if (!dlg.Invoke())
	{
		ACAPI_WriteReport("ERROR IN OPEN FILE DIALOG!", false);
	}
	else
	{
		location = dlg.GetSelectedFile();
                   // with the location you can start working on the file
	}

 

You find this in a modified version in the DG_Test example 😃 

 

Hi Joel,

From your code below, the fileExtensions parameter can be only "xls". Which recently it could be "xls" or "xlsx", so how could it filter with both format? 

 

	//OPEN DIALOG UNISTRINGS SETTINGS
	const GS::UniString input = "Open Button... =)";
	const GS::UniString inputFilter = "Excel Files";
	const char* fileExtensions = "xls";

	//FILE TYPE MANAGER SETTINGS
	FTM::TypeID	retID;
	FTM::FileTypeManager ftman("xls");
	FTM::FileType type(nullptr, fileExtensions, 0, 0, 0);

like this: 

 

 

	FTM::FileTypeManager	ftMan("Exel Files");
	FTM::GroupID			gid = ftMan.AddGroup("Excel Old Format");
	ftMan.AddType(FTM::FileType("ExcelOld", "xls", '    ', '    ', 0), gid);

	FTM::GroupID			gid2 = ftMan.AddGroup("Excel New Format");
	ftMan.AddType(FTM::FileType("ExcelNew", "xlsx", '    ', '    ', 0), gid2);

	DG::FileDialog  flDlg(DG::FileDialog::OpenFile);
	flDlg.AddFilter(gid);
	flDlg.AddFilter(gid2);

 

 

results in this:

 

JoelBuehler_0-1689454422323.pngJoelBuehler_1-1689454433615.png

 

by the way: The Archicad API has the very cool excel capabilities since the paid version of the libXl library is a part of archicad. 

https://www.libxl.com/