<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Smart-Page.net &#187; Python</title>
	<atom:link href="http://www.smart-page.net/blog/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.smart-page.net/blog</link>
	<description>C++ / C# / Py / Actionscript ... &#039;My God. It&#039;s full of stars!&#039;</description>
	<lastBuildDate>Thu, 23 Jun 2011 00:14:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Advanced Python plugin coding for Cinema 4D</title>
		<link>http://www.smart-page.net/blog/2011/05/09/advanced-python-plugin-coding-for-cinema-4d/</link>
		<comments>http://www.smart-page.net/blog/2011/05/09/advanced-python-plugin-coding-for-cinema-4d/#comments</comments>
		<pubDate>Sun, 08 May 2011 22:31:06 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[cinema 4D]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Plugin development]]></category>
		<category><![CDATA[Pydev]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=1215</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2011/05/09/advanced-python-plugin-coding-for-cinema-4d/" title="Advanced Python plugin coding for Cinema 4D"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/title2.32lgm6px71s0w08c8gkk8cwsw.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Advanced Python plugin coding for Cinema 4D" style="float:left;padding:0 10px 10px 0;" ></a>It&#8217;s been a long time&#8230; how have you been? This is going to be another Python/Cinema 4D related post. While python is great for quickly scripting workflow optimizing tools, prototype stuff or write generators and tags, is it suited for big, complex plugin development? It is! You get &#8216;nearly&#8217; full access to the C++ API [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2011/05/09/advanced-python-plugin-coding-for-cinema-4d/" title="Advanced Python plugin coding for Cinema 4D"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/title2.32lgm6px71s0w08c8gkk8cwsw.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Advanced Python plugin coding for Cinema 4D" style="float:left;padding:0 10px 10px 0;" ></a><p>It&#8217;s been a long time&#8230; how have you been?</p>
<p>This is going to be another Python/Cinema 4D related post.</p>
<p>While python is great for quickly scripting workflow optimizing tools, prototype stuff or write generators and tags, is it suited for big, complex plugin development?</p>
<p><span id="more-1215"></span>It is!</p>
<p>You get &#8216;nearly&#8217; full access to the C++ API of Cinema 4D, don&#8217;t have to compile or worry much about platform dependencies, can easily find a ton of neat recipes and libraries out there&#8230;</p>
<p>So it’s not only possible to code full-fledged python plugins but it even has its advantages over classical C++ development.</p>
<p>Imagine you wrote a nifty script, decided to make it a simple plugin, and now want to take it a step further &#8211; add more features, a complex GUI with some dialogs etc&#8230;</p>
<p>If you are still working with the script editor by now, things will most likely start to get out of hand as you introduce more modules and classes, deal with more code and more functionality.</p>
<p>This is the point where you might want to look out for a little help.</p>
<p>We are going to set up an IDE (Integrated Development Environment), talk a bit about modules/packages and finally I will try to give some general hints and tips.<br />
<br/></p>
<h1>Coding Environment/IDE:</h1>
<h2>Prepare Cinema 4D:</h2>
<p>You may skip this part, but I highly recommend it:</p>
<ul>
<li>Make a copy of your Cinema 4D installation &#8211; name it <em>&#8220;Cinema 4D R12 Dev&#8221;</em> for example.</li>
<li>Get rid of all Cinema 4D plugins you don&#8217;t need for your development</li>
<li>Place an empty text file named <em>&#8220;c4d_debug.txt&#8221;</em> into the root folder of your Cinema 4D copy.</li>
</ul>
<p>This will slow Cinema 4D down a bit, but enables you to monitor memory leaks.</p>
<p>We will add some useful things on Cinema 4D-side later &#8211; for now let&#8217;s continue with the Eclipse setup&#8230;<br />
<br/></p>
<h2>Eclipse:</h2>
<p><img class="alignnone size-full wp-image-1217" title="eclipse" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/eclipse.jpg" alt="" width="683" height="101" /></p>
<p>If you never used one, think of an IDE as your workshop, it’s a collection of tools as well as the place where you do and organize your coding work.</p>
<p>Eclipse is one of the most popular &#8211; its Java based, open source, free to use and most importantly has excellent support for python.</p>
<p>So let&#8217;s start by downloading and installing Eclipse Classic from <a href="http://www.eclipse.org/downloads/" target="_blank">http://www.eclipse.org/downloads/</a><br />
If you don&#8217;t have the <a href="http://www.java.com/de/download/"  target="_blank">Java Runtime Environment</a> installed jet, you need to do this first.<br />
<br/></p>
<h2>PyDev:</h2>
<p>As said before, Eclipse has excellent python support &#8211; but not out of the box, so we are going to install <a href="http://www.pydev.org" target="_blank">PyDev</a>.</p>
<p>PyDev will help you coding by adding syntax highlighting, code completion and much more.<br />
Should you encounter any trouble with the following steps, please refer to the PyDev <a href="http://pydev.org/manual_101_install.html" target="_blank">installation manual</a>.</p>
<ul>
<li>After installation, startup Eclipse, click <em>&#8220;Help&#8221;, </em>and chose <em>&#8220;Install New Software&#8230;&#8221;.</em></li>
<li>Next click the <em>&#8220;Add&#8230;&#8221;</em> button, type in <em>&#8220;PyDev&#8221;</em> as name and <em>&#8220;http://pydev.org/updates&#8221; </em>as location &#8211; then confirm.</li>
<li>Now enter <em>&#8220;PyDev&#8221;</em> in the <em>&#8220;Work with:&#8221;</em> field, you should see an entry<em> &#8220;PyDev for Eclipse&#8221; </em>- check it and click <em>&#8220;Next&#8221;.</em></li>
</ul>
<p>After confirming again and accepting the terms, it will download and install.</p>
<ul>
<li>Click <em>&#8220;Windows&#8221;</em> and open the <em>&#8220;Preferences&#8221;</em> dialog.</li>
<li>Select PyDev and the child <em>&#8220;Interpreter &#8211; Python&#8221;</em></li>
<li>Click <em>&#8220;New&#8230;&#8221;</em>, input <em>&#8220;Python Cinema 4D&#8221;</em> as name and browse to your Cinema 4D installation.</li>
<li>In <em>&#8220;/resource/modules/python/res/Python.win64.framework/&#8221;</em> select the <em>python.exe</em>.</li>
<li>Confirm your selection and the paths PyDev wants to add to your syspath.</li>
</ul>
<p>So much for the PyDev installation itself, now we have to associate the Cinema 4D Python plugin extension *.pyp with PyDev to enable syntax highlighting and code completion for those files as well:</p>
<ul>
<li>Open <em>&#8216;Window&#8217;</em> within the file-menu and click <em>&#8216;Preferences&#8217;</em></li>
<li>Select <em>&#8216;General&#8217; -> &#8216;Content Types&#8217;</em> from the list on the left.</li>
<li>In the <em>&#8216;Content types:&#8217;</em> view on the right, unfold <em>&#8216;Text&#8217;</em> and click <em>&#8216;Python File&#8217;</em></li>
<li>Hit the <em>&#8216;Add&#8230;&#8217;</em> button of the <em>&#8216;File associations:&#8217;</em> list on the lower right, type <em>&#8220;*.pyp&#8221;</em> into the popup and confirm.</li>
</ul>
<p>Its helpful to add a file containing all symbols of the Cinema 4D Python API’s “c4d” package to the ‘site-packages folder to spice up the auto-completion – <a href="http://www.smart-page.net/py4d/c4d.zip">grab it here</a>.</p>
<p>Place the file within <em>&#8220;/resource/modules/python/res/Python.win64.framework/Lib/site-packages</em><em>&#8220;</em><br />
<br/></p>
<h4>Note:</h4>
<p>You will have to update this file if you want to keep up to date with future versions of Cinema4D, it can be easily printed to the console by executing:</p>
<pre>for itm in dir(c4d):
    s = getattr(c4d, itm)
    print "%s = %s" % (itm, s)</pre>
<p><br/></p>
<h2>Project setup</h2>
<p><img class="alignnone size-full wp-image-1218" title="construction" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/construction.jpg" alt="" width="683" height="134" /></p>
<p>We take your IDE for a spin and create the first project:</p>
<ul>
<li>Click <em>&#8220;File&#8221; &#8211; &#8220;New&#8221;</em> and chose <em>&#8220;PyDev Project&#8221;</em></li>
<li>Input a Name for your Project and uncheck the <em>&#8220;Use default&#8221; </em>box below.</li>
<li>Browse to your Cinema 4D installations plugin folder, create a new directory with your plugins name and select it.</li>
<li>Select<em> &#8220;2.6&#8243; </em>from the <em>&#8220;Grammar Version&#8221;- </em>dropdown and leave the Interpreter set to default.</li>
<li>Last but not least uncheck the <em>&#8220;Create default &#8216;src&#8217; folder&#8230;&#8221; checkbox and hit &#8220;Finish&#8221;.</em></li>
</ul>
<p>To setup the needed folder structure, header- resource- and string files for your plugin, please read the Cinema 4D Python documentation <em>“Plugin structure”</em> &#8211;  especially <em>“Directory structure”</em> &#8211; and take a look at the Python plugin examples within the documentation &#8211; or the experimental plugin from <a href="http://www.smart-page.net/blog/2010/09/10/a-raytracer-in-python-for-cinema-4d" target="_blank">this post</a>:</p>
<p>Just remember this part is vital, so do not rush through it &#8211; at least read the section mentioned above and take a good look at the SDK examples.</p>
<p>Only if you have built C++ plugins before and are already familiar with the structure, you may&#8230;<br />
<br/></p>
<h4>Hint:</h4>
<p>You can also add your existing project files by just placing them within the plugin-directory we just created, or dragging them into the project-folder within Eclipse.</p>
<p>When organizing the file structure within your project, you are working with your file system &#8211; changes you do here are reflected on your harddisk.<br />
This also works the other way round, move something on the file system and Eclipse will update those changes to your project &#8211; while not always instantly.</p>
<p>You can press F5 within Eclipse to update a folder and its subfolders or the contents of a file.</p>
<p>Don&#8217;t worry, if the project-view is out of sync with the file system &#8211; Eclipse will tell you.<br />
<br/></p>
<h2>A coders Cinema 4D:</h2>
<p><img class="alignnone size-full wp-image-1219" title="c4d" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/c4d.jpg" alt="" width="683" height="112" /></p>
<p>We are all set with the IDE part &#8211; let&#8217;s tune the Cinema 4D installation a bit more to improve the workflow and finalize your coding environment.</p>
<p>If you didn&#8217;t add/import your existing code to the project we just created, write a simple hello world and fire up Cinema.</p>
<p>It&#8217;s a good idea to setup a developer friendly layout, I like adding the console window to the tabs on the right, next to the object manager &#8211; or even better to a side monitor.<br />
Should you be writing a CommandData Plugin, consider opening the Command Manager and dragging its icon into the layout, so you can quickly re-open it.</p>
<p>You will be launching and closing Cinema 4D a lot during development &#8211; it&#8217;s helpful to have a strategy to quickly start and close it.<br />
Place a link to Cinema 4D on your taskbar/dock, close it using <em>ALT+F4/Command+Q</em> or create a little python script containing <em>&#8220;exit()&#8221; </em>and add it to the layout/create a shortcut.</p>
<p>Finally, open your Plugin as well as everything you need to test its functionality and save the layout as startup layout.</p>
<p>If you have a test document that you need to check your plugin, press <em>CTRL+E</em>, click the &#8220;Open Preferences Folder&#8230;&#8221; button and place it as &#8220;default.c4d&#8221; within that folder so it will load on startup.</p>
<p>You long got the idea &#8211; try to prepare everything so you don&#8217;t have to spend time doing recurring tasks on every unit-test you are going to make during development.<br />
<br/></p>
<h2>Some additional tools:</h2>
<p>It&#8217;s often helpful to keep an eye on memory consumption and or active threads so I always have the task manager/activity monitor in reach when coding.</p>
<p>And while not really necessary, it&#8217;s convenient to have a good, fast text editor with Python syntax highlighting so you are able to read a file or snippet without having to launch the IDE first.<br />
I can recommend <a href="http://notepad-plus-plus.org/" target="_blank">Notepad++</a> and <a href="http://macromates.com/" target="_blank">TextMate </a>or <a href="http://www.gnu.org/software/emacs/" target="_blank">Emacs </a>for this job.<br />
<br/></p>
<h1>Working with eclipse:</h1>
<p><img class="alignnone size-full wp-image-1220" title="prototype" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/prototype.jpg" alt="" width="683" height="134" /></p>
<p>Eclipse in combination with PyDev is a mighty! tool &#8211; Aside from the obvious killer features &#8211; syntax highlighting and code completion, there is a ton of others.</p>
<p>Often you will discover some that will make you feel bad for not having used them right from the start, so I&#8217;ll try to point out the most useful, while I encourage you to read up on Eclipse and PyDev.<br />
<br/></p>
<h3>The Find/Replace Dialog</h3>
<p>Press CTRL+F for all your search and replace needs – just listing it to make you aware of the direction-, selection- and regex support.<br />
If you haven&#8217;t used regular expressions jet, you should directly head over to <a href="http://en.wikipedia.org/wiki/Regular_expression" target="_blank">Wikipedia </a>- you won&#8217;t regret it.</p>
<p>Even more powerful is the&#8230;<br />
<br/></p>
<h3>Search Dialog</h3>
<p>CTRL+H opens the global or project wide search – here you can also replace over all files.</p>
<p>Just keep in mind that the &#8220;PyDev Search&#8221; tab does only look within *.py files while the &#8220;File Search&#8221; tab by default searches over a *.* pattern.<br />
<br/></p>
<h3>Compare feature and history</h3>
<p>Just select two files, right click and chose <em>&#8220;Compare with&#8221; -&gt; &#8220;Each other&#8221;.</em></p>
<p>You can also compare a file with an earlier state of itself by choosing <em>&#8220;Local history&#8221;.</em></p>
<p>This is another huge plus of using an Eclipse &#8211; don&#8217;t worry anymore about changing huge sections of code or commenting it &#8211; just go ahead and delete it &#8211; you can always return to an earlier state using the &#8220;History&#8221;- tab.</p>
<p>But use this with care, as it’s possible to lose the history by moving or re-creating a project and it’s not infinite.<br />
<br/></p>
<h3>Tabbed views</h3>
<p>You can drag a tab to one side of the code view until a small arrow appears &#8211; the tab will then snap to that side, splitting your view so you can work with multiple source files at the same time.</p>
<p>This is very useful when working with the header-, resource- or string files of your project as you can code on the left and copy &#8216;n paste ID&#8217;s from the right for example.<br />
<br/></p>
<h1>Coding python for Cinema 4D:</h1>
<p><img class="alignnone size-full wp-image-1221" title="python" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/python.jpg" alt="" width="683" height="126" /></p>
<p>We have setup the coding environment &#8211; how about doing some programming now?</p>
<p>This will be a loose collection of tips that are all more or less Cinema 4D related, but mostly  good practice in general.<br />
<br/></p>
<h3>Modules and namespace:</h3>
<p>First &#8211; this is <a href="http://en.wikipedia.org/wiki/Object-oriented_programming" target="_blank">OOP </a>(Object Oriented Programming) and your project&#8217;s structure should reflect that.</p>
<p>In general, classes and modules are a good thing, it&#8217;s a far more common fault to have less abstraction than too much.</p>
<p>Packages/Modules are also the key to keep your code organized, manageable &#8211; AND reusable.</p>
<p>So if you are going to write something that you might want to use again later, consider spending the extra time to make it a bit more user/coder-friendly and build a class or module.</p>
<p>When working with python and modules you have to keep a close eye on naming and namespace, especially in context with the Cinema 4D SDK.</p>
<p>Be creative and use unique module names &#8211; this will keep things easier when you are using other modules &#8211; and you will &#8211; at least the ones from the Cinema 4D API.<br />
Also be careful when importing from modules &#8211; it&#8217;s rarely a good idea to just import everything (<em>from foo import *</em>) &#8211; instead carefully select the members you really need and give everyone its own import line rather than stacking them with commas in one.</p>
<p>It&#8217;s often better to just import the module into your namespace and reference the members via <em>module.foo</em> – you don’t pollute your namespace and it’s more readable.</p>
<p>In any case you should avoid the API&#8217;s module AND member names like the plaque.</p>
<p>For example if you extend the GeDialog Class and have a method <em>&#8220;def close(self):&#8221;</em> &#8211; but make the slight mistake to call it as <em>&#8220;Close()&#8221;</em>, you might end up with a similar behavior but wonder for minutes while your dialog just closes without saving it&#8217;s settings first (or whatever “<em>close()“</em> should have done).</p>
<p>I know for some this is basic stuff &#8211; many have their own patterns for this and that’s ok!</p>
<p>Whatever you do &#8211; be consistent and aware of your namespace.<br />
<br/></p>
<h3>Symbols:</h3>
<p><img class="alignnone size-full wp-image-1223" title="symbols" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/symbols1.jpg" alt="" width="683" height="112" /></p>
<p>As you need to keep track of the enums within the c4d_symbols.h, it is best to define every integer by yourself and not auto-enumerate them.</p>
<p>Then mirror those symbols to a *.py file called <em>&#8220;ids.py&#8221;</em> and be careful to update both should you change them or introduce new ones.</p>
<p>Instead of hardcoding ID&#8217;s, you should always use the symbol within the c4d-package.<br />
Should you ever need to identify a symbol by it&#8217;s integer value (for example if you want to check for a certain flag that is returned) &#8211; this little script will help you out:</p>
<pre>import c4d;
from c4d import gui; 

def main():
    wanted = gui.RenameDialog("ID to search for...")
    outp = ""

    for itm in dir(c4d):
        s = getattr(c4d, itm)
        if s == int(wanted):
            outp += "%s = %s\n" % (itm, s)

    gui.MessageDialog("Sorry - none found..." if outp == "" else outp)

if __name__=='__main__':
    main()</pre>
<p><br/></p>
<h3>API calls / performance:</h3>
<p>Don&#8217;t get me wrong &#8211; the Python API is blazing fast &#8211; so fast you often can&#8217;t tell the difference to C++ &#8211; but still, API calls take time.<br />
When working with thousands of objects, this quickly adds up no matter how fast each individual call is.</p>
<p>Try to limit those calls in sections of your code, where you really need performance &#8211; look for ways to keep states within your own plugin logic rather than querying them form Cinema 4D whenever possible.</p>
<p>If you are looking for bottlenecks, be sure to check out <a href="http://docs.python.org/library/profile.html" target="_blank">cProfile </a>– it’s great.<br />
<br/></p>
<h3>Prototyping:</h3>
<p>Using an IDE doesn&#8217;t forbid you to use Cinema 4D&#8217;s script editor and console to quickly whip up and test something &#8211; you can even write and directly execute a simple test script within eclipse if you are working on parts of your plugin that don&#8217;t need the Cinema SDK (some kind of parser for example) and take advantage of the PyDev debugger.<br />
<br/></p>
<h3>Debugging:</h3>
<p>The lack of a real debugger can be compensated by using the <a href='http://www.smart-page.net/blog/2011/05/29/debugging-cinema-4d-python-plugins-with-pydev/' target='_blank'>PyDev remote debugger</a>, pythons inspect module and the logging package.</p>
<p>Remember that there is a limit to the amount of characters the Cinema 4D console can output for a single print command.</p>
<p>Also take a look at <a href="http://docs.python.org/library/sys.html" target="_blank"><em>sys.exc_info()</em></a><br />
<br/></p>
<h3>Garbage Collection:</h3>
<p>When introducing <a href="http://en.wikipedia.org/wiki/Circular_reference" target="_blank">circular references</a> you should use <a href="http://docs.python.org/library/weakref.html" target="_blank">weak references</a> to give the garbage collector a hand.<br />
<br/></p>
<h3>Compilation:</h3>
<p><a href="http://www.smart-page.net/blog/wp-content/uploads/2011/05/stuff.jpg" rel="lightbox[1215]"><img class="alignnone size-full wp-image-1226" title="stuff" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/stuff.jpg" alt="" width="683" height="112" /></a></p>
<p>How about shipping your plugin as precompiled byte code?</p>
<p>This will make Cinema 4D start up faster &#8211; as the compilation of your plugin can be skipped, obfuse your source and still be platform interoperable.</p>
<p>Just copy your plugin, open the console/terminal and execute <em>&#8220;python.exe -<a href="http://docs.python.org/library/compileall.html" target="_blank">mcompileall </a>C:\PathToMyPlugin&#8221;</em> and delete all *.py files afterwards.</p>
<p>Note that this might not work in some cases, so be sure to test your plugins functionality again.<br />
<br/></p>
<h3>Platform dependency:</h3>
<p>While Python is platform-independent, there are still some things to keep in mind.</p>
<p>Don&#8217;t use backslashes in paths but slashes &#8211; they are understood by windows AND mac OS.</p>
<p>You can also use <a href="http://docs.python.org/library/platform.html" target="_blank"><em>platform.system()</em></a> to determine on what OS your plugin runs on and import modules after a conditional check &#8211; for example:</p>
<pre>if platform.system().lower() == "windows":</pre>
<pre>    import winsound
    winsound.PlaySound(os.path.join(os.path.dirname(__file__), "../res/snd", "DingSound.wav"),
winsound.SND_FILENAME)</pre>
<p><br/></p>
<h3>GUI &#8211; Threading:</h3>
<p>It&#8217;s the old story, if the GUI thread has to wait for your plugin, you lock up Cinema 4D &#8211; unacceptable for the user.</p>
<p>Doing time intensive stuff within your own threads is the simple solution to this, but keep in mind that you can&#8217;t have them call the GUI thread &#8211; instead use messages and the GeDialog&#8217;s <em>SetTimer().</em><br />
<br/></p>
<h3>Resource reference:</h3>
<p>Classes that use the &#8220;plugins&#8221; module need a reference to the plugins resource pointer.</p>
<p>This can be handled by importing those classes within the plugins *.pyp file and setting the class variable <em>&#8220;__res__&#8221;</em> or using a <a href="http://en.wikipedia.org/wiki/Singleton_pattern" target="_blank">singleton </a>(see below).<br />
<br/></p>
<h3>Singletons and invading Borgs:</h3>
<p><img class="alignnone size-full wp-image-1224" title="borg" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/borg.jpg" alt="" width="683" height="107" /></p>
<p>This is something for the advanced developer &#8211; and kind of a hot topic too.</p>
<p>The use of globally accessible objects or ‘globals’ is often considered bad practice but also unavoidable in some cases (logger) and python even somewhat encourages it.</p>
<p>So if you know what you are doing and think about using a singleton, you might want to take a look at the &#8220;borg&#8221;-(anti)pattern &#8211; a monostate proxy with a twist.</p>
<pre>class Borg:</pre>
<pre>__we_are_one = {}</pre>
<pre>    def __init__(self):       
    self.__dict__ = self.__we_are_one</pre>
<p><br/></p>
<h1>Still alive</h1>
<p>This was a lot of compressed stuff to digest, I know, but please do me the favor and don’t let any of this scare you off, it’s easier and more fun than you would expect.</p>
<p>I am sorry some topics where not covered in the depth they deserve -  it wasn’t easy to keep this a readable post rather than a book…</p>
<p>I hope this still was helpful to someone, if you have any questions, thoughts or would like me to write a more detailed post on a certain topic &#8211; let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2011/05/09/advanced-python-plugin-coding-for-cinema-4d/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>PY4D Boids</title>
		<link>http://www.smart-page.net/blog/2009/08/07/py4d-boids/</link>
		<comments>http://www.smart-page.net/blog/2009/08/07/py4d-boids/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 17:17:02 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[boids]]></category>
		<category><![CDATA[cinema 4D]]></category>
		<category><![CDATA[flocking]]></category>
		<category><![CDATA[py4d]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=309</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2009/08/07/py4d-boids/" title="PY4D Boids"><img src="http://www.smart-page.net/blog/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=309&amp;w=200&amp;h=150&amp;zc=1" width="200" height="150" alt="PY4D Boids" style="float:left;padding:0 10px 10px 0;" ></a>Sebastian Rath´s PY4D is a new, alternative way to script with or to code plugins for Cinema4D &#8211; without COFFE or C++ &#8211; but in Python. The current beta (v0.9.0001) already makes a fine impression and proves itself easy to get started with. This video shows a little script that was adapted in a twinkling [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2009/08/07/py4d-boids/" title="PY4D Boids"><img src="http://www.smart-page.net/blog/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=309&amp;w=200&amp;h=150&amp;zc=1" width="200" height="150" alt="PY4D Boids" style="float:left;padding:0 10px 10px 0;" ></a><p>Sebastian Rath´s <a href="http://py4d.xpresso24.com" target="_blank">PY4D</a> is a new, alternative way to script with or to code plugins for Cinema4D &#8211; without COFFE or C++ &#8211; but in Python.</p>
<p>The current beta (v0.9.0001) already makes a fine impression and proves itself easy to get started with.</p>
<p><b><a href="http://www.vconverter.de/?file=fishboids" target="_blank">This video</a></b> shows a little script that was adapted in a twinkling and controls the particles of a TP-Storm to behave after the three flocking boids rules.<a href="http://www.py4d.com/2009/08/there-comming/" target="_blank"><br />
Don</a> has rendered a <b><a href="http://www.vconverter.de/?file=tunaboids" target="_blank">much prettyer version</a></b> of the dummy above.</p>
<p>You can download the C4D-scene <a href="http://www.smart-page.net/python/Boids4Py.c4d">here</a>.</p>
<p><strong><span style="color: #ff9900;">Update:</span></strong> <em>The file has been updated to work with the R12 version of Cinema 4D.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2009/08/07/py4d-boids/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

