Docx Module with C4D?



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



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



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



  • 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



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



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


Log in to reply