Permalink
Browse files

Done! All done! The script now can process stock Makerbot GCodes real…

…istically!

This means that the extruded filament dimensions are now read directly from the skeinforge machine-generated comments in the GCode file.
What you see here is what you'll get when the object has been printed.

This should have been easier to do, but due to Blender's polyline function not allowing for sharp directional changes without serious profile skewing/distorting,
it took WAY LONGER than expected to implement this functionality.

A big shout-out goes to my friend Jon Spyreas for helping me block-out the maths needed in the "addArc" subroutine
Thanks a million dude!
  • Loading branch information...
1 parent 4758310 commit 7610fd5d12ac37429b8867239b009d31d9a988ad @Winter-Guerra committed Feb 18, 2012
Showing with 73 additions and 60 deletions.
  1. +30 −23 README
  2. +43 −37 io_import_gcode.py
View
@@ -1,38 +1,45 @@
-blender gcode reader
-reads reprap gcode files into blender 2.5 for rendering and visualization
+Blender GCode Reader Add-on
+Reads reprap gcode files into blender 2.6 for rendering and visualization
-modified by Alessandro Ranellucci (2011-10-14)
+History:
+--------
+Modified by Alessandro Ranellucci (2011-10-14)
to make it compatible with Blender 2.59
and with modern 5D GCODE
+Modified by Winter Guerra (XtremD) on February 16th, 2012
+to make the script compatable with stock Makerbot GCode files
+and grab all nozzle extrusion information from Skeinforge's machine output
+WARNING: This script no longer works with stock 5D GCode! (Can somebody please integrate the two versions together?)
+A big shout-out goes to my friend Jon Spyreas for helping me block-out the maths needed in the "addArc" subroutine
+Thanks a million dude!
+Github branch link: https://github.com/xtremd/blender-gcode-reader
-simon kirkby
-tigger@interthingy.com
-Instructions
+Original developer:
+-------------------
+Simon Kirkby
+tigger@interthingy.com
-get latest blender
+Instructions:
+-------------
+1. Get latest version of Blender here: http://www.blender.org/download/get-blender/
-http://www.blender.org/download/get-256-beta/
+2. Open Blender
-open blender
-Select
+3. Navigate to:
File Menu
- User Preferences CTL-ALT-U
+ User Preferences (CTL-ALT-U)
Select The Add-Ons Tab
- Press the Install Add-On Button ( down the bottom )
-
-If you want to keep it click to Save As Default
-
-Now there should be a menu item of
-File
- Import
- Reprap GCode (.gcode)
+ Press the Install Add-On Button ( down the bottom )
+ Select the python script in the file browser
+ CLick the "Enable Add-on" checkbox to the right of the Add-on slot
+ Click "Save As Default" if you want the Add-on to always be available
+4. Import your GCode file for visualization: File-> Import -> Gcode
+ Select a file and watch the console for progress. The import process is VERY CPU intensive and may take a long time.
+ Having a computer with lots of RAM might help speed up the process considerably.
-Select a file , watch the console for progress.
-
-Bask in the glory of your awesome small plastic thing.
+5. Bask in the glory of your awesome small plastic thing.
Simon
-
View
@@ -21,13 +21,13 @@
import bpy
bl_info = {
- 'name': 'Import GCode for FDM .gcode',
+ 'name': 'Import GCode from Makerbot or Reprap',
'author': 'Simon Kirkby',
- 'version': (0,0,4),
+ 'version': (0,0,5),
'blender': (2, 5, 6),
'api': 32738,
'location': 'File > Import-Export > Gcode',
- 'description': 'Import and visualize gcode files for Makerbot printers (.gcode)',
+ 'description': 'Import and visualize gcode files generated for Makerbot printers (.gcode)',
"wiki_url": "",
"tracker_url": "",
'category': 'Import-Export'}
@@ -49,7 +49,11 @@
# Modified by Winter Guerra (XtremD) on February 16th, 2012
# to make the script compatable with stock Makerbot GCode files
# and grab all nozzle extrusion information from Skeinforge's machine output
-# WARNING: This script no longer works with stock 5D GCode! (Would somebody please integrate the two versions together?)
+# WARNING: This script no longer works with stock 5D GCode! (Can somebody please integrate the two versions together?)
+
+# A big shout-out goes to my friend Jon Spyreas for helping me block-out the maths needed in the "addArc" subroutine
+# Thanks a million dude!
+# Github branch link: https://github.com/xtremd/blender-gcode-reader
import string,os
import bpy
@@ -200,8 +204,13 @@ def create_poly(verts,counter):
def addArc(Verts):
#Takes the verts for a polyline and then adds verts on either side of the original verts to create a sort of 'arc'
#Should help prevent the polyline from doing stupid things like kinking or twisting
+
+ # A big shout-out goes to my friend Jon Spyreas for helping me block-out the maths needed in this subroutine
+ # Thanks a million dude!
+
vertArray = []
+ #Take the list of verts to process
for index, vert in enumerate(Verts):
#Place first vert into list
vertArray.append(vert)
@@ -213,10 +222,8 @@ def addArc(Verts):
#Peek at the next vert
peekVert = Verts[index+1]
- #perhaps the format is Y,X,Z
- #x=0, y=1, z=2
-
- distance = 0.05
+ #Add arcpoints this far apart (in mm) on either side of the polyline point grabbed from the GCode file
+ distance = 0.05
if((peekVert[0]-vert[0]) == 0):
#interpolated verts will be straight along the y axis
@@ -227,62 +234,61 @@ def addArc(Verts):
else:
#Calculate slope (Rise over run)
slope = (peekVert[1]-vert[1])/(peekVert[0]-vert[0])
-
+ #Get angle relative to X axis
radians = math.atan(slope) #Outputs radians
+ #Calculate the x and y offsets
xOffset = math.cos(radians)*distance
-
yOffset = math.sin(radians)*distance
+ #Make sure that the offsets are positive (this makes for easier arithmetic logic)
+ xOffset = math.fabs(xOffset)
+ yOffset = math.fabs(yOffset)
+
+ #Init arcpoints
arcPoint1 = []
arcPoint2 = []
#if the starting loc is smaller than the ending loc
- #
+ #We want the points to gradually increase
if (vert[0] < peekVert[0]):
arcPoint1.append(vert[0]+xOffset)
arcPoint2.append(peekVert[0]-xOffset)
else:
+ #gradually decrease
arcPoint1.append(vert[0]-xOffset)
arcPoint2.append(peekVert[0]+xOffset)
if (vert[1] < peekVert[1]):
+ #gradually increase
arcPoint1.append(vert[1]+yOffset)
arcPoint2.append(peekVert[1]-yOffset)
else:
+ #gradually decrease
arcPoint1.append(vert[1]-yOffset)
arcPoint2.append(peekVert[1]+yOffset)
+ #Add the current Z position to the new arcpoints
arcPoint1.append(vert[2])
arcPoint2.append(peekVert[2])
-
-
- #arcPoint1 = [vert[0]+xOffset, vert[1]+yOffset, vert[2]]
-
- #arcPoint2 = [peekVert[0]-xOffset, peekVert[1]-yOffset, peekVert[2]]
-
- #xOffset = math.sqrt(math.pow(distance,2) / (math.pow(slope,2) + 1))
-
- #yOffset = math.sqrt((math.pow(slope,2) * math.pow(distance,2))/(math.pow(slope,2) + 1))
-
- #arcPoint1 = [vert[0]+xOffset, vert[1]+yOffset, vert[2]]
-
- #arcPoint2 = [peekVert[0]-xOffset, peekVert[1]-yOffset, peekVert[2]]
-
- print('#######Interpolating points########')
+
- print('Point1 X'+str(vert[0])+' Y'+str(vert[1])+' Z'+str(vert[2]))
+# ######DEBUG OUTPUT CODE######
+# print('#######Interpolating points########')
+#
+# print('Point1 X'+str(vert[0])+' Y'+str(vert[1])+' Z'+str(vert[2]))
+#
+# print('Point2 X'+str(arcPoint1[0])+' Y'+str(arcPoint1[1])+' Z'+str(arcPoint1[2]))
+#
+# print('Point3 X'+str(arcPoint2[0])+' Y'+str(arcPoint2[1])+' Z'+str(arcPoint2[2]))
+#
+# print('Point4 X'+str(peekVert[0])+' Y'+str(peekVert[1])+' Z'+str(peekVert[2]))
+#
+# print('xOffset'+str(xOffset)+' yOffset'+str(yOffset))
+#
+# print('#######Done interpolating points########')
- print('Point2 X'+str(arcPoint1[0])+' Y'+str(arcPoint1[1])+' Z'+str(arcPoint1[2]))
-
- print('Point3 X'+str(arcPoint2[0])+' Y'+str(arcPoint2[1])+' Z'+str(arcPoint2[2]))
-
- print('Point4 X'+str(peekVert[0])+' Y'+str(peekVert[1])+' Z'+str(peekVert[2]))
-
- print('xOffset'+str(xOffset)+' yOffset'+str(yOffset))
-
- print('#######Done interpolating points########')
-
+ #Add the arcpoints to the vert list
vertArray.append(arcPoint1)
vertArray.append(arcPoint2)

0 comments on commit 7610fd5

Please sign in to comment.