Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Register
    • Login

    Faster way of checking if dialog has closed?

    Cinema 4D SDK
    python
    3
    8
    1.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • I
      iluxa7k
      last edited by

      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

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @iluxa7k
        last edited by

        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?

        On a totally unrelated topic: The function name PrefsLib_OpenDialog makes me feel itchy.

        Cheers,
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • I
          iluxa7k
          last edited by

          Hello zipit

          Found methods at https://github.com/asweigart/pygetwindow

          about https://developers.maxon.net/docs/py/2023_2/modules/c4d/index.html?highlight=prefslib_opendialog#c4d.PrefsLib_OpenDialog

          1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand
            last edited by

            Hi,

            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.

            • When the user has docked the Preferences dialog there will be no window handle for it. Which might leave your code in an undefined state, depending on your implementation.
            • 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.

            Also making Python non-OS-agnostic for such a minor functionality does not seem to be worth it in my opinion.

            Cheers,
            zipit

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 1
            • I
              iluxa7k
              last edited by iluxa7k

              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 ❓

              ferdinandF M 2 Replies Last reply Reply Quote 0
              • ferdinandF
                ferdinand @iluxa7k
                last edited by ferdinand

                @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.

                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.

                Cheers,
                zipit

                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.

                MAXON SDK Specialist
                developers.maxon.net

                I 1 Reply Last reply Reply Quote 2
                • I
                  iluxa7k @ferdinand
                  last edited by iluxa7k

                  @zipit 🤘 cool stuff

                  update 🔴

                  Thank you for GUI tips!

                  Inject Maxon GUI to script

                  abcseq.png

                  1 Reply Last reply Reply Quote 0
                  • M
                    m_adam @iluxa7k
                    last edited by

                    @iluxa7k said in Faster way of checking if dialog has closed?:

                    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.

                    MAXON SDK Specialist

                    Development Blog, MAXON Registered Developer

                    1 Reply Last reply Reply Quote 1
                    • ferdinandF ferdinand referenced this topic on
                    • First post
                      Last post