<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>python.rhino3d.com - Blogs</title>
		<link>http://python.rhino3d.com/blog.php</link>
		<description>This is a discussion forum powered by vBulletin. To find out about vBulletin, go to http://www.vbulletin.com/ .</description>
		<language>en</language>
		<lastBuildDate>Mon, 20 May 2013 07:58:24 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://python.rhino3d.com/images/misc/rss.jpg</url>
			<title>python.rhino3d.com - Blogs</title>
			<link>http://python.rhino3d.com/blog.php</link>
		</image>
		<item>
			<title>Python Goodies - the sorted function</title>
			<link>http://python.rhino3d.com/blog.php?b=654</link>
			<pubDate>Tue, 18 Oct 2011 17:35:25 GMT</pubDate>
			<description><![CDATA[There are so many nice little features of python.  Here's a good one to learn; the sorted function. 
 
*sorted(iterable[, cmp[, key[, reverse]]])* -...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">There are so many nice little features of python.  Here's a good one to learn; the sorted function.<br />
<br />
<b>sorted(iterable[, cmp[, key[, reverse]]])</b> - <a href="http://wiki.python.org/moin/HowTo/Sorting/" target="_blank" rel="nofollow">http://wiki.python.org/moin/HowTo/Sorting/</a><br />
This function takes a list and returns a sorted version of the list.  That's nice...... but I wouldn't write a blog post about this if that was all this function does.  Here's what I really like about the sorted function, the optional <i>key</i> argument.  This argument lets you define a function that tells the sorted function what to use to compare different entries in the list.<br />
<br />
I recently attended a Rhino python workshop and a student with a background in RhinoScript was putting together a python script that sorted a bunch of curves based on the Z height of each curve's start point.  This isn't necessarily hard to do, but it does involve quite a few lines of script to write the sorting routine, and you can potentially write very slow scripts if you aren't careful about your sorting algorithm.<br />
<br />
Here's how this script could be written in python using the sorted function along with the key parameter.  The function asks you to select a bunch of curves and then adds text dots to the start point of every curve sorted by the curve's start point Z height<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Python Code:</div>
	<div class="geshi_highlight">
  <div dir="ltr" style="text-align:left;"><div class="python"><ol><div class="de1"><span class="kw1">import</span> rhinoscriptsyntax as rs</div><div class="de1">&nbsp;</div><div class="de1"><span class="kw1">def</span> curvekey<span class="br0">&#40;</span>curve<span class="br0">&#41;</span>:</div><div class="de1">&nbsp; &nbsp; point = rs.<span class="me1">CurveStartPoint</span><span class="br0">&#40;</span>curve<span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> point<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span></div><div class="de1">&nbsp;</div><div class="de1"><span class="kw1">def</span> SortCurvesByZ<span class="br0">&#40;</span><span class="br0">&#41;</span>:</div><div class="de1">&nbsp; &nbsp; curves = rs.<span class="me1">GetObjects</span><span class="br0">&#40;</span><span class="st0">"Select Curves"</span>, rs.<span class="kw2">filter</span>.<span class="me1">curve</span><span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="kw1">not</span> curves: <span class="kw1">return</span></div><div class="de1">&nbsp; &nbsp; sorted_curves = <span class="kw2">sorted</span><span class="br0">&#40;</span>curves, key=curvekey<span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; <span class="kw1">for</span> i, curve <span class="kw1">in</span> <span class="kw2">enumerate</span><span class="br0">&#40;</span>sorted_curves<span class="br0">&#41;</span>:</div><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; point = rs.<span class="me1">CurveStartPoint</span><span class="br0">&#40;</span>curve<span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; rs.<span class="me1">AddTextDot</span><span class="br0">&#40;</span>i+<span class="nu0">1</span>, point<span class="br0">&#41;</span></div><div class="de1">&nbsp;</div><div class="de1"><span class="kw1">if</span> __name__==<span class="st0">"__main__"</span>:</div><div class="de1">&nbsp; &nbsp; SortCurvesByZ<span class="br0">&#40;</span><span class="br0">&#41;</span> </div></ol></div></div></div>
</div><br />
Here's a breakdown of what is happening.<ol class="decimal"><li>GetObjects is called so that the user can select a bunch of curves</li>
<li>Once we a list, we call the sorted function passing the curves and using the named parameter of <i>key=curvekey</i></li>
<li>sorted() goes about its job of sorting the list, but since the key parameter was set it knows to call the curvekey function to get a value to use for comparison when sorting.</li>
<li>We defined curvekey as a function that takes a single input parameter. This is what the key parameter in sorted is expecting; a function that takes a single parameter and returns some sort of value that it knows how to compare.  curvekey is called for every item in the list and we return a floating point number (the z height of the start point).  The floating point number returned is what sorted uses to compare each item's &quot;value&quot;</li>
<li>sorted returns a new list of curves that are now in sorted order.  We just walk through the new list and add text dots so we can see that things are working.</li>
</ol><br />
Pretty darn useful function to keep in your python toolbox!</blockquote>

 ]]></content:encoded>
			<dc:creator>Steve Baer</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=654</guid>
		</item>
		<item>
			<title>Kinect2RhinoSkeleton through OpenNI/OSCeleton</title>
			<link>http://python.rhino3d.com/blog.php?b=632</link>
			<pubDate>Sun, 21 Aug 2011 20:41:42 GMT</pubDate>
			<description>After installing OpenNI you need to unzip the donwload file and  start osceleton.exe.  
Then you start test_rhino.py through EditPythonScript in...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">After installing OpenNI you need to unzip the donwload file and  start osceleton.exe. <br />
Then you start test_rhino.py through EditPythonScript in Rhino5. <br />
Finally OpenNI/Kinect must detect a skeleton. For this reason you have to do the &quot;init-gesture&quot;, i.e. spreading your arms and lifting them, while the kinect sees your upper body .<br />
It is also possible to record data and play them back if you are a bit shy or lazy.<br />
Comments:<br />
Besides OpenNI you need OSCeleton and pyOsc which are both OpenSource projects.<br />
For convenience I included them for this project.<br />
the pure Python pyOSC needed minor modification to be Ironpython compatible-&gt; ipyOSC</blockquote>


<!-- attachments -->
	<div class="blogattachments">
		
		
		
		
			<fieldset class="blogcontent">
				<legend>Attached Files</legend>
				<ul>
					
				</ul>
			</fieldset>
		

	</div>
<!-- / attachments -->
 ]]></content:encoded>
			<dc:creator>bar</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=632</guid>
		</item>
		<item>
			<title>Is there a way to change the size of the font inside the editing Python editor?</title>
			<link>http://python.rhino3d.com/blog.php?b=617</link>
			<pubDate>Sun, 24 Jul 2011 02:41:23 GMT</pubDate>
			<description>Hi, it is not that I can not read it, but when you teach, the students on the back of the room can not read the lines... 
 
Thanks 
 
Andres</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Hi, it is not that I can not read it, but when you teach, the students on the back of the room can not read the lines...<br />
<br />
Thanks<br />
<br />
Andres</blockquote>

 ]]></content:encoded>
			<dc:creator>andres</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=617</guid>
		</item>
		<item>
			<title>My First RhinoPython Script</title>
			<link>http://python.rhino3d.com/blog.php?b=611</link>
			<pubDate>Wed, 06 Jul 2011 16:14:12 GMT</pubDate>
			<description>I know this is kinda cheezy, since I use the RhinoScript syntax. But hey! gotta start somewhere... 
 
 
...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">I know this is kinda cheezy, since I use the RhinoScript syntax. But hey! gotta start somewhere...<br />
<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Python Code:</div>
	<div class="geshi_highlight">
  <div dir="ltr" style="text-align:left;"><div class="python"><ol><div class="de1"><span class="co1">###############################################################################</span></div><div class="de1"><span class="co1"># ArchimedeanSpiral.py -- July 2011</span></div><div class="de1"><span class="co1"># If this code works, it was written by Dale Fugier.</span></div><div class="de1"><span class="co1"># If not, I don't know who wrote it.</span></div><div class="de1"><span class="co1">#</span></div><div class="de1"><span class="co1"># Change 'a_const' to turn the spiral.</span></div><div class="de1"><span class="co1"># Change 'b_const' to control the distance between turnings.</span></div><div class="de1">&nbsp;</div><div class="de1"><span class="kw1">import</span> rhinoscriptsyntax as rs</div><div class="de1">&nbsp;</div><div class="de1"><span class="kw1">def</span> ArchimedeanSpiral<span class="br0">&#40;</span><span class="br0">&#41;</span>:</div><div class="de1">&nbsp; &nbsp; </div><div class="de1">&nbsp; &nbsp; <span class="kw1">print</span> <span class="st0">"Archimedean Spiral: Radius = A + B * Theta"</span></div><div class="de1">&nbsp; &nbsp; </div><div class="de1">&nbsp; &nbsp; a_const = rs.<span class="me1">GetReal</span><span class="br0">&#40;</span><span class="st0">"Value of A constant"</span>, <span class="nu0">1</span>.<span class="nu0">0</span>, <span class="nu0">0</span>.<span class="nu0">01</span><span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> a_const <span class="kw1">is</span> <span class="kw2">None</span>: <span class="kw1">return</span></div><div class="de1">&nbsp; &nbsp; </div><div class="de1">&nbsp; &nbsp; b_const = rs.<span class="me1">GetReal</span><span class="br0">&#40;</span><span class="st0">"Value of B constant"</span>, <span class="nu0">1</span>.<span class="nu0">0</span>, <span class="nu0">0</span>.<span class="nu0">01</span><span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> b_const <span class="kw1">is</span> <span class="kw2">None</span>: <span class="kw1">return</span></div><div class="de1">&nbsp; &nbsp; </div><div class="de1">&nbsp; &nbsp; num_points = rs.<span class="me1">GetInteger</span><span class="br0">&#40;</span><span class="st0">"Number of points to calculate"</span>, <span class="nu0">10</span>, <span class="nu0">1</span><span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> num_points <span class="kw1">is</span> <span class="kw2">None</span>: <span class="kw1">return</span></div><div class="de1">&nbsp; &nbsp; </div><div class="de1">&nbsp; &nbsp; step_angle = rs.<span class="me1">GetReal</span><span class="br0">&#40;</span><span class="st0">"Angle between points"</span>,&nbsp; <span class="nu0">30</span>.<span class="nu0">0</span>, <span class="nu0">1</span>.<span class="nu0">0</span>, <span class="nu0">45</span>.<span class="nu0">0</span><span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> step_angle <span class="kw1">is</span> <span class="kw2">None</span>: <span class="kw1">return</span></div><div class="de1">&nbsp; &nbsp; </div><div class="de1">&nbsp; &nbsp; curr_angle = <span class="nu0">0</span>.<span class="nu0">0</span></div><div class="de1">&nbsp; &nbsp; base_point = <span class="br0">&#91;</span><span class="nu0">0</span>.<span class="nu0">0</span>, <span class="nu0">0</span>.<span class="nu0">0</span>, <span class="nu0">0</span>.<span class="nu0">0</span><span class="br0">&#93;</span></div><div class="de1">&nbsp; &nbsp; points = <span class="br0">&#91;</span><span class="br0">&#93;</span></div><div class="de1">&nbsp; &nbsp; </div><div class="de1">&nbsp; &nbsp; <span class="kw1">for</span> i <span class="kw1">in</span> <span class="kw2">xrange</span><span class="br0">&#40;</span><span class="nu0">0</span>, num_points<span class="br0">&#41;</span>:</div><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;radius = a_const + <span class="br0">&#40;</span>b_const * curr_angle<span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pt = rs.<span class="me1">Polar</span><span class="br0">&#40;</span>base_point, radius, curr_angle<span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;points.<span class="me1">append</span><span class="br0">&#40;</span>pt<span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;curr_angle = curr_angle + step_angle</div><div class="de1">&nbsp; &nbsp; </div><div class="de1">&nbsp; &nbsp; rs.<span class="me1">AddInterpCurve</span><span class="br0">&#40;</span>points<span class="br0">&#41;</span></div><div class="de1">&nbsp;</div><div class="de1"><span class="co1">##########################################################################</span></div><div class="de1"><span class="co1"># Check to see if this file is being executed as the &quot;main&quot; python</span></div><div class="de1"><span class="co1"># script instead of being used as a module by some other python script</span></div><div class="de1"><span class="co1"># This allows us to use the module which ever way we want.</span></div><div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span> __name__ == <span class="st0">"__main__"</span> <span class="br0">&#41;</span>:</div><div class="de1">&nbsp; &nbsp; ArchimedeanSpiral<span class="br0">&#40;</span><span class="br0">&#41;</span> </div></ol></div></div></div>
</div><br />
Enjoy!</blockquote>

 ]]></content:encoded>
			<dc:creator>Dale Fugier</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=611</guid>
		</item>
		<item>
			<title>Numpy and Scipy in RhinoPython</title>
			<link>http://python.rhino3d.com/blog.php?b=610</link>
			<pubDate>Mon, 27 Jun 2011 21:14:25 GMT</pubDate>
			<description>---Quote--- 
Disclaimer: I have very little experience with numpy and scipy so you are going to do better by searching google for support with these...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore"><div class="bbcode_container">
	<div class="bbcode_quote">
		<div class="quote_container">
			<div class="bbcode_quote_container"></div>
			
				Disclaimer: I have very little experience with numpy and scipy so you are going to do better by searching google for support with these libraries.  This blog is about getting these libraries to run in Rhino.
			
		</div>
	</div>
</div> <b>Yes it is possible now!!!</b><br />
Okay, here's what I did to get numpy/scipy running in Rhino<br />
<br />
<b>1 - Install Rhino 5 (32bit version)</b><br />
numpy/scipy uses C++ DLLs which need to be compiled for a specific platform.  Currently numpy/scipy for IronPython will only run in 32bit applications on Windows.  I contacted the guys at Enthought and they do plan on releasing a 64bit version for Windows, but they want to make sure everything is working on 32bit first.  They have some doubts about being able to release a mono version for you Mac guys out there.<br />
<br />
<b>2 - Install numpy/scipy for IronPython</b><br />
Follow the instructions on this site <a href="http://www.enthought.com/repo/.iron/" target="_blank" rel="nofollow">http://www.enthought.com/repo/.iron/</a><br />
<br />
<b>3 - Modify settings in RhinoPython</b><br />
Start Rhino 5 - 32bit version and run &quot;EditPythonScript&quot; to bring up the editor.  Go to the options dialog by selecting Tools-&gt;Options from the menu<br />
<br />
Add site-packages and DLLs to the search paths (see image). This helps RhinoPython find the numpy/scipy packages and associated DLLs.<br />
<a href="http://python.rhino3d.com/attachment.php?attachmentid=252&amp;d=1309209247" id="attachment252" rel="Lightbox_610" ><img src="http://python.rhino3d.com/attachment.php?attachmentid=252&amp;d=1309209234&amp;thumb=1" border="0" alt="Click image for larger version

Name:	numpy_paths.png
Views:	498
Size:	35.5 KB
ID:	252" class="thumbnail" /></a><br />
<br />
Check the &quot;Frames Enabled&quot; option since numpy/scipy requires this to be turned on.<br />
<a href="http://python.rhino3d.com/attachment.php?attachmentid=250&amp;d=1309209105" id="attachment250" rel="Lightbox_610" ><img src="http://python.rhino3d.com/attachment.php?attachmentid=250&amp;d=1309209105&amp;thumb=1" border="0" alt="Click image for larger version

Name:	numpy_frames.png
Views:	400
Size:	26.0 KB
ID:	250" class="thumbnail" /></a><br />
I decided to make the &quot;Frames Enabled&quot; an optional engine feature since it does have a performance impact on scripts. Numpy/scipy requires this feature to be turned on.<br />
<br />
<b>4 - Run a test</b><br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Python Code:</div>
	<div class="geshi_highlight">
  <div dir="ltr" style="text-align:left;"><div class="python"><ol><div class="de1"><span class="co1"># For now, we need to manually load mtrand before using numpy or scipy</span></div><div class="de1"><span class="co1"># I'm still trying to figure out why mtrand is not automatically getting</span></div><div class="de1"><span class="co1"># loaded when numpy/scipy imports it.&nbsp; If I can fix this, we won't need</span></div><div class="de1"><span class="co1"># the following two lines</span></div><div class="de1"><span class="kw1">import</span> clr</div><div class="de1">clr.<span class="me1">AddReference</span><span class="br0">&#40;</span><span class="st0">"mtrand"</span><span class="br0">&#41;</span></div><div class="de1">&nbsp;</div><div class="de1"><span class="kw1">import</span> numpy</div><div class="de1"><span class="kw1">import</span> rhinoscriptsyntax as rs</div><div class="de1">&nbsp;</div><div class="de1">x_coord = <span class="br0">&#91;</span>&nbsp; <span class="nu0">0</span>,&nbsp; <span class="nu0">1</span>,&nbsp; <span class="nu0">2</span>,&nbsp; <span class="nu0">3</span>,&nbsp; <span class="nu0">4</span>,&nbsp; <span class="nu0">5</span>,&nbsp; <span class="nu0">6</span><span class="br0">&#93;</span></div><div class="de1">y_coord = <span class="br0">&#91;</span><span class="nu0">0</span>.<span class="nu0">0</span>,<span class="nu0">0</span>.<span class="nu0">1</span>,<span class="nu0">0</span>.<span class="nu0">5</span>,<span class="nu0">2</span>.<span class="nu0">5</span>,<span class="nu0">2</span>.<span class="nu0">5</span>,<span class="nu0">2</span>.<span class="nu0">5</span>,<span class="nu0">4</span>.<span class="nu0">0</span><span class="br0">&#93;</span></div><div class="de1">xyz = <span class="kw2">zip</span><span class="br0">&#40;</span>x_coord,y_coord,<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>*<span class="kw2">len</span><span class="br0">&#40;</span>x_coord<span class="br0">&#41;</span><span class="br0">&#41;</span></div><div class="de1">rs.<span class="me1">AddPoints</span><span class="br0">&#40;</span>xyz<span class="br0">&#41;</span></div><div class="de1">&nbsp;</div><div class="de1">degree = <span class="nu0">5</span></div><div class="de1">eq = numpy.<span class="me1">polyfit</span><span class="br0">&#40;</span>x_coord, y_coord, degree<span class="br0">&#41;</span></div><div class="de1">fitfunc = numpy.<span class="me1">poly1d</span><span class="br0">&#40;</span>eq<span class="br0">&#41;</span></div><div class="de1">&nbsp;</div><div class="de1">fit_points = <span class="br0">&#91;</span><span class="br0">&#93;</span></div><div class="de1"><span class="kw1">for</span> i <span class="kw1">in</span> <span class="kw2">range</span><span class="br0">&#40;</span><span class="nu0">61</span><span class="br0">&#41;</span>:</div><div class="de1">&nbsp; &nbsp; x = i/<span class="nu0">10</span>.<span class="nu0">0</span></div><div class="de1">&nbsp; &nbsp; y = fitfunc<span class="br0">&#40;</span>x<span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; fit_points.<span class="me1">append</span><span class="br0">&#40;</span><span class="br0">&#40;</span>x, y, <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div><div class="de1">rs.<span class="me1">AddPolyline</span><span class="br0">&#40;</span>fit_points<span class="br0">&#41;</span> </div></ol></div></div></div>
</div><br />
If you get a polyline in rhino fit through a series of point then you are all all set; if not go back to step 1 and repeat.<br />
<br />
This looks like a good place to start if you want to learn more about numpy/scipy<br />
<a href="http://docs.scipy.org/doc/" target="_blank" rel="nofollow">http://docs.scipy.org/doc/</a></blockquote>

 ]]></content:encoded>
			<dc:creator>Steve Baer</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=610</guid>
		</item>
		<item>
			<title>Kinect SDK</title>
			<link>http://python.rhino3d.com/blog.php?b=609</link>
			<pubDate>Fri, 17 Jun 2011 16:31:46 GMT</pubDate>
			<description>YES!!! This could lead to some incredible applications. 
  
http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/  
  
Now if they only...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">YES!!! This could lead to some incredible applications.<br />
 <br />
<a href="http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/" target="_blank" rel="nofollow">http://research.microsoft.com/en-us/...cts/kinectsdk/</a> <br />
 <br />
Now if they only had a version that clipped to your monitor and tracked your fingers...</blockquote>

 ]]></content:encoded>
			<dc:creator>Steve Baer</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=609</guid>
		</item>
		<item>
			<title>Outside the Box 2 - Calling the Shapeways API from Python</title>
			<link>http://python.rhino3d.com/blog.php?b=608</link>
			<pubDate>Thu, 02 Jun 2011 19:48:24 GMT</pubDate>
			<description><![CDATA[I received a question on accessing the ShapeWays API from my last "Outside the Box" blog and figured I should dig in and figure out what is going on....]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">I received a question on accessing the ShapeWays API from my last &quot;Outside the Box&quot; blog and figured I should dig in and figure out what is going on.  Shapeways has a web service API that uses SOAP and a WSDL page (<a href="http://en.wikipedia.org/wiki/Web_Services_Description_Language" target="_blank" rel="nofollow">http://en.wikipedia.org/wiki/Web_Ser...ption_Language</a>) as described here<br />
<a href="http://www.shapeways.com/api" target="_blank" rel="nofollow">http://www.shapeways.com/api</a><br />
<br />
This API is a bit different than the REST API which I wrote a script to access in my previous blog post. In order to use this API, I ended up modifying a script originally put together by Michael Foord (author of &quot;IronPython in Action&quot;) that creates a .NET assembly on the fly for a given WSDL url.<br />
<br />
Here are the two scripts:<br />
<a href="http://python.rhino3d.com/attachment.php?attachmentid=239&amp;d=1307043550" >useshapeways.py</a><br />
<a href="http://python.rhino3d.com/attachment.php?attachmentid=240&amp;d=1307043557" >wsdlprovider.py</a><br />
<br />
Place both of these scripts in the same directory and open the &quot;useshapeways.py&quot; script. Here's the script itself<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Python Code:</div>
	<div class="geshi_highlight">
  <div dir="ltr" style="text-align:left;"><div class="python"><ol><div class="de1"><span class="st0">""</span><span class="st0">"Sample script that accesses the shapeways API</span></div><div class="de1"><span class="st0">[url]http://www.shapeways.com/api[/url]</span></div><div class="de1"><span class="st0">"</span><span class="st0">""</span></div><div class="de1"><span class="kw1">import</span> wsdlprovider</div><div class="de1">&nbsp;</div><div class="de1">wsdl_url = <span class="st0">"http://api.shapeways.com/v1/wsdl.php"</span></div><div class="de1">username = <span class="st0">"username"</span></div><div class="de1">password = <span class="st0">"password"</span></div><div class="de1">application_id = <span class="st0">"rhinotest"</span></div><div class="de1">&nbsp;</div><div class="de1">assembly = wsdlprovider.<span class="me1">GetWebservice</span><span class="br0">&#40;</span>wsdl_url<span class="br0">&#41;</span></div><div class="de1">shapeways = assembly.<span class="me1">SWwsdlService</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div><div class="de1">session_id = shapeways.<span class="me1">login</span><span class="br0">&#40;</span>username, password, application_id<span class="br0">&#41;</span></div><div class="de1"><span class="kw1">if</span> session_id:</div><div class="de1">&nbsp; &nbsp; <span class="co1">#get list of printers available</span></div><div class="de1">&nbsp; &nbsp; printers = shapeways.<span class="me1">getPrinters</span><span class="br0">&#40;</span>session_id, <span class="st0">""</span>, application_id<span class="br0">&#41;</span></div><div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> printers:</div><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> printer <span class="kw1">in</span> printers:</div><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">print</span> <span class="st0">"printer:"</span>, printer.<span class="me1">title</span></div><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> material <span class="kw1">in</span> printer.<span class="me1">materials</span>:</div><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">print</span> <span class="st0">" - material "</span>, material.<span class="me1">title</span> </div></ol></div></div></div>
</div><br />
The script uses the wsdlprovider script to generate a .NET assembly from the shapeways wsdl url. This assembly has a class in it called SWwsdlService which we create an instance of and call functions on. It looks like a normal class to python, but all of the function calls are sent to ShapeWays over the internet and response are turned into classes that you can use.  This sample simply logs into shapeways to get a &quot;session id&quot; and then asks Shapeways for a list of it's available printers along with what materials each printer supports.<br />
<br />
At the time of this blog post, the printed output from this script is<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code" style="height:372px;">printer: Somatech FDM
 - material  Grey Robust
printer: Somatech Objet 720
 - material  Black Detail
 - material  White Detail
 - material  Transparent Detail
printer: SLS Printer
 - material  White Strong &amp; Flexible
printer: Metal Printer matt
 - material  Gold Plated Glossy
 - material  Antique Bronze Glossy
 - material  Antique Bronze Matte
 - material  Stainless Steel
printer: SLS Color Printer
 - material  Black Strong &amp; Flexible
printer: Silver Printer
 - material  Silver Glossy
 - material  Silver
printer: ZPrinter 650
 - material  Sandstone
 - material  Full Color Sandstone
printer: SLS Alumide
 - material  Alumide
printer: Glass Printer
 - material  High Gloss Black Glass
 - material  High Gloss White Glass
 - material  Milky White Matte Glass
printer: Metal printer Gold
 - material  Gold Plated Matte
printer: SLS Color Printer New
 - material  Dark Grey Strong and Flexible
 - material  Indigo Strong and Flexible
 - material  Winter Red Strong and Flexible
printer: HD printer
 - material  Frosted Detail
printer: UHD printer
 - material  Frosted Ultra Detail
printer: SLS Printer polished
 - material  White Strong &amp; Flexible Polished
printer: Ceramics printer
 - material  Glazed Ceramics</pre>
</div> Pretty neat!</blockquote>

 ]]></content:encoded>
			<dc:creator>Steve Baer</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=608</guid>
		</item>
		<item>
			<title>Multithreaded Python</title>
			<link>http://python.rhino3d.com/blog.php?b=607</link>
			<pubDate>Wed, 01 Jun 2011 19:52:35 GMT</pubDate>
			<description>Image: http://wiki.mcneel.com/_media/developer/multithreaded_py.png  
One of the nice bits that we have access to in Rhino python is the Task...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore"><img src="http://wiki.mcneel.com/_media/developer/multithreaded_py.png" border="0" alt="" /><br />
One of the nice bits that we have access to in Rhino python is the Task Parallel Library that is built into .NET 4<br />
<a href="http://msdn.microsoft.com/en-us/library/system.threading.tasks.aspx" target="_blank" rel="nofollow">http://msdn.microsoft.com/en-us/libr...ing.tasks.aspx</a><br />
<br />
This set of classes and functions makes it relatively easy to write things like parallel for loops in which every iteration of the loop may be processed on different threads.  This nice thing about parallel for loops is that they make coding with multiple threads much simpler since the &quot;multi-threading&quot; only occurs inside the for loop and once the loop is finished you know that the all of the threads have completed and you are back on the main execution thread.<br />
<br />
Here's a sample python script (standalone and in a grasshopper definition) which runs many Plane-Brep intersections either on a single thread or using multiple threads.<br />
<a href="http://python.rhino3d.com/attachment.php?attachmentid=238&amp;d=1306957714" >radial_contour.py</a><br />
<a href="http://python.rhino3d.com/attachment.php?attachmentid=237&amp;d=1306957708" >radial_contour.ghx</a></blockquote>

 ]]></content:encoded>
			<dc:creator>Steve Baer</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=607</guid>
		</item>
		<item>
			<title>Outside the Box - Using Web Services from Python</title>
			<link>http://python.rhino3d.com/blog.php?b=606</link>
			<pubDate>Fri, 27 May 2011 18:14:17 GMT</pubDate>
			<description><![CDATA[I've been trying to learn more about things like web services and APIs provided by internet companies (gotta figure out what all of these buzzwords...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">I've been trying to learn more about things like web services and APIs provided by internet companies (gotta figure out what all of these buzzwords are.)  One thing I've noticed is that many companies now provide a REST API which return JSON objects.  There are enough resources on the web that describe REST and JSON that I don't need to repeat it here; I'm just going to get to my python experiments on this technology.<br />
<br />
Attached are a python script and a grasshopper definition containing a python component.<br />
<a href="http://python.rhino3d.com/attachment.php?attachmentid=229&amp;d=1306518124" >googletranslate.ghx</a><br />
<a href="http://python.rhino3d.com/attachment.php?attachmentid=230&amp;d=1306518130" >googletranslate.py</a><br />
<br />
<b>So what does it do?</b><br />
The python script uses the <a href="http://code.google.com/apis/language/translate/overview.html" target="_blank" rel="nofollow">Google Translate API</a> to translate text from one language to another.  Maybe not the most useful new tool for Rhino, but it shows how simple it is to format a request to a web service and get at the results.<br />
<br />
<a href="http://python.rhino3d.com/attachment.php?attachmentid=231&amp;d=1306518147" id="attachment231" rel="Lightbox_606" ><img src="http://python.rhino3d.com/attachment.php?attachmentid=231&amp;d=1306518147&amp;thumb=1" border="0" alt="Click image for larger version

Name:	gtranslate_ghx.png
Views:	452
Size:	93.5 KB
ID:	231" class="thumbnail" /></a> <a href="http://python.rhino3d.com/attachment.php?attachmentid=232&amp;d=1306518207" id="attachment232" rel="Lightbox_606" ><img src="http://python.rhino3d.com/attachment.php?attachmentid=232&amp;d=1306518207&amp;thumb=1" border="0" alt="Click image for larger version

Name:	gtranslate_py.png
Views:	239
Size:	75.6 KB
ID:	232" class="thumbnail" /></a><br />
<br />
Some important things to note:<ol class="decimal"><li>The scripts in both attachments are exactly the same.  There is code in the script to figure out if it is running as a normal Rhino python script or inside of Grasshopper.</li>
<li>The script does different things when it is running in Rhino versus when running in Grasshopper. In Rhino, the script converts text dot text which in Grasshopper the script uses input and output variables.</li>
<li>I'm using the sticky variable to cache results. This way we don't have to keep going out to Google if we are translating the same text over and over again</li>
</ol><br />
Search around on the internet for REST apis that return JSON data. Your python scripts that use these other services will end up looking pretty similar to the samples I posted (unless you don't like my scripting style;)) Here are some interesting APIs to look at:<br />
<a href="http://code.google.com/more/" target="_blank" rel="nofollow">http://code.google.com/more/</a><br />
<a href="http://friendfeed.com/api/documentation" target="_blank" rel="nofollow">http://friendfeed.com/api/documentation</a><br />
<a href="http://www.flickr.com/services/api/" target="_blank" rel="nofollow">http://www.flickr.com/services/api/</a><br />
<a href="http://developer.ning.com/docs/ningapi/1.0/index.html" target="_blank" rel="nofollow">http://developer.ning.com/docs/ningapi/1.0/index.html</a><br />
<a href="http://develop.github.com/" target="_blank" rel="nofollow">http://develop.github.com/</a><br />
<a href="http://api.pachube.com/" target="_blank" rel="nofollow">http://api.pachube.com/</a></blockquote>

 ]]></content:encoded>
			<dc:creator>Steve Baer</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=606</guid>
		</item>
		<item>
			<title>Python component for Grasshopper</title>
			<link>http://python.rhino3d.com/blog.php?b=366</link>
			<pubDate>Mon, 02 May 2011 23:56:37 GMT</pubDate>
			<description>Giulio Piacentino and I have been working on an update to the grasshopper/python component and finally have something to show off!!! 
...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Giulio Piacentino and I have been working on an update to the grasshopper/python component and finally have something to show off!!!<br />
<br />
<b><a href="http://www.food4rhino.com/project/ghpython" target="_blank" rel="nofollow">http://www.food4rhino.com/project/ghpython</a> - NOTE: Will only work in Rhino 5</b><br />
<br />
<br />
This component is a scripting component similar to the VB.NET and C# components that ship with Grasshopper.  You get a component where you can define as many input and output variables as you want and then reference these variables in the python script.<br />
<a href="http://python.rhino3d.com/attachment.php?attachmentid=199&amp;d=1304379311" id="attachment199" rel="Lightbox_366" ><img src="http://python.rhino3d.com/attachment.php?attachmentid=199&amp;d=1304379311&amp;thumb=1" border="0" alt="Click image for larger version

Name:	ghpython.jpg
Views:	518
Size:	88.9 KB
ID:	199" class="thumbnail" /></a><br />
If you double click on the component, you get a light version of the python script editor which you are used to in the EditPythonScript command (keywords are colorized and functions autocomplete when possible)<br />
<a href="http://python.rhino3d.com/attachment.php?attachmentid=198&amp;d=1304379280" id="attachment198" rel="Lightbox_366" ><img src="http://python.rhino3d.com/attachment.php?attachmentid=198&amp;d=1304379280&amp;thumb=1" border="0" alt="Click image for larger version

Name:	ghpython_editor.png
Views:	425
Size:	67.7 KB
ID:	198" class="thumbnail" /></a><br />
<br />
<b>But there is a cool twist...</b>  this component supports the rhinoscriptsyntax functions. The rhinoscriptsyntax functions can be set to generate geometry inside of Grasshopper that does not live in the Rhino document.  We are using a concept called &quot;duck typing&quot; to swap the document that the rhinoscriptsyntax functions use from the rhino document to a grasshopper document.  This means that the following script<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Python Code:</div>
	<div class="geshi_highlight">
  <div dir="ltr" style="text-align:left;"><div class="python"><ol><div class="de1"><span class="kw1">import</span> rhinoscriptsyntax as rs</div><div class="de1"><span class="kw1">for</span> x <span class="kw1">in</span> <span class="kw2">range</span><span class="br0">&#40;</span><span class="nu0">10</span><span class="br0">&#41;</span>:</div><div class="de1">&nbsp; &nbsp; rs.<span class="me1">AddPoint</span><span class="br0">&#40;</span><span class="br0">&#40;</span>x,<span class="nu0">0</span>,<span class="nu0">0</span><span class="br0">&#41;</span> </div></ol></div></div></div>
</div>will add 10 points to the Rhino document when run from Rhino's &quot;RunPythonScript&quot; or &quot;EditPythonScript&quot; functions.  The same script will add 10 points to a grasshopper document that can be passed on to other grasshopper components when run inside the syntax of grasshopper.<br />
<br />
We are writing this as an open source project which is hosted at<br />
<a href="https://github.com/mcneel/ghpython" target="_blank" rel="nofollow">https://github.com/mcneel/ghpython</a><br />
Developers are welcome to download, compile, and tinker with the component source code.  If you find bugs or want to add features, let us know and we'll figure out how to get you more involved in the development process.<br />
<br />
You can also log bugs and wishlist items at<br />
<a href="https://github.com/mcneel/ghpython/issues" target="_blank" rel="nofollow">https://github.com/mcneel/ghpython/issues</a><br />
<br />
Use your python scripting skills in Rhino 5 for Windows, Rhino 5 for Mac, and in Grasshopper for Rhino 5;)<br />
Thanks,<br />
-Steve</blockquote>

 ]]></content:encoded>
			<dc:creator>Steve Baer</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=366</guid>
		</item>
		<item>
			<title>Running scripts from Toolbar buttons</title>
			<link>http://python.rhino3d.com/blog.php?b=364</link>
			<pubDate>Mon, 11 Apr 2011 17:47:53 GMT</pubDate>
			<description><![CDATA[This is only for Windows Rhino right now since you can't customize toolbar buttons on Mac yet, but once that feature becomes available I'm pretty...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">This is only for Windows Rhino right now since you can't customize toolbar buttons on Mac yet, but once that feature becomes available I'm pretty sure the technique will be the same.<br />
<br />
In Rhino, create a new toolbar button and edit it.  Consult the Rhino help for for adding and editing toolbar buttons. Now you have three options (that I can think of at the moment) for adding a python script to a toolbar button.  All of these involve executing the RunPythonScript command<br />
<br />
<a href="http://python.rhino3d.com/attachment.php?attachmentid=184&amp;d=1302543959" id="attachment184" rel="Lightbox_364" ><img src="http://python.rhino3d.com/attachment.php?attachmentid=184&amp;d=1302543959&amp;thumb=1" border="0" alt="Click image for larger version

Name:	editbutton.png
Views:	299
Size:	58.5 KB
ID:	184" class="thumbnail" /></a><br />
<ol class="decimal"><li>Directly embed the script<br />
Make sure the first line reads <b>-_RunPythonScript (</b>. Note that there needs to be a space between RunPythonScript and the parentheses.<br />
Make sure the last line is just a closing parentheses. The lines in between are interpreted as your python script.<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Python Code:</div>
	<div class="geshi_highlight">
  <div dir="ltr" style="text-align:left;"><div class="python"><ol><div class="de1">-_RunPythonScript <span class="br0">&#40;</span></div><div class="de1"><span class="kw1">import</span> rhinoscriptsyntax as rs</div><div class="de1">point0 = rs.<span class="me1">GetPoint</span><span class="br0">&#40;</span><span class="st0">"start"</span><span class="br0">&#41;</span></div><div class="de1">point1 = rs.<span class="me1">GetPoint</span><span class="br0">&#40;</span><span class="st0">"end"</span><span class="br0">&#41;</span></div><div class="de1">rs.<span class="me1">AddLine</span><span class="br0">&#40;</span>point0,point1<span class="br0">&#41;</span></div><div class="de1"><span class="br0">&#41;</span> </div></ol></div></div></div>
</div></li>
<li>Absolute path to the script<br />
<b>-_RunPythonScript (C:\Users\a-steve\Desktop\CurveLength.py)</b></li>
<li>Path to script on search path<br />
If the script is on python's search path, you can use the following form to let python find the script (use period separate subdirectories.)<br />
<b>-_RunPythonScript (Samples.CurveLength.py)</b></li>
</ol></blockquote>

 ]]></content:encoded>
			<dc:creator>Steve Baer</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=364</guid>
		</item>
		<item>
			<title>Komodo Edit on Mac and RhinoPython</title>
			<link>http://python.rhino3d.com/blog.php?b=363</link>
			<pubDate>Tue, 15 Mar 2011 16:45:07 GMT</pubDate>
			<description>Image: http://wiki.mcneel.com/_media/rhino/mac/komodoedit.png  
 
Komodo Edit can be configured to recognize the rhinoscriptsyntax module which...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore"><img src="http://wiki.mcneel.com/_media/rhino/mac/komodoedit.png" border="0" alt="" /><br />
<br />
Komodo Edit can be configured to recognize the rhinoscriptsyntax module which provides for editor features like autocomplete and function tooltips.<br />
<ul><li>Download and start Komodo Edit - <a href="http://www.activestate.com/komodo-edit" target="_blank" rel="nofollow">http://www.activestate.com/komodo-edit</a></li>
<li>On the menu, select Komodo-&gt;Preferences...</li>
<li>Expand &quot;Languages&quot; and select &quot;Python&quot;</li>
<li>In the Additional Python Import Directories click on the &quot;add&quot; button and navigate to<br />
/Users/&lt;your user name&gt;/Application Support/McNeel/Rhinoceros/MacPlugIns/IronPython/settings/lib</li>
<li> Click OK, it may take a minute for Komodo Edit to parse all of the files and generate autocomplete information, but once that is done you should be able to type your Mac Rhino python scripts with a little help from Komodo!!</li>
</ul><a href="http://python.rhino3d.com/attachment.php?attachmentid=169&amp;d=1300207305" id="attachment169" rel="Lightbox_363" ><img src="http://python.rhino3d.com/attachment.php?attachmentid=169&amp;d=1300207305&amp;thumb=1" border="0" alt="Click image for larger version

Name:	komodosetup.png
Views:	269
Size:	69.6 KB
ID:	169" class="thumbnail" /></a></blockquote>

 ]]></content:encoded>
			<dc:creator>Steve Baer</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=363</guid>
		</item>
		<item>
			<title>ACADIA and MIT wrap up</title>
			<link>http://python.rhino3d.com/blog.php?b=138</link>
			<pubDate>Tue, 26 Oct 2010 17:10:03 GMT</pubDate>
			<description>Just got back from a trip to New York and Boston for the ACADIA conference (http://www.acadia.org/acadia2010/). I want to thank everyone that spent...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Just got back from a trip to New York and Boston for the ACADIA conference (<a href="http://www.acadia.org/acadia2010/" target="_blank" rel="nofollow">http://www.acadia.org/acadia2010/</a>). I want to thank everyone that spent the time to meet with me and talk python. In particular, it was great getting together with<br />
Marc Fornes - <a href="http://theverymany.com/" target="_blank" rel="nofollow">http://theverymany.com/</a><br />
Skylar Tibbits - <a href="http://www.sjet.us/" target="_blank" rel="nofollow">http://www.sjet.us/</a><br />
<br />
who from what I can tell are doing most of their Rhino oriented scripting in python now. Nice!<br />
<br />
-Steve</blockquote>

 ]]></content:encoded>
			<dc:creator>Steve Baer</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=138</guid>
		</item>
		<item>
			<title>StarMaker - An advanced sample</title>
			<link>http://python.rhino3d.com/blog.php?b=42</link>
			<pubDate>Thu, 22 Jul 2010 20:33:40 GMT</pubDate>
			<description><![CDATA[Here's a sample that demonstrates quite a few of the advanced features in Rhino.python.  This sample was written and tested on Windows (I doubt it is...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Here's a sample that demonstrates quite a few of the advanced features in Rhino.python.  This sample was written and tested on Windows (I doubt it is going to work very well on OSX given that Windows.Forms are being used.) You are going to need to be running at least the July 20th build of Rhino 5 to test this.<br />
<br />
StarMaker is composed of two script files; starmaker.py and sliderform.py. Save these files to the same directory.<br />
<br />
What does it do? StarMaker just creates a new curve based on points from a closed planar polyline and some input from a form. Run the Polygon command and create a polygon with something like 30 edges. Then run starmaker.py<br />
<br />
Some python features demonstrated:<ol class="decimal"><li>Multiple Script Files - the python script is broken into two files. sliderform.py doesn't do anything on it's own and is imported into starmaker.py</li>
<li>Direct use of RhinoCommon - the script uses some of the functionality provided by the rhinoscript python functions, but it really makes heavy use of .NET classes defined in RhinoCommon</li>
<li>Custom Windows Form - This is pretty cool!!! sliderform.py is a custom Wnidows Form user interface. This file was actually created in SharpDevelop (<a href="http://www.icsharpcode.net/opensource/sd/" target="_blank" rel="nofollow">http://www.icsharpcode.net/opensource/sd/</a>). SharpDevelop has a nice user interface editor for creating custom forms which are written as python files. Try opening sliderform.py in SharpDevelop and click on the design button. (See the attached SharpDev image)</li>
<li>Custom Display for Preview Geometry - The red curve, dotted lines, and points in the screenshot are not actual geometry in the rhino document but are drawn using display callbacks (also know as conduits)</li>
</ol><br />
Calling RhinoCommon from python hasn't been covered too much on this site so much of the script may look foreign.<br />
<br />
I want to thank Marc Fornes of <a href="http://www.theverymany.com" target="_blank" rel="nofollow">www.theverymany.com</a> for inspiring this sample.<br />
<br />
<img src="http://python.rhino3d.com/attachment.php?attachmentid=93&amp;stc=1&amp;d=1279824020" border="0" alt="" /></blockquote>


<!-- attachments -->
	<div class="blogattachments">
		
			<fieldset class="blogcontent">
				<legend>Attached Thumbnails</legend>
				
			</fieldset>
		
		
		
		
			<fieldset class="blogcontent">
				<legend>Attached Files</legend>
				<ul>
					
				</ul>
			</fieldset>
		

	</div>
<!-- / attachments -->
 ]]></content:encoded>
			<dc:creator>Steve Baer</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=42</guid>
		</item>
		<item>
			<title>Configuring Pydev for Rhino.Python</title>
			<link>http://python.rhino3d.com/blog.php?b=12</link>
			<pubDate>Sat, 12 Jun 2010 23:40:31 GMT</pubDate>
			<description><![CDATA[Image: http://pydev.org/images/pydev_banner2.gif  
*NOTE*: This article is specific to getting Pydev to work on *Windows*. I've had problems getting...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore"><img src="http://pydev.org/images/pydev_banner2.gif" border="0" alt="" /><br />
<b>NOTE</b>: This article is specific to getting Pydev to work on <b>Windows</b>. I've had problems getting the ironpython interpreter to work inside Pydev on Mac. Hopefully this will inspire someone to hack away at the Mac version of Pydev and figure out what it takes to make it work for Rhino.Python.<br />
<br />
<u>What's Pydev?</u><br />
The folks at Pydev can probably do a much better job of explaining their product (<a href="http://pydev.org/index.html" target="_blank" rel="nofollow">http://pydev.org/index.html</a>). In short, Pydev is a popular Python script editor (and debugger).  Several python scripters who are familiar with Pydev have asked about how to configure it for editing Rhino.Python scripts.<br />
<br />
Rhino for windows already comes with a built-in python editor, but I can understand that people will want to use a different editor for many reasons (they're familiar with it or it has features that are missing in the Rhino editor.) Here's the steps I took to get this to work on my Windows 7 computer.<br />
<br />
<b>A. Install Pydev</b> - Here's a page I used to get everything set up for Pydev <a href="http://pydev.org/manual_101_root.html" target="_blank" rel="nofollow">http://pydev.org/manual_101_root.html</a><br />
If you've already installed Pydev on your computer, you can skip this section.<ol class="decimal"><li> Download eclipse (<a href="http://www.eclipse.org/downloads/" target="_blank" rel="nofollow">http://www.eclipse.org/downloads/</a>).<br />
I downloaded Eclipse Classic 3.6.1 (~170MB) 32bit version for windows.<br />
I downloaded the 32 bit version because I haven't installed the 64 bit version of java on my computer and eclipse requires java to run.<br />
File name is  eclipse-SDK-3.6.1-win32.zip</li>
<li> Unzip file and double click on the eclipse.exe to start eclipse</li>
<li> go to help-&gt;Install Software and type the following URL into the Work with text box<br />
<a href="http://pydev.org/updates" target="_blank" rel="nofollow">http://pydev.org/updates</a></li>
<li> You should get checkboxes for available pydev plug-ins. Check the Pydev item and click next, then finish</li>
<li> This installs the pydev plug-in for eclipse</li>
</ol><br />
<br />
<b>B. Install IronPython Executables</b><br />
Rhino.Python uses Microsoft's IronPython engine to process python scripts. Pydev is going to need to use this same engine in  order to get things like auto-complete to work.<ol class="decimal"><li> Go to codeplex and Install &quot;IronPython 2.6.2 for .NET 4.0&quot; <a href="http://ironpython.codeplex.com/releases/view/41236" target="_blank" rel="nofollow">http://ironpython.codeplex.com/releases/view/41236</a><br />
The download link is in the upper right corner of the web page</li>
<li> This installs the command IronPython command line interpreter which is needed by PyDev</li>
</ol><br />
<br />
<b>C. Configure Pydev</b><ol class="decimal"><li> Start eclipse.exe</li>
<li> Select Preferences from the Window menu</li>
<li> Expand the Pydev node in the preferences tree  and select &quot;Interpreter - Iron Python&quot;</li>
<li> Click the &quot;New...&quot; button which brings up a &quot;Select Interpreter&quot; dialog</li>
<li> Click the &quot;Browse...&quot; button and select ipy.exe which on my computer happens to be located at<br />
C:\Program Files (x86)\IronPython 2.6\ipy.exe</li>
<li> Click OK and then another OK to accept the default folders added to the SYSTEM pythonpath</li>
<li> Add the lib folder that contains the rhinoscript package to the system python path in order for Pydev to recognize any of the rhinoscript functions<br />
On the Libraries tab click click the &quot;New Folder&quot; button and pick the directory where the rhinoscript package is located. You can find this folder location by looking at the Paths in the built-in Rhino.Python editor. On my computer this directory is located at<br />
C:\Users\a-steve\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib</li>
<li> Add RhinoCommon as a &quot;Forced Builtin&quot;. In order to do this we need to create a directory that will be on the python path. I created a new folder in the eclipse directory called pydevrhino and added it to the python path by clicking the &quot;New Folder&quot; button on the Libraries tab and selecting this new folder. On my computer, this folder is located at<br />
C:\Users\a-steve\Desktop\eclipse-SDK-3.5.2-win32\pydevrhino</li>
<li> Pydev has a limitation where it can only read .NET assemblies with a root namespace the same as the dll. We want to get at all of the classes inside of RhinoCommon.DLL, but the root namespace in this DLL is Rhino. Go to the Rhino5 system folder (where the main executable is located) and copy RhinoCommon.dll (and RhinoCommon.xml) to the new folder that you created in the previous step. In the new folder, rename these files to Rhino.dll and Rhino.xml (DON'T CHANGE THE FILES IN THE RHINO SYSTEM DIRECTORY).</li>
<li> Go to the &quot;Forced Builtins&quot; tab, click New... button and type in &quot;Rhino&quot;.</li>
</ol><br />
<b>D. Start Using Pydev</b><br />
Good luck! Here's what I get for autocomplete on Rhino and rhinoscript classes/functions<br />
<br />
<img src="http://python.rhino3d.com/attachment.php?attachmentid=79&amp;stc=1&amp;d=1276384997" border="0" alt="" /></blockquote>

 ]]></content:encoded>
			<dc:creator>Steve Baer</dc:creator>
			<guid isPermaLink="true">http://python.rhino3d.com/blog.php?b=12</guid>
		</item>
	</channel>
</rss>
