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

[GUI] DG::Palette disappears

Anonymous
Not applicable
Hello,

When i use DG::ModalDialog and run method Invoke() my GUI stays on top of the window and message processing system works fine. But when i use DG::Palette (i need it, because I have to have possibility to select items during plug-in is running) there is no Invoke method:/ I've try:
GDLInterface gdlInterface; 
	gdlInterface.Activate(); 
	gdlInterface.BeginEventProcessing(); 
	gdlInterface.Show(); 
	gdlInterface.BringToFront();

GDLInterface inherits from DG::Palette.
BUT my interface disappears immediately after in shows up.
How can I use palette? Should it be running in thread?
GUI is turned on from menu.

Maciek
3 REPLIES 3
Anonymous
Not applicable
Hello.

I still haven't found solution of my problem. These objects for creating dialog boxes are great. But only for modal dialogs. With Palette which inherits from ModelessBase it's not.
GSErrCode __ACENV_CALL	CommandHandler (const API_MenuParams * params)   
{   
	switch(params->menuItemRef.menuResID)   
	{   
	case 32500:   
		switch(params->menuItemRef.itemIndex)   
		{   
		case 1:   
			{ // <-- here Palette should show   
				DG::Rect rect;   
				rect.Set(10, 10, 100, 100);   
				DG::Palette palette(rect);   
				palette.BeginEventProcessing();   
				palette.Show();   
				// here destructor works, like it should, and palette closes   
			}   
		}   
	}   
	return NoError;   
}		// CommandHandler ()

I've try to use pointers, but ArchiCAD crashes.

I haven't found any functions, like RegisterPalette, and I really need to make it working.
Did anyone wrote plugin which uses palette as main window and make it working??

Main problem is that I wrote a lot of code which uses object oriented dialog manager. It works fine with DG::ModalDialog, but with DG::Palette don't, because Palette is destroyed right after it was created... Please help...
Ralph Wessel
Mentor
bamboos wrote:
I still haven't found solution of my problem. These objects for creating dialog boxes are great. But only for modal dialogs. With Palette which inherits from ModelessBase it's not.
[...]
I've try to use pointers, but ArchiCAD crashes.
Did anyone wrote plugin which uses palette as main window and make it working?? Main problem is that I wrote a lot of code which uses object oriented dialog manager. It works fine with DG::ModalDialog, but with DG::Palette don't, because Palette is destroyed right after it was created... Please help...
I'm guessing the reason for the problem is that the palette object has to persist outside of the scope of the menu-handler callback. Modal dialogs don't have this problem because you're finished with the dialog before returning from the callback.

You're on the right track using a pointer, but I suspect you haven't allocated memory for the object by using 'new'. If your class is called 'GDL Interface', you would create an instance with something like
GDLInterface* interfacePalette = new GDLInterface;
You also need to make sure the pointer is a global variable (initialised to 0), perhaps a static member variable of the GDLInterface class, and keep the constructor private so you get an instance with something like
 GDLInterface* interfacePalette = GDLInterface::getInstance();
Finally, make sure ArchiCAD knows your add-on has to remain loaded (see ACAPI_KeepInMemory) and the instance is deleted before the add-on shuts down.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Yes!!!

Ralph Wessel, you helped me a lot. I've try pointers and memory allocation by new, but ArchiCAD crashed. Function ACAPI_KeepInMemory solved the problem.

Thanks again.
Maciek