Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
Hello I'm trying to understand a way of checking if dialog has closed(Preferences)?
Script opens: c4d.PrefsLib_OpenDialog(c4d.FORMAT_ABCEXPORT) and wait until user closes Preferences
Hi,
@iluxa7k said:
Faster way of checking if dialog has closed
I am slightly confused, because your title implies that you have found a way to check if a GeDialog has closed, that has not been implemented by yourself. At least to my knowledge there is no official way to do this and I also could not think of a hacky way to do it. Would you mind sharing your workaround?
GeDialog
On a totally unrelated topic: The function name PrefsLib_OpenDialog makes me feel itchy.
PrefsLib_OpenDialog
Cheers, zipit
Hello zipit
Found methods at https://github.com/asweigart/pygetwindow
about https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d/index.html?highlight=prefslib_opendialog#c4d.PrefsLib_OpenDialog
thanks for sharing, okay that is so hacky, that I did not even consider it I still have no solution for you, but would like to point out that your solution is rather risky.
Also making Python non-OS-agnostic for such a minor functionality does not seem to be worth it in my opinion.
Hello After analyzing data, found
(u'Preferences', <maxon.interface.LP_c_long object at 0x0000024CCDF7A848>)
But i can't find LP_c_long in maxon.interface or interface in *resource\modules\python\libs\python27\maxon*
@zipit said in Faster way of checking if dialog has closed?:
I assume you are just using the window title as an identifier and not the actual handle? The name Preferences is not that uncommon and you might run into problems when the user is running an app that also spawns a window that title.
I use silly method to seek in string
if str(data)[0:6] == '<maxon': print True
Or how to get data by maxon.interface methods
@iluxa7k said in Faster way of checking if dialog has closed?:
Hello After analyzing data, found (u'Preferences', <maxon.interface.LP_c_long object at 0x0000024CCDF7A848>)
That is rather vague. But generally speaking most parts of the maxon API are read-only, undocumented and a little bit on the buggy side when it comes to Python. I would not bother trying to get anything meaningful out of it.
maxon
If you are really hell-bent on doing this, the best approach IMHO would be not open Cinema's Preferences dialog, but a dialog that wraps around the preferences plugin node. Here you could easily implement a callback for an on_close event. This would also avoid the situation that the user has the preferences docked in his GUI and therefor will never close it. But it comes with its own problems. See the attached script manager script for a sketch on how you could implement this.
on_close
import c4d class PreferencesDialog(c4d.gui.GeDialog): """Dirty little gui wrapper around the preferences node. Attributes: PREFERENCES_ID (int): The id of the preferences plugin node. """ PREFERENCES_ID = 465001632 def __init__(self, on_close_callback=None): """ """ self._on_close_callback = on_close_callback def CreateLayout(self): """We just create a description gui and attach the preferences plugin node to it. This all probably runs under the flag of "not really intended" and due to the sheer size of the description of that node, it does not render very nicely. If you would knew the specific tab you want the user to edit, that would make things considerably easier, as you could just grab that node then and display it. """ # Whit this container you can make it look prettier, I did # not bother, see c4d.gui.DescriptionCustomGui for details. bc = c4d.BaseContainer() # Add a DescriptionCustomGui to the dialog. description_gui = self.AddCustomGui( 0, c4d.CUSTOMGUI_DESCRIPTION, "", c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 1000, 1000, bc) # Find the preferences node and attach it to the DescriptionCustomGui prefs = c4d.plugins.FindPlugin(PreferencesDialog.PREFERENCES_ID) description_gui.SetObject(prefs) return True def AskClose(self): """Call our callback when the dialog is about to be closed. """ if self._on_close_callback: self._on_close_callback() return False def my_callback(): """A little callback function. """ print "Whee, i got called by a closing PreferencesDialog." def main(): """ """ dialog = PreferencesDialog(on_close_callback=my_callback) dialog.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE) if __name__ == "__main__": main()
@maxon: The Python docs on DescriptionCustomGui.SetObject(self, op) say that op has to be of type BaseObject. I am not sure if this intended, but I would assume the required type to actually be BaseList2D.
DescriptionCustomGui.SetObject(self, op)
op
BaseObject
BaseList2D
@zipit cool stuff
update
Thank you for GUI tips!
Inject Maxon GUI to script
LP_c_long
Long story short it's a pointer http://makble.com/the-story-of-lpclong, and I think the method provided by Zipit is the best one, since as he said there is no way to control the behavior of an external (from your plugin) GeDialog.
Cheers, Maxime.