PageRenderTime 33ms CodeModel.GetById 4ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/0006/skeinforge/skeinforge.py

http://replicatorg.googlecode.com/
Python | 316 lines | 242 code | 51 blank | 23 comment | 39 complexity | e76877a06120d13939802f900cc415ea MD5 | raw file
Possible License(s): AGPL-1.0
  1. #!/usr/bin/python
  2. """
  3. Introduction
  4. Skeinforge is a GPL tool chain to forge a gcode skein for a model.
  5. The tool chain starts with carve, which carves the model into layers, then the layers are modified by other tools in turn like
  6. fill, comb, tower, raft, stretch, hop, wipe, oozebane, fillet & export. Each tool automatically gets the gcode from the
  7. previous tool. So if you want a carved & filled gcode, call the fill tool and it will call carve, then it will fill and output the
  8. gcode. If you want to use all the tools, call export and it will call in turn all the other tools down the chain to produce the gcode file.
  9. The skeinforge module provides a single place to call up all the preference dialogs. When the 'Skeinforge' button is clicked,
  10. skeinforge calls export, since that is the end of the chain.
  11. To run skeinforge, type in a shell in the same folder as skeinforge:
  12. > python skeinforge.py
  13. To run only fill for example, type in the skeinforge_tools folder which fill is in:
  14. > python fill.py
  15. If you do not want a tool after fill to modify the output, deselect the Activate checkbox for that tool. When the Activate checkbox
  16. is off, the tool will just hand off the gcode to the next tool without modifying it.
  17. There are also tools which handle preferences for the chain, like material & polyfile.
  18. The analyze tool calls plugins in the analyze_plugins folder, which will analyze the gcode in some way when it is generated if
  19. their Activate checkbox is selected.
  20. The interpret tool accesses and displays the import plugins.
  21. The default preferences are similar to those on Nophead's machine. A preference which is often different is the
  22. 'Extrusion Diameter' in carve.
  23. Alternative
  24. Another way to make gcode for a model is to use the Java RepRap host program, described at:
  25. http://dev.www.reprap.org/bin/view/Main/DriverSoftware#Creating_GCode_files_from_STL_fi
  26. Getting Started
  27. For skeinforge to run, install python 2.x on your machine, which is available from:
  28. http://www.python.org/download/
  29. To use the preferences dialog you'll also need Tkinter, which probably came with the python installation. If it did not, look for it at:
  30. http://www.tcl.tk/software/tcltk/
  31. If you want python and Tkinter together on MacOS, you can try:
  32. http://www.astro.washington.edu/owen/PythonOnMacOSX.html
  33. If you want python and Tkinter together on all platforms and don't mind filling out forms, you can try the ActivePython package
  34. from Active State at:
  35. http://www.activestate.com/Products/activepython/feature_list.mhtml
  36. Skeinforge imports Stereolithography (.stl) files or GNU Triangulated Surface (.gts) files. The import plugin for STL files is
  37. experimental and if it doesn't work, an indirect way to import an STL file is by turning it into a GTS file is by using the Export GNU
  38. Triangulated Surface script at:
  39. http://members.axion.net/~enrique/Export%20GNU%20Triangulated%20Surface.bsh
  40. The Export GNU Triangulated Surface script is also in the Art of Illusion folder, which is in the same folder as skeinforge.py. To
  41. bring the script into Art of Illusion, drop it into the folder ArtOfIllusion/Scripts/Tools/. Then import the STL file using the STL
  42. import plugin in the import submenu of the Art of Illusion file menu. Then from the Scripts submenu in the Tools menu, choose
  43. 'Export GNU Triangulated Surface' and select the imported STL shape. Click the 'Export Selected' checkbox and click OK.
  44. Once you've created the GTS file, you can turn it into gcode by typing in a shell in the same folder as skeinforge:
  45. > python skeinforge.py
  46. When the skeinforge dialog pops up, click 'Skeinforge', choose the file which you exported in 'Export GNU Triangulated Surface'
  47. and the gcode file will be saved with the suffix '_export.gcode'.
  48. Or you can turn files into gcode by adding the file name, for example:
  49. > python skeinforge.py Screw Holder Bottom.stl
  50. End of the Beginning
  51. When carve is generating the code, if there is a file start.txt, it will add that to the very beginning of the gcode. After it has
  52. added some initialization code and just before it adds the extrusion gcode, it will add the file endofthebeginning.txt if it exists.
  53. At the very end, it will add the file end.txt if it exists. Carve does not care if the text file names are capitalized, but some file
  54. systems do not handle file name cases properly, so to be on the safe side you should give them lower case names. It will
  55. first look for the file in the same directory as carve, if it does not find it it will look in ~/.skeinforge/gcode_scripts.
  56. The computation intensive python modules will use psyco if it is available and run about twice as fast. Psyco is described at:
  57. http://psyco.sourceforge.net/index.html
  58. The psyco download page is:
  59. http://psyco.sourceforge.net/download.html
  60. Documentation
  61. The documentation is in the documentation folder, in the doc strings for each module and it can be called from the '?'
  62. button in each preference dialog.
  63. To modify the documentation for this program, modify the first comment in the desired module. Then open a shell in
  64. the skeinforge.py directory, then type:
  65. > pydoc -w ./'
  66. Then move all the generated html files to the documentation folder.
  67. There is a list of tutorials at:
  68. http://dev.www.reprap.org/bin/view/Main/SkeinforgeTutorials
  69. Fabrication
  70. To fabricate a model with gcode and the Arduino you can use the send.py in the fabricate folder. The documentation for it is
  71. in the folder as send.html and at:
  72. http://reprap.org/bin/view/Main/ArduinoSend
  73. Another way is to use an EMC2 or similar computer controlled milling machine, as described in the "ECM2 based repstrap"
  74. forum thread at:
  75. http://forums.reprap.org/read.php?1,12143
  76. using the M-Apps package, which is at:
  77. http://forums.reprap.org/file.php?1,file=772
  78. Another way is to use Zach's ReplicatorG at:
  79. http://replicat.org/
  80. There is also an older Processing script at:
  81. http://reprap.svn.sourceforge.net/viewvc/reprap/trunk/users/hoeken/arduino/GCode_Host/
  82. Yet another way is to use the reprap host, written in Java, to load and print gcode:
  83. http://dev.www.reprap.org/bin/view/Main/DriverSoftware#Load_GCode
  84. For jogging, the Metalab group wrote their own exerciser, also in Processing:
  85. http://reprap.svn.sourceforge.net/viewvc/reprap/trunk/users/metalab/processing/GCode_Exerciser/
  86. The Metalab group has descriptions of skeinforge in action and their adventures are described at:
  87. http://reprap.soup.io/
  88. File Formats
  89. An explanation of the gcodes is at:
  90. http://reprap.org/bin/view/Main/Arduino_GCode_Interpreter
  91. and at:
  92. http://reprap.org/bin/view/Main/MCodeReference
  93. A gode example is at:
  94. http://forums.reprap.org/file.php?12,file=565
  95. The preferences are saved as tab separated .csv files in the .skeinforge folder in your home directory. The preferences can
  96. be set in the tool dialogs. The .csv files can also be edited with a text editor or a spreadsheet program set to separate tabs.
  97. The Scalable Vector Graphics file produced by vectorwrite can be opened by an SVG viewer or an SVG capable browser
  98. like Mozilla:
  99. http://www.mozilla.com/firefox/
  100. A good triangle surface format is the GNU Triangulated Surface format, which is supported by Mesh Viewer and described at:
  101. http://gts.sourceforge.net/reference/gts-surfaces.html#GTS-SURFACE-WRITE
  102. You can export GTS files from Art of Illusion with the Export GNU Triangulated Surface.bsh script in the Art of Illusion Scripts
  103. folder.
  104. STL is an inferior triangle surface format, described at:
  105. http://en.wikipedia.org/wiki/STL_(file_format)
  106. If you're using an STL file and you can't even carve it, try converting it to a GNU Triangulated Surface file in Art of Illusion. If
  107. it still doesn't carve, then follow the advice in the troubleshooting section.
  108. Getting Skeinforge
  109. The latest version is at:
  110. http://members.axion.net/~enrique/reprap_python_beanshell.zip
  111. a sometimes out of date version is in the last reprap_python_beanshell.zip attachment in the "Skeinforge Powwow" thread at:
  112. http://forums.reprap.org/read.php?12,20013
  113. another sometimes out of date version is at:
  114. https://reprap.svn.sourceforge.net/svnroot/reprap/trunk/reprap/miscellaneous/python-beanshell-scripts/
  115. Motto
  116. I may be slow, but I get there in the end.
  117. Troubleshooting
  118. If there's a bug, try downloading the very latest version because sometimes I update without posting.
  119. Then you can ask for skeinforge help by sending a private message through the forum software by going to my page at:
  120. http://forums.reprap.org/profile.php?12,488
  121. or posting in the "Skeinforge Powwow" thread at:
  122. http://forums.reprap.org/read.php?12,20013
  123. When asking for help please include your object and your zipped skeinforge preferences. The skeinforge preferences are in
  124. the .skeinforge folder in your home directory.
  125. Examples
  126. The following examples carve and dice the STL file Screw Holder.stl. The examples are run in a terminal in the folder which
  127. contains Screw Holder.gts and skeinforge.py.
  128. > python skeinforge.py
  129. This brings up the dialog, after clicking 'Skeinforge', the following is printed:
  130. The exported file is saved as Screw Holder_export.gcode
  131. > python skeinforge.py Screw Holder.stl
  132. The exported file is saved as Screw Holder_export.gcode
  133. > python
  134. Python 2.5.1 (r251:54863, Sep 22 2007, 01:43:31)
  135. [GCC 4.2.1 (SUSE Linux)] on linux2
  136. Type "help", "copyright", "credits" or "license" for more information.
  137. >>> import skeinforge
  138. >>> skeinforge.writeOutput()
  139. The exported file is saved as Screw Holder_export.gcode
  140. >>> skeinforge.main()
  141. This brings up the skeinforge dialog.
  142. """
  143. from __future__ import absolute_import
  144. from skeinforge_tools.skeinforge_utilities import gcodec
  145. from skeinforge_tools.skeinforge_utilities import preferences
  146. from skeinforge_tools.skeinforge_utilities import interpret
  147. from skeinforge_tools import polyfile
  148. import cStringIO
  149. import sys
  150. __author__ = "Enrique Perez (perez_enrique@yahoo.com)"
  151. __credits__ = """
  152. Adrian Bowyer <http://forums.reprap.org/profile.php?12,13>
  153. Brendan Erwin <http://forums.reprap.org/profile.php?12,217>
  154. Greenarrow <http://forums.reprap.org/profile.php?12,81>
  155. Ian England <http://forums.reprap.org/profile.php?12,192>
  156. John Gilmore <http://forums.reprap.org/profile.php?12,364>
  157. Jonwise <http://forums.reprap.org/profile.php?12,716>
  158. Kyle Corbitt <http://forums.reprap.org/profile.php?12,90>
  159. Michael Duffin <http://forums.reprap.org/profile.php?12,930>
  160. Marius Kintel <http://reprap.soup.io/>
  161. Nophead <http://www.blogger.com/profile/12801535866788103677>
  162. PJR <http://forums.reprap.org/profile.php?12,757>
  163. Reece.Arnott <http://forums.reprap.org/profile.php?12,152>
  164. Wade <http://forums.reprap.org/profile.php?12,489>
  165. Xsainnz <http://forums.reprap.org/profile.php?12,563>
  166. Zach Hoeken <http://blog.zachhoeken.com/>
  167. Organizations:
  168. Art of Illusion <http://www.artofillusion.org/>"""
  169. __date__ = "$Date: 2008/21/11 $"
  170. __license__ = "GPL 3.0"
  171. def getSkeinforgeToolFilenames():
  172. "Get skeinforge plugin fileNames."
  173. return gcodec.getPluginFilenames( 'skeinforge_tools', __file__ )
  174. def writeOutput( fileName = '' ):
  175. "Skeinforge a gcode file. If no fileName is specified, skeinforge the first gcode file in this folder that is not modified."
  176. skeinforgePluginFilenames = getSkeinforgeToolFilenames()
  177. toolNames = 'export unpause fillet oozebane wipe hop stretch clip comb tower raft speed multiply fill inset carve'.split()
  178. for toolName in toolNames:
  179. for skeinforgePluginFilename in skeinforgePluginFilenames:
  180. if skeinforgePluginFilename == toolName:
  181. pluginModule = gcodec.getModule( skeinforgePluginFilename, 'skeinforge_tools', __file__ )
  182. if pluginModule != None:
  183. pluginModule.writeOutput( fileName )
  184. return
  185. class SkeinforgePreferences:
  186. "A class to handle the skeinforge preferences."
  187. def __init__( self ):
  188. "Set the default preferences, execute title & preferences fileName."
  189. #Set the default preferences.
  190. self.archive = []
  191. self.skeinforgeLabel = preferences.LabelDisplay().getFromName( 'Open Preferences: ' )
  192. self.archive.append( self.skeinforgeLabel )
  193. skeinforgePluginFilenames = getSkeinforgeToolFilenames()
  194. self.skeinforgeDisplayToolButtons = []
  195. for skeinforgePluginFilename in skeinforgePluginFilenames:
  196. skeinforgeDisplayToolButton = preferences.DisplayToolButton().getFromFolderName( 'skeinforge_tools', __file__, skeinforgePluginFilename )
  197. self.skeinforgeDisplayToolButtons.append( skeinforgeDisplayToolButton )
  198. self.archive += self.skeinforgeDisplayToolButtons
  199. self.fileNameInput = preferences.Filename().getFromFilename( interpret.getGNUTranslatorGcodeFileTypeTuples(), 'Open File to be Skeinforged', '' )
  200. self.archive.append( self.fileNameInput )
  201. #Create the archive, title of the execute button, title of the dialog & preferences fileName.
  202. self.executeTitle = 'Skeinforge'
  203. self.saveTitle = None
  204. preferences.setHelpPreferencesFileNameTitleWindowPosition( self, 'skeinforge.html' )
  205. def execute( self ):
  206. "Skeinforge button has been clicked."
  207. fileNames = polyfile.getFileOrDirectoryTypesUnmodifiedGcode( self.fileNameInput.value, interpret.getImportPluginFilenames(), self.fileNameInput.wasCancelled )
  208. for fileName in fileNames:
  209. writeOutput( fileName )
  210. def main():
  211. "Display the skeinforge dialog."
  212. if len( sys.argv ) > 1:
  213. writeOutput( ' '.join( sys.argv[ 1 : ] ) )
  214. else:
  215. preferences.displayDialog( SkeinforgePreferences() )
  216. if __name__ == "__main__":
  217. main()