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
    • Recent
    • Tags
    • Users
    • Login

    Docx Module with C4D?

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 494 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

      On 19/09/2013 at 14:28, xxxxxxxx wrote:

      Hoping some of the more experienced coders here can shed some light on this one.

      I can't get the docx module to work with C4D. Trying to create a docx from within c4d, and insert some text. A Word 2003 .doc would be even nicer, but I couldn't find a module for it.

      docx module:
      https://github.com/mikemaccana/python-docx

      Any help is appreciated!

      ---
      More specifically, the error I'm getting is from the Nose module (required for python docx to work?), core.py:

      sysExit(False) cannot be called within this embedded environment.

      ---
      Or using another example I'm getting:

      from lxml import etree ImportError:DLL load failed: The specified module could not be found.

      To fix that, I tried copying the xml/etree module from Python itself, and it bypassed that error but instead says:

      Module object has no attribute Element.

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

        On 20/09/2013 at 10:19, xxxxxxxx wrote:

        I guess you are better of in some forum for that specific docx module. Chances you will
        find here someone that has experience with it are quite low. Your posted exception can
        be caused by everything from missing modules to version conflicts.

        Is there a specific reason why it has to be the word 2003 format ? XML is usually the format 
        of choice for such tasks. Also the rtf format is very simple to write, colors and styles are directly 
        included with the ascii stream (it is human readable to some degree like the XML format).

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

          On 21/09/2013 at 02:48, xxxxxxxx wrote:

          You're probably right about posting it in a docx forum, but it must be how C4D deals with modules that are maybe path specific (I'm guessing) or maybe the version of Python that's included with C4D. Cause it works perfectly if I just run the example .py file from within python 2.7.5/.../site-packages/docx. Generates the file and everything. So the issue starts with loading the module in C4D.

          It does not have to be word 2003 format. I just have it installed, so I thought it might be better to test actual .doc files instead of using Microsofts docx to doc converter. Cause it might mess up the formatting, and have me thinking it's the python script that's doing it.

          I tried PyRTF, and it actually works!!! It's appearantly very old (2005?) and no longer supported, but at least it works 😃 Not sure how to make it output the .rtf file in another location than the location of the .c4d file (or Cinema 4D's folder, if the project is not saved), but it's no biggie. So a big thanks for the suggestion!

          I would still love to get python-docx working though. Hopefully someone from Maxon might reply, with how to deal with embedded environment issues, as it seems to be the main problem.

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

            On 21/09/2013 at 03:38, xxxxxxxx wrote:

            1. The c4d python interpreter is python 2.6. Many packages use python 2.7 as a prerequisite today, 
            because of some fundamental changes which came with 2.7, allowing deeper access with hooks 
            on built in functions and so on. However these changes came with quite a speed bump (python has 
            the tendency to get slower which each version (3k can be almost 3 times slower than 2.6). That 
            might be the reason why Sebastian initially chose 2.6 and Maxon is now sticking with it.

            2. I actually meant you could encode the RTF format yourself, as it is quite simple. I have done
            it once in C# for a RTF-style control. Less external packages is always a good thing imho.

            http://msdn.microsoft.com/en-us/library/office/aa140277(v=office.10).aspx

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

              On 21/09/2013 at 06:39, xxxxxxxx wrote:

              1. Good to know, will try the version of python-docx and lxml (required) for 2.6 then and see how it goes.

              2. Sweet, I'll have a look at that as well. I never thought about using rtf for doc files, but it's looking pretty damn good so far 🙂 So thanks for that one!

              PyRTF save location was a really easy fix using BaseDocument.GetDocumentPath() and shutil.move.

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

                On 21/09/2013 at 08:38, xxxxxxxx wrote:

                Tried using 2.6 versions, still don't work. Problem lies with this line:

                import etree from lxml

                It's 100% there though, cause I can run it from within Pythons dir. Also I see some files like etree.pyd and stuff in the lxml folder.

                According to this post, it seems to be a problem with embedding, not sure if C4D has a way of circumvent this issue?

                https://mailman-mail5.webfaction.com/pipermail/lxml/2011-June/006079.html

                Probably way to complicated to get it to work, if even possible, maybe I should stick to rtf.

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