[PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.9

[PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.9

Postby Davidfi1 » Thu Jan 17, 2013 5:11 pm

Hello Guys.
Small step in Plugin Vertion giant leap for 3D-Printer's kind :berserk:

Attached is a 3D-Printer's G-Code Importer AND Exporter.
It will turn Sketchup to a Virtual 3D-Printer :ecstatic:
Fishelzon_GcodeTools0.0.9.rbz


Version 0.0.9
New in Importer:
Will put a Attribute with the value of speed from the imported G-Code in the
"filament" & "MotorMove" components
Change the Z scale of the "filament" component according to the amount of
extruded filament in the imported G-Code
New in Exporter:
Export to the G-Code the Attribute of speed as was imported by the importer.
Export the Extruded length according to the Z scale of the "filament" component

Version 0.0.8
Added to the exporter the ability to connect "unconnected" components
so now if a component is deleted - the exporter will just put a link to the
first component of the disconnected chain

Version 0.0.7
Now we have a G-Code Exporter of the previously imported G-Code in the plugin menu.
So I changed the name to GcodeTools ... (please delete the old one)
The new exporter is a very simple assuming that in the next versions will be
adding all the needed features to make it usable
- so please let me know what need's to be fixed!.

Version 0.0.6
Added Layers - Each New Z level gets it's one layer
- Using the Sketchup Layer it is easy to hide and unhide Layers of the Gcode
Version 0.0.5
Impruvment to speed by making no shadow hidden edjes of the filament


If you just want to help clean up my begginesrs ruby codeing
you can use this test gcode files
Tests.zip


I would like to thenk the guys who helped me allot in the
Developers' Forum at http://sketchucation.com/forums/viewforum.php?f=180
Thank you.

P.S
1) Look at the ruby console to see the progress of the importing - every 1000 lines it prints the line count
2) In the "Entity Info" you can see the line of G Code that is responsiable for the filament pice
3) A move of the motors is also a component with a line inside - so you could hide it by hiding the line inside one of the movements.

My Motivation for writing this Importer:
I am trying to learn about 3D printing while waiting for my printer to arrive.
I was using SketchUp to play with 3D design for many years, so it was natural for me to
make a 3D model with SketchUp - slice it - and see the result.

I made few models, downloaded few from the internet - that was no problem.
Slicing turned out to be much harder.
I tried 3 slicing softwares with different levels of success.
In the process foud out that there are two types of G-Code formats,
and that it is not possible to convert from one type of G-Code to the other.

So I started to write an importer of G-Code for Sketchup.
My intention is that it will be possible to see what the G-Code will look like in a "neutral" environment and will enable the export of G-Code in a "wanted" format

Please follow my work and give any advice you think fit.
Keep in mind it is a work in progress...


Thank you,
David.
3
Last edited by Davidfi1 on Sat Feb 23, 2013 7:28 pm, edited 9 times in total.

Davidfi1 
 

Re: 3D Printers G-Code importer

Postby Whaat » Thu Jan 17, 2013 7:29 pm

I could sure use this. Looking forward to trying it out. Thanks!
0

Whaat 
PluginStore Author
PluginStore Author
 

Re: 3D Printers G-Code importer

Postby sdmitch » Thu Jan 17, 2013 10:50 pm

I find a problem with the Get_Filament_component method. The problem occurs when you run the plugin a second time. The @filamentComp and @HeadMoveComp are not remembered from the first to the second run so @HeadMoveComp is not redefined because of the return executed when @filamentComp is found and redefined.

Here is my re-write

Code: Select all
   def Get_Filament_component
   @filamentComp =Sketchup.active_model.definitions[ "filament" ]
    # if there is no existing component named "filament", make one
    unless @filamentComp
     @nozel = 0.4.mm
     @layerH = 1.mm # the Z axis movements will scale this parameter
     @filamentComp = Sketchup.active_model.definitions.add("filament")
     @pts = [ ORIGIN,
     [-@nozel/2, 0.mm , -@layerH/2],
     [-@nozel/2, 0.mm , -@layerH ],
     [ @nozel/2, 0.mm , -@layerH ],
     [ @nozel/2, 0.mm , -@layerH/2] ]
     @newface = @filamentComp.entities.add_face(@pts)
     @newface.reverse! if @newface.normal.y < 0
     @newface.pushpull(1.mm)
    end
   @HeadMoveComp = Sketchup.active_model.definitions[ "HeadMove" ]
    unless @HeadMoveComp
     @HeadMoveComp = Sketchup.active_model.definitions.add("HeadMove")
     @oldPoint = [0, 0, 0]
     @newPoint = [0, 1.mm, 0]
     @HeadMoveComp.entities.add_line @oldPoint, @newPoint
    end
   end # def Get_Filament_component
0
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch 
PluginStore Author
PluginStore Author
 

Re: 3D Printers G-Code importer

Postby Dan Rathbun » Fri Jan 18, 2013 3:49 am

    In Ruby, everything is an object, and every object has a reference.

    References that begin with a capital letter are constants. Module and Class references (names) are constants that are in title case (without underscore spacing, such as FileImporter).
    Other constants are all capital characters (with underscore spacing, such as ROOT_PATH.)

    Methods are also objects, and the method name is it's reference, which by convention is lower case (with underscore spacing, such as get_filament_component.)

    The Ruby interpreter is designed to work fastest when we follow these conventions.

    :idea:
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      G-Code importer: Options dialog error / Import units

      Postby Dan Rathbun » Fri Jan 18, 2013 4:21 am

      When choosing a file to import... and clicking the "Options..." button (in the import file dialog,) I get an error:

      Error: #<NoMethodError: undefined method `[]' for nil:NilClass>
      C:/Program Files/Google/Google SketchUp 8/Plugins/Fishelzon/GcodeImporterVer0.0.3.rb:262:in `units_dialog'
      C:/Program Files/Google/Google SketchUp 8/Plugins/Fishelzon/GcodeImporterVer0.0.3.rb:102:in `do_options'


      The error occurs on line 262 of the plugin file, viz:
      cu = Sketchup.active_model.options["unitsOptions"]["LengthUnit"]

      Reason: The Sketchup::OptionsManager instance method [] returns a valid Sketchup::OptionsProvider instance object IF the key is valid, otherwise it returns nil (the singleton instance of the NilClass class.)
      Since the key is invalid, nil is returned, and since the NilClass class does not have a [] instance method, the NoMethodError exception is raised.

      The valid key name to get a reference to the units options provider is "UnitsOptions"



      NOW... there are ONLY TWO possible import units in a Gcode file.. inches (G20) and mm (G21), so can the plugin set mm as default, and then recognize the Gcodes G20 and G21, to change the import units "on-the-fly" as needed ?

      This would actually make the import file options dialog unnecessary (at least when it comes to setting import units.)

      :idea:
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        Re: 3D Printers G-Code importer

        Postby Dan Rathbun » Fri Jan 18, 2013 8:58 am

          Key for saving defaults:

          It is preferable to use underscore "_" instead of spaces, and to prepend "Plugin_" to the key, thus:

          "Plugin_Fishelzon_GcodeImporter"
          0
            I'm not here much anymore. But a PM will fire email notifications.
            User avatar
            Dan Rathbun 
            PluginStore Author
            PluginStore Author
             

            Re: 3D Printers G-Code importer

            Postby Davidfi1 » Fri Jan 18, 2013 9:17 pm

            OK Guys - Thank you.
            I fixed the code according to your suggestions in the next version
            I added a "last version" load to the loader and updated the version number.
            Waiting for yor remarks befor moving on.

            I am thinking about how to implement a "G-Code exporter"
            I need to figure out a way to keep the unused G-Code lines.
            The adding of these lines will enable the exporter to put these lines
            back to the exported G-Code.
            0

            Davidfi1 
             

            Re: [PlugIn] 3D Printers G-Code importer Ver0.0.4

            Postby Didier Bur » Mon Jan 21, 2013 10:47 am

            Hi,
            Call me stupid but how to launch the script ??
            0
            Didier Bur
            Ecole Nationale Supérieure d'Architecture de Nancy (F)
            http://rld.crai.archi.fr/rubylibrarydepot/
            User avatar
            Didier Bur 
             

            Re: [PlugIn] 3D Printers G-Code importer Ver0.0.4

            Postby thomthom » Mon Jan 21, 2013 11:14 am

            Didier Bur wrote:Hi,
            Call me stupid but how to launch the script ??

            It's an importer, you find in the list of import formats. File > Import and in the file dialogue you pick the fileformat for G code.
            0
            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund
            User avatar
            thomthom 
            PluginStore Author
            PluginStore Author
             

            Re: [PlugIn] 3D Printers G-Code importer Ver0.0.5

            Postby Davidfi1 » Thu Jan 24, 2013 8:15 am

            Uploaded vertion 0.0.5.
            Include impruvment to speed and rendering

            Please let me know if you like it :-)
            0

            Davidfi1 
             

            Re: [PlugIn] 3D Printers G-Code importer Ver0.0.5

            Postby Dan Rathbun » Thu Jan 24, 2013 11:35 am

            Line 117:
            if (Sketchup.version_number < 7)

            should be:
            if (Sketchup.version.to_i < 7)

            Line 135:
            Code: Select all
            # wait forever
            while 1==1 do
            end # while 1

            That is dangerous! It could lock up SketchUp if an error occurs, causing file handles to remain open.

            Use a continue messagebox instead.

            And you should return a numeric error code instead of 0 when an exception occurs.
            0
              I'm not here much anymore. But a PM will fire email notifications.
              User avatar
              Dan Rathbun 
              PluginStore Author
              PluginStore Author
               

              Re: [PlugIn] 3D Printers G-Code importer Ver0.0.5

              Postby Dan Rathbun » Thu Jan 24, 2013 11:43 am

              Davidfi1 wrote:Uploaded vertion 0.0.5.
              Include improvment to speed and rendering

              Just so you know...

              The native Ruby Console, is not actually a "true console interface".
              It is really a dialog with a non-editable multi-line text control.
              Writing output to the text control is VERY slow, and gets SLOWER the more that is written.

              (*) Write only what you NEED to.
              OR ...
              Perhaps write output to a log file instead, and after the import, display the log file's text in a Webdialog frame. (The browser can display plain text files.)
              0
                I'm not here much anymore. But a PM will fire email notifications.
                User avatar
                Dan Rathbun 
                PluginStore Author
                PluginStore Author
                 

                Re: [PlugIn] 3D Printers G-Code importer Ver0.0.5

                Postby Davidfi1 » Thu Jan 24, 2013 8:24 pm

                Dan.
                Thank you, you are very helpfull.
                I don't really know what to do with these errors in the G-Code I am getting.
                It is not even correct to say they are errors at all.
                I use the ruby console as a very simple "information console"
                There is nothing to do with these "errors" just know about them...

                If somone don't want to see these messages he could just close the console.

                In the following versions I will not open the ruby console at all.

                Thank you again.
                David.
                0

                Davidfi1 
                 

                Re: [PlugIn] 3D Printers G-Code importer Ver0.0.5

                Postby Davidfi1 » Thu Jan 24, 2013 8:29 pm

                Dan Rathbun wrote:Line 117:
                Line 135:
                Code: Select all
                # wait forever
                while 1==1 do
                end # while 1

                That is dangerous! It could lock up SketchUp if an error occurs, causing file handles to remain open.


                will do.
                Thank you.
                0

                Davidfi1 
                 

                Re: [PlugIn] 3D Printers G-Code importer Ver0.0.6

                Postby Davidfi1 » Sun Jan 27, 2013 2:46 pm

                New Version 0.0.6 posted
                Thank you.
                0

                Davidfi1 
                 

                Re: [PlugIn] 3D Printers G-Code importer Ver0.0.6

                Postby antoninoion » Sat Feb 02, 2013 4:10 am

                I'm getting the following error in the ruby console every time I start SU and it doesn’t show the G-code file type in the import file types list:

                GcodeImporterVer0.0.6.rb:38: warning: Object#type is deprecated; use Object#class

                I installed the plugin through the "Preferences/Extensions/Install Extension" option. I have SU V8.0.16845 for Mac, any idea on what I should do?

                Thanks
                Antonio
                0

                antoninoion 
                 

                Re: [PlugIn] 3D Printers G-Code importer Ver0.0.6

                Postby Davidfi1 » Sat Feb 02, 2013 9:51 pm

                antoninoion wrote:I'm getting the following error in the ruby console every time I start SU and it doesn’t show the G-code file type in the import file types list:

                GcodeImporterVer0.0.6.rb:38: warning: Object#type is deprecated; use Object#class

                I installed the plugin through the "Preferences/Extensions/Install Extension" option. I have SU V8.0.16845 for Mac, any idea on what I should do?

                Thanks
                Antonio


                I found the problem - fixing it soon.
                change line 38 from:
                if @ent.type == Sketchup::Edge
                to:
                if @ent.class == Sketchup::Edge

                But wait for more testing - I will post a fix soon
                Thank you.
                0

                Davidfi1 
                 

                Re: [PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.7

                Postby Davidfi1 » Sat Feb 09, 2013 8:13 pm

                Version 0.0.7
                Now we have a G-Code Exporter of the previously imported G-Code in the plugin menu.
                So I changed the name to GcodeTools ... (please delete the old one)
                The new exporter is a very simple assuming that in the next versions will be
                adding all the needed features to make it usable
                - so please let me know what need's to be fixed!.
                0

                Davidfi1 
                 

                Re: [PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.8

                Postby Davidfi1 » Thu Feb 14, 2013 11:14 pm

                Version 0.0.8
                Added to the exporter the ability to connect "unconnected" components
                so now if a component is deleted - the exporter will just put a link to the
                first component of the disconnected chain
                0

                Davidfi1 
                 

                Re: [PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.8

                Postby Davidfi1 » Sat Feb 23, 2013 7:27 pm

                Version 0.0.9
                New in Importer:
                Will put a Attribute with the value of speed from the imported G-Code in the
                "filament" & "MotorMove" components
                Change the Z scale of the "filament" component according to the amount of
                extruded filament in the imported G-Code
                New in Exporter:
                Export to the G-Code the Attribute of speed as was imported by the importer.
                Export the Extruded length according to the Z scale of the "filament" component
                0

                Davidfi1 
                 

                Re: [PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.9

                Postby Davidfi1 » Sun Mar 03, 2013 6:37 pm

                What should the next feature be?
                If you have an idea, I will be very happy to try implementing it.
                0

                Davidfi1 
                 

                Re: [PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.9

                Postby Jim » Sun Mar 03, 2013 6:41 pm

                Davidfi1 wrote:What should the next feature be?
                If you have an idea, I will be very happy to try implementing it.


                Animate a model of a cnc machine from the gcode.
                0
                Hi

                Jim 
                Global Moderator
                 

                Re: [PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.9

                Postby Davidfi1 » Thu Mar 07, 2013 9:03 pm

                Jim wrote:
                Davidfi1 wrote:What should the next feature be?
                If you have an idea, I will be very happy to try implementing it.


                Animate a model of a cnc machine from the gcode.


                Did you try to import CNC G-Code?
                Can you explain what was the problem?
                Do you have an idea how it should work if it was working correctly?
                0

                Davidfi1 
                 

                Re: [PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.9

                Postby dooseyboy » Thu Jul 11, 2013 6:41 am

                i have attempted this plugin in 2013, about to try it in 8 pro.
                thought i should bring this little web app that i found recently.
                it is a gcode viewer and i was hoping to use it to view the gcode i exported from sketchup in it but it doesn't seem to be working from being exported in 2013.
                http://jherrm.github.io/gcode-viewer/

                neither of the gcode files i exported from regular sketchup files worked in the simulator. but i am keen to use this addon to use the simulation app
                0

                dooseyboy 
                 

                Re: [PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.9

                Postby zurits » Fri Sep 27, 2013 11:43 pm

                Does not work for me either; Sketchup 2013 Win7x86, thanks for for the code.
                0

                zurits 
                 

                Re: [PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.9

                Postby mkultra » Sun May 25, 2014 4:32 pm

                2014 load fails...
                2014/SketchUp/Plugins/Fishelzon/GcodeImporterVer0.0.8.rb:38: formal argument cannot be an instance variable
                @filamentComp.entities.each { |@ent|

                ^
                C:/Users/Cheryl/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon/GcodeImporterVer0.0.8.rb:163: formal argument cannot be an instance variable
                IO.foreach(filename) do |@line|

                ^
                C:/Users/Cheryl/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon/GcodeImporterVer0.0.8.rb:183: formal argument cannot be an instance variable
                @params.map {|@var|

                ^>
                C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/extensions.rb:197:in `require'
                C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/extensions.rb:197:in `load'
                C:/Users/Cheryl/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon_GcodeTools_ext.rb:40:in `register_extension'
                C:/Users/Cheryl/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon_GcodeTools_ext.rb:40:in `loadLastVer'
                C:/Users/Cheryl/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon_GcodeTools_ext.rb:47:in `<module:Fishelzon>'
                C:/Users/Cheryl/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon_GcodeTools_ext.rb:11:in `<top (required)>'
                0

                mkultra 
                 

                Re: [PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.9

                Postby mctabish » Sat Feb 14, 2015 11:28 am

                I am also failing to load on start up. I get:
                Error Loading File C:/Users/Pop/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon/GcodeImporterVer0.0.8.rb
                Error: #<SyntaxError: C:/Users/Pop/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon/GcodeImporterVer0.0.8.rb:38: formal argument cannot be an instance variable
                @filamentComp.entities.each { |@ent|

                ^
                C:/Users/Pop/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon/GcodeImporterVer0.0.8.rb:163: formal argument cannot be an instance variable
                IO.foreach(filename) do |@line|

                ^
                C:/Users/Pop/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon/GcodeImporterVer0.0.8.rb:183: formal argument cannot be an instance variable
                @params.map {|@var|

                ^>
                C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/extensions.rb:197:in `require'
                C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/extensions.rb:197:in `load'
                C:/Users/Pop/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon_GcodeTools_ext.rb:40:in `register_extension'
                C:/Users/Pop/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon_GcodeTools_ext.rb:40:in `loadLastVer'
                C:/Users/Pop/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon_GcodeTools_ext.rb:47:in `<module:Fishelzon>'
                C:/Users/Pop/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/Fishelzon_GcodeTools_ext.rb:11:in `<top (required)>'


                Any resolution?
                sketchup 2014 Win 7 x64

                Thanks
                Bruce
                0

                mctabish 
                 

                Re: [PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.9

                Postby Dan Rathbun » Sat Feb 21, 2015 11:59 pm

                Try making the following changes. untested

                (Ruby v 2.0 will not allow direct references to instance variables in the block parameter list.)

                Line 38:
                @filamentComp.entities.each { |ent| @ent = ent

                Line 163:
                IO.foreach(filename) do |line| @line = line

                Line 183:
                @params.map {|var| @var = var
                0
                  I'm not here much anymore. But a PM will fire email notifications.
                  User avatar
                  Dan Rathbun 
                  PluginStore Author
                  PluginStore Author
                   

                  Re: [PlugIn] 3D Printers G-Code importer/Exporter Ver0.0.9

                  Postby sparkdaddychad » Fri Apr 17, 2015 2:06 pm

                  I know this is a couple of years old but the plugin does not appear to work with latest version of SKetchup Make. Any chance there is an updated version of this plugin anywhere? Would really love to import Gcode files into SKetchup.

                  Thanks!!
                  0

                  sparkdaddychad 
                   

                  SketchUcation One-Liner Adverts

                  by Ad Machine » 5 minutes ago



                  Ad Machine 
                  Robot
                   



                   

                  Return to Plugins

                  Who is online

                  Users browsing this forum: No registered users and 16 guests

                  Visit our sponsors: