Objects created in real time



  • 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())
    


  • 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



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



  • 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



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



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

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

    Cheers,
    Manuel