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
    • Login

    Objects created in real time

    Cinema 4D SDK
    python r19 r21 r20
    5
    6
    965
    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.
    • KantroninK
      Kantronin
      last edited by Manuel

      Hi,
      I an converting all my C.O.F.F.E.E scripts to python.
      But I have a problem with python at the real-time display of the objects I create.
      I synthesized this problem in the simplified script below.
      If I press on the button <Creation null polygon> the polygon will only show on the screen when I close the plugin window.
      How to make the polygon appear on the screen without being obliged to close the plugin window ?

      import c4d
      from c4d import gui, documents
      
      button_1 = 1000
      
      class MyDialog(c4d.gui.GeDialog):
      	def CreateLayout(self):
      		self.SetTitle("Creation polygon")	
      		self.AddButton(button_1, c4d.BFH_LEFT, 300, 24, "Creation null polygon")
      		self.GroupEnd()
      		
      		return True
      
      	def Command(self, cid, msg):
      		if cid == button_1:
      			polygon = c4d.BaseObject(c4d.Opolygon)
      			doc = c4d.documents.GetActiveDocument()
      			doc.InsertObject(polygon)  
      			c4d.EventAdd()
      
      		return True
      
      class MyCommandData(c4d.plugins.CommandData):
      	def Execute(self, doc):
      		dlg = MyDialog()
      		dlg.Open(c4d.DLG_TYPE_MODAL, -1, -1, 400, 200)
      		dlg.InitValues(self)
      		return True
      
      if __name__ == "__main__":
      	c4d.plugins.RegisterCommandPlugin(id=10000015, 
                                            str="Creation polygon", 
                                            info=0, 
                                            icon=c4d.bitmaps.BaseBitmap(), 
                                            help="", 
                                            dat=MyCommandData())
      
      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by ferdinand

        Hi,

        have you tried using a non-modal dialog? I am using dialogs not very often, but it could be possible that the modal dialog blocks redraws of your scene.

        dlg.Open(c4d.DLG_TYPE_ASYNC, -1, -1, 400, 200)
        

        Sometimes you have also to invoke a redraw manually.

        c4d.EventAdd(c4d.EVENT_FORCEREDRAW) 
        
        or
        
        c4d.DrawViews(c4d.DRAWFLAGS_NONE)
        

        Cannot say much else, do not have c4d here to test your code.

        Cheers
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 1
        • M
          mp5gosu
          last edited by

          You are calling the Dialog via DLG_TYPE_MODAL. So the Dialog is blocking the main thread until you close it.
          Try opening the dialog with DLG_TYPE_ASYNC.

          1 Reply Last reply Reply Quote 1
          • KantroninK
            Kantronin
            last edited by

            It was indeed the modal window that prevented the real-time display of objects.
            By putting the code below, the display of objects is immediate.

            class MyCommandData(c4d.plugins.CommandData):
            def Execute(self, doc):
            self.dlg = MyDialog()
            self.dlg.Open(c4d.DLG_TYPE_ASYNC, -1, -1, 400, 200)
            return True

            However, the plugin window opens to the left of my screen and to move it to the center of the screen, I must first enlarge it.
            I find that a little strange !

            But it can be considered that my problem is solved.

            Thank you for your answers

            CairynC 1 Reply Last reply Reply Quote 0
            • CairynC
              Cairyn @Kantronin
              last edited by

              @Kantronin said in Objects created in real time:

                self.dlg.Open(c4d.DLG_TYPE_ASYNC, -1, -1, 400, 200)
              

              However, the plugin window opens to the left of my screen and to move it to the center of the screen, I must first enlarge it.

              The GeDialog manual says:

              If xpos=-1 and ypos=-1 the dialog will be opened at the current mouse position.
              If xpos=-2 and ypos=-2 the dialog will be opened at the center of the screen.

              So, if the dialog opens to the left of your screen, I guess that's where your mouse was? Try -2, -2.

              1 Reply Last reply Reply Quote 1
              • ManuelM
                Manuel
                last edited by Manuel

                Hello,

                For your next threads, please help us keeping things organised and clean. I know it's not your priority but it really simplify our work here.

                • Q&A New Functionality.
                • How to Post Questions especially the tagging part.

                @zipit and @Cairyn have already answer here (thanks a lot) nothing to add.

                Cheers,
                Manuel

                MAXON SDK Specialist

                MAXON Registered Developer

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