PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/branches/refactor2/skeinforge/skeinforge.py

http://replicatorg.googlecode.com/
Python | 314 lines | 240 code | 51 blank | 23 comment | 39 complexity | bd2b4e9825a52f979f08cc9cd438a98c 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. Fabrication
  68. To fabricate a model with gcode and the Arduino you can use the send.py in the fabricate folder. The documentation for it is
  69. in the folder as send.html and at:
  70. http://reprap.org/bin/view/Main/ArduinoSend
  71. Another way is to use an EMC2 or similar computer controlled milling machine, as described in the "ECM2 based repstrap"
  72. forum thread at:
  73. http://forums.reprap.org/read.php?1,12143
  74. using the M-Apps package, which is at:
  75. http://forums.reprap.org/file.php?1,file=772
  76. Another way is to use Zach's ReplicatorG at:
  77. http://replicat.org/
  78. There is also an older Processing script at:
  79. http://reprap.svn.sourceforge.net/viewvc/reprap/trunk/users/hoeken/arduino/GCode_Host/
  80. Yet another way is to use the reprap host, written in Java, to load and print gcode:
  81. http://dev.www.reprap.org/bin/view/Main/DriverSoftware#Load_GCode
  82. For jogging, the Metalab group wrote their own exerciser, also in Processing:
  83. http://reprap.svn.sourceforge.net/viewvc/reprap/trunk/users/metalab/processing/GCode_Exerciser/
  84. The Metalab group has descriptions of skeinforge in action and their adventures are described at:
  85. http://reprap.soup.io/
  86. File Formats
  87. An explanation of the gcodes is at:
  88. http://reprap.org/bin/view/Main/Arduino_GCode_Interpreter
  89. and at:
  90. http://reprap.org/bin/view/Main/MCodeReference
  91. A gode example is at:
  92. http://forums.reprap.org/file.php?12,file=565
  93. The preferences are saved as tab separated .csv files in the .skeinforge folder in your home directory. The preferences can
  94. 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.
  95. The Scalable Vector Graphics file produced by vectorwrite can be opened by an SVG viewer or an SVG capable browser
  96. like Mozilla:
  97. http://www.mozilla.com/firefox/
  98. A good triangle surface format is the GNU Triangulated Surface format, which is supported by Mesh Viewer and described at:
  99. http://gts.sourceforge.net/reference/gts-surfaces.html#GTS-SURFACE-WRITE
  100. You can export GTS files from Art of Illusion with the Export GNU Triangulated Surface.bsh script in the Art of Illusion Scripts
  101. folder.
  102. STL is an inferior triangle surface format, described at:
  103. http://en.wikipedia.org/wiki/STL_(file_format)
  104. 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
  105. it still doesn't carve, then follow the advice in the troubleshooting section.
  106. Getting Skeinforge
  107. The latest version is at:
  108. http://members.axion.net/~enrique/reprap_python_beanshell.zip
  109. a sometimes out of date version is in the last reprap_python_beanshell.zip attachment in the "Skeinforge Powwow" thread at:
  110. http://forums.reprap.org/read.php?12,20013
  111. another sometimes out of date version is at:
  112. https://reprap.svn.sourceforge.net/svnroot/reprap/trunk/reprap/miscellaneous/python-beanshell-scripts/
  113. Motto
  114. I may be slow, but I get there in the end.
  115. Troubleshooting
  116. If there's a bug, try downloading the very latest version because sometimes I update without posting.
  117. Then you can ask for skeinforge help by sending a private message through the forum software by going to my page at:
  118. http://forums.reprap.org/profile.php?12,488
  119. or posting in the "Skeinforge Powwow" thread at:
  120. http://forums.reprap.org/read.php?12,20013
  121. When asking for help please include your object and your zipped skeinforge preferences. The skeinforge preferences are in
  122. the .skeinforge folder in your home directory.
  123. Examples
  124. The following examples carve and dice the STL file Screw Holder.stl. The examples are run in a terminal in the folder which
  125. contains Screw Holder.gts and skeinforge.py.
  126. > python skeinforge.py
  127. This brings up the dialog, after clicking 'Skeinforge', the following is printed:
  128. The exported file is saved as Screw Holder_export.gcode
  129. > python skeinforge.py Screw Holder.stl
  130. The exported file is saved as Screw Holder_export.gcode
  131. > python
  132. Python 2.5.1 (r251:54863, Sep 22 2007, 01:43:31)
  133. [GCC 4.2.1 (SUSE Linux)] on linux2
  134. Type "help", "copyright", "credits" or "license" for more information.
  135. >>> import skeinforge
  136. >>> skeinforge.writeOutput()
  137. The exported file is saved as Screw Holder_export.gcode
  138. >>> skeinforge.main()
  139. This brings up the skeinforge dialog.
  140. """
  141. from __future__ import absolute_import
  142. from skeinforge_tools.skeinforge_utilities import gcodec
  143. from skeinforge_tools.skeinforge_utilities import preferences
  144. from skeinforge_tools.skeinforge_utilities import interpret
  145. from skeinforge_tools import polyfile
  146. import cStringIO
  147. import sys
  148. __author__ = "Enrique Perez (perez_enrique@yahoo.com)"
  149. __credits__ = """
  150. Adrian Bowyer <http://forums.reprap.org/profile.php?12,13>
  151. Brendan Erwin <http://forums.reprap.org/profile.php?12,217>
  152. Greenarrow <http://forums.reprap.org/profile.php?12,81>
  153. Ian England <http://forums.reprap.org/profile.php?12,192>
  154. John Gilmore <http://forums.reprap.org/profile.php?12,364>
  155. Jonwise <http://forums.reprap.org/profile.php?12,716>
  156. Kyle Corbitt <http://forums.reprap.org/profile.php?12,90>
  157. Michael Duffin <http://forums.reprap.org/profile.php?12,930>
  158. Marius Kintel <http://reprap.soup.io/>
  159. Nophead <http://www.blogger.com/profile/12801535866788103677>
  160. PJR <http://forums.reprap.org/profile.php?12,757>
  161. Reece.Arnott <http://forums.reprap.org/profile.php?12,152>
  162. Wade <http://forums.reprap.org/profile.php?12,489>
  163. Xsainnz <http://forums.reprap.org/profile.php?12,563>
  164. Zach Hoeken <http://blog.zachhoeken.com/>
  165. Organizations:
  166. Art of Illusion <http://www.artofillusion.org/>"""
  167. __date__ = "$Date: 2008/21/11 $"
  168. __license__ = "GPL 3.0"
  169. def getSkeinforgeToolFilenames():
  170. "Get skeinforge plugin fileNames."
  171. return gcodec.getPluginFilenames( 'skeinforge_tools', __file__ )
  172. def writeOutput( fileName = '' ):
  173. "Skeinforge a gcode file. If no fileName is specified, skeinforge the first gcode file in this folder that is not modified."
  174. skeinforgePluginFilenames = getSkeinforgeToolFilenames()
  175. toolNames = 'export unpause fillet oozebane wipe hop stretch clip comb tower raft speed multiply fill inset carve'.split()
  176. for toolName in toolNames:
  177. for skeinforgePluginFilename in skeinforgePluginFilenames:
  178. if skeinforgePluginFilename == toolName:
  179. pluginModule = gcodec.getModule( skeinforgePluginFilename, 'skeinforge_tools', __file__ )
  180. if pluginModule != None:
  181. pluginModule.writeOutput( fileName )
  182. return
  183. class SkeinforgePreferences:
  184. "A class to handle the skeinforge preferences."
  185. def __init__( self ):
  186. "Set the default preferences, execute title & preferences fileName."
  187. #Set the default preferences.
  188. self.archive = []
  189. self.skeinforgeLabel = preferences.LabelDisplay().getFromName( 'Open Preferences: ' )
  190. self.archive.append( self.skeinforgeLabel )
  191. skeinforgePluginFilenames = getSkeinforgeToolFilenames()
  192. self.skeinforgeDisplayToolButtons = []
  193. for skeinforgePluginFilename in skeinforgePluginFilenames:
  194. skeinforgeDisplayToolButton = preferences.DisplayToolButton().getFromFolderName( 'skeinforge_tools', __file__, skeinforgePluginFilename )
  195. self.skeinforgeDisplayToolButtons.append( skeinforgeDisplayToolButton )
  196. self.archive += self.skeinforgeDisplayToolButtons
  197. self.fileNameInput = preferences.Filename().getFromFilename( interpret.getGNUTranslatorGcodeFileTypeTuples(), 'Open File to be Skeinforged', '' )
  198. self.archive.append( self.fileNameInput )
  199. #Create the archive, title of the execute button, title of the dialog & preferences fileName.
  200. self.executeTitle = 'Skeinforge'
  201. self.saveTitle = None
  202. preferences.setHelpPreferencesFileNameTitleWindowPosition( self, 'skeinforge.html' )
  203. def execute( self ):
  204. "Skeinforge button has been clicked."
  205. fileNames = polyfile.getFileOrDirectoryTypesUnmodifiedGcode( self.fileNameInput.value, interpret.getImportPluginFilenames(), self.fileNameInput.wasCancelled )
  206. for fileName in fileNames:
  207. writeOutput( fileName )
  208. def main():
  209. "Display the skeinforge dialog."
  210. if len( sys.argv ) > 1:
  211. writeOutput( ' '.join( sys.argv[ 1 : ] ) )
  212. else:
  213. preferences.displayDialog( SkeinforgePreferences() )
  214. if __name__ == "__main__":
  215. main()