PySide2 Integration



  • Hi,

    I'm coming to C4D scriptin from a Houdini background. I've made a project loader/saver dialog which is working in Houdini/Nuke (they both ship with PySide2) and would like to use the interface in C4D.

    On copying the PySide2 lib from the Houdini site-packages I'm hit with DLL errors. It also seems PySide2 is not available as a wheel or using pip with Python27?

    My workaround has been to install PySide into the C4D PYTHONPATH (which works fine) and use Qt.py for compatibility, but I'm wondering if anyone has successfully managed to use PySide2 with C4D?



  • Additional question:
    I'm creating a QApplication and then a QDialog but I can't seem to close the QApplication at all when the dialog is closed?
    This means even when C4D is closed normally it's still running in the background and needs to be force-quit. Any suggestions appreciated



  • Why don't you avoid all those difficulties and simply implement that dialog using the C4D UI?


  • Global Moderator

    Hi,

    here at MAXON we have no experience with PySide, I can't really give much feedback on that specifically.

    In general we try to stick to the environment described by the VFX Reference Platform. For Python this means, inside of Cinema 4D it is still Python 2.7 being used. As far as I can see, PySide2 relies on Python 3, only. So I doubt, it's possible to make use of PySide2 inside of Cinema 4D at the moment.

    Also we do not recommend to mix other/external GUI systems in Cinema 4D plugins. Another thing we can not really provide support for. I have the feeling in order to get constructive feedback on your last question about the application staying open upon quitting Cinema 4D you'd need to provide additional details. I would leave this topic to our community. My recommendation would be to go with @fwilleke80's suggestion and stick to Cinema 4D's GUI system.

    I have turned this thread into a question and moved this thread to the General Programming & Discussions category.

    Cheers,
    Andreas



  • @fwilleke80 - I was just hoping to avoid rewriting existing code I have working in Houdini/Nuke, as it's 80% ui-building and cleanly shared between implementations. I've also never used the c4d python api and don't use C4D at all.

    @a_block Thanks for the help. Houdini/Nuke both use Python27 with PySide2 although I'm not sure of the details



  • I've solved my 2nd issue which is good news.
    I have a general c4d api question which I'll post here to avoid spam:

    I'm calling c4d.documents.SaveDocument() with a new filepath, expecting this to work like a 'save as' command with the open scene becoming this new file.

    However it doesn't I've had to do this workaround, which seems strange?

    scene = c4d.documents.GetActiveDocument()
    c4d.documents.SaveDocument(scene, newpath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, c4d.FORMAT_C4DEXPORT)
    c4d.documents.LoadFile(newpath)
    c4d.documents.KillDocument(scene)
    

  • Global Moderator

    Hi,

    indeed SaveDocument() does save the document, only.
    Your approach of simulating "save as" functionality is fine. If you can live with a requester, you could also use SAVEDOCUMENTFLAGS_SAVEAS instead.

    If you don't mind, I'd like to ask you to please open separate threads for such unrelated questions. We do not regard this as spamming, but regard it helpful for future users searching for certain information. Such questions would go into the Cinema 4D Development category.
    Also please consider using code tags. I have changed this in your previous post.

    Cheers,
    Andreas