Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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
    • Login

    Cinema 4D dies when plugindialog is linked in gui

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 468 Views
    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.
    • H Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 24/06/2011 at 15:28, xxxxxxxx wrote:

      Hi,

      when I link my plugindialog into the gui and set it as default layout and then restart Cinema, it doesn't show up anymore.
      Deleting the "prefs" folder fixes this problem, because the Dialog is no more linked in the gui.

      I assume this is because of CommandData.RestoreLayout ?
      I just can't figure it out.

      Here's the source:

        
      # still quick and dirty  
      import  c4d  
      from    c4d             import Vector  
      from    c4d.documents   import GetFirstDocument, GetActiveDocument, SetActiveDocument  
      from    c4d.gui         import GeUserArea, GeDialog  
      from    c4d.plugins     import CommandData, RegisterCommandPlugin  
        
      def GetDocuments() :  
        def foo() :  
            doc     = GetFirstDocument()  
            while doc:  
                yield doc  
                doc = doc.GetNext()  
        return tuple(foo())  
        
        
      class DocViewer_View(GeUserArea) :  
        rowheight           = 18  
        indentation         = 5  
        color_darker        = Vector(.29)  
        color_lighter       = Vector(.31)  
        color_selected      = Vector(.2)  
        color_text          = Vector(.64705)  
        color_text_marked   = Vector(1., .66, .024)  
        
        
        def __init__(self, parent = None) :  
            if parent:  
                self.InitParent(parent)  
        
        def InitParent(self, parent) :  
            if not isinstance(parent, GeDialog) :  
                return False  
            self.parent     = parent  
            return True  
        
        def DrawMsg(self, x1, y1, x2, y2, msg) :  
            documents       = GetDocuments()  
            active          = GetActiveDocument()  
        
            self.DrawRectangle(x1, y1, x2, y2)  
            self.DrawBorder(c4d.BORDER_THIN_IN, x1, y1, x2, y2)  
        
            for i, doc in enumerate(documents) :  
                if i % 2 == 0:  
                    self.DrawSetPen(self.color_darker)  
                else:  
                    self.DrawSetPen(self.color_lighter)  
                if doc == active:  
                    self.DrawSetTextCol(self.color_text_marked, 999)  
                    self.DrawSetPen(self.color_selected)  
                else:  
                    self.DrawSetTextCol(self.color_text, 999)  
        
                Rect    = {  
                    "x1":       x1,  
                    "x2":       x2,  
                    "y1":       i * self.rowheight,  
                    "y2":       (i + 1) * self.rowheight,  
                }  
        
                self.DrawRectangle(**Rect)  
        
                name    = doc.GetDocumentName()  
                if not name:  
                    name    = "Untitled " + str(i).rjust(3, "0")  
                self.DrawText(name, x1 + self.indentation, Rect["y1"] + 1)  
        
        def InputEvent(self, msg) :  
            device      = msg[c4d.BFM_INPUT_DEVICE]  
            if device == c4d.BFM_INPUT_MOUSE:  
                documents       = GetDocuments()  
        
                global2local    = self.Global2Local()  
                mouseY          = msg[c4d.BFM_INPUT_Y] + global2local["y"]  
                row             = int(mouseY / self.rowheight)  
        
                if row >= len(documents) :  
                    pass  
                else:  
                    SetActiveDocument(documents[row])  
                    c4d.EventAdd()  
                    self.Redraw()  
                if self.parent:  
                    self.parent.Command(self.GetId(), msg)  
        
            return True  
        
        def GetMinSize(self) :  
            return 100, self.rowheight * 2  
        
        
      class DocViewer_Dialog(GeDialog) :  
        ua      = DocViewer_View()  
        ua_id   = 99999  
        
        def __init__(self) :  
            pass  
        
        def CreateLayout(self) :  
            self.ua.InitParent(self)  
            self.AddUserArea(self.ua_id, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT)  
            self.AttachUserArea(self.ua, self.ua_id)  
        
            return True  
        
        
      class DocViewer_Command(CommandData) :  
        dlg             = None  
        COMMAND_ID      = 10009121 # not registered !!  
        COMMAND_ICON    = None  
        
        def Execute(self, doc) :  
            if not self.dlg:  
                self.dlg        = DocViewer_Dialog()  
            self.dlg.Open(c4d.DLG_TYPE_ASYNC)  
        
            return True  
        
        def RestoreLayout(self, subid) :  
            if not self.dlg:  
                self.dlg        = DocViewer_Dialog()  
            return self.dlg.Restore(self.COMMAND_ID, subid)  
        
        @classmethod  
        def Register(cls) :  
            data    = {  
                "id":       cls.COMMAND_ID,  
                "icon":     cls.COMMAND_ICON,  
                "str":      "Documents Viewer",  
                "help":     "Shows up a dialog with all open Documents. You can change the active Document by clicking into the Dialog.",  
                "info":     c4d.PLUGINFLAG_COMMAND_HOTKEY,  
                "dat":      cls(),  
            }  
        
            RegisterCommandPlugin(**data)  
        
        
      if __name__ == "__main__":  
        DocViewer_Command.Register()
      

      I've never been that desperate.. 🤢
      Thanks,
      Niklas

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 24/06/2011 at 17:24, xxxxxxxx wrote:

        In your code you forgot to pass the ID to GeDialog.Open (2nd arg). If you open an asynchronous dialog you have to pass the pluginid.

        Edit:
        Btw,you dont need to pass them in synchronous dialogs.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 25/06/2011 at 00:22, xxxxxxxx wrote:

          Thanks Sebastian ! That did it ! :hugging:
          Perfect ! 😄

          Originally posted by xxxxxxxx

          Dialogs are very error-prone if they are not handled correctly.

          Yes, they are ! 😂
          But you can do cool stuff with them. 🙂

          1 Reply Last reply Reply Quote 0
          • First post
            Last post