• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Rusty with Ruby. Import help needed.

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 3 Posters 453 Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    jpjapers
    last edited by 4 Nov 2014, 20:05

    Hi, I used to dabble in a bit of ruby scripting about five years ago but its all disappeared from my memory and im stuck on something im sure is incredibly easy.
    I basically want to add a button the the maon toolbar that simply runs the built in DWG import (Pro obviously) but the documentation on the sketchup site doesnt seem as comprehensive as it once was.
    Can anyone help?

    Id also like to add a button that saves only sketchup 8 files. Its simple but the code snippets i have gathered from my previous scripts dont seem to work properly anymore and i cant figure out for the life of me why my code isnt running when the buttons are pressed.

    Thanks
    Jack

    1 Reply Last reply Reply Quote 0
    • D Offline
      driven
      last edited by 4 Nov 2014, 20:53

      fill in your profile so we know what your using...
      post your code in the developers forum for more advice...

      there have been a lot of changes to ruby in the last 4 versions of SU...
      john

      learn from the mistakes of others, you may not live long enough to make them all yourself...

      1 Reply Last reply Reply Quote 0
      • J Offline
        jpjapers
        last edited by 4 Nov 2014, 21:00

        Sorry about that. Ive filled in the profile. Ive fixed the code running issue now but i cant seem to find an answer on the web for my other query. I know its completely possible to force a dialog with only a sketchup v8 file as the sole save option or a DWG import as the only option but the snippets in the documentation give little help unless you really know what youre doing.

        1 Reply Last reply Reply Quote 0
        • D Offline
          driven
          last edited by 4 Nov 2014, 21:53

          this is the API code for import

           model = Sketchup.active_model
           show_summary = true
           status = model.import "filename", show_summary
          

          if you replace filename with a dwg file it will import it, and show a summary...

          if you want to selectr a file first than you need

          chosen_dwg = UI.openpanel("Open CAD File", "c;/", "DXF|*.dxf|DWG|*.dwg||")
          

          if you wan to combine the two, you do something like...

          
          chosen_dwg = UI.openpanel("Open CAD File", "~/Documents", "DXF|*.dxf|DWG|*.dwg||")
           model = Sketchup.active_model
           show_summary = true
           status = model.import chosen_dwg, show_summary
          

          now if you want to use that on a button...

          have a look at making a toolbar and wrap this as your command...

          john

          learn from the mistakes of others, you may not live long enough to make them all yourself...

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 4 Nov 2014, 22:19

            You'll need to make your own button images 16x16 and 24x24

            The code will be near to:

            if Sketchup.version.to_i > 13 # no save as before v14 !
            
              save_as_v8_cmd = UI;;Command.new("Save As v8") {
              
                model = Sketchup.active_model
                path = model.path
                
                if path.empty?
            
                  if RUBY_PLATFORM !~ /(darwin)/i # MS Windows
                    path = UI.savepanel(
                      "Save Model As v8 skp...",
                      "*.skp",
                      "SketchUp Files (*.skp)|*.skp;||"
                    )
                  else # Mac
                    path = UI.savepanel(
                      "Save Model As v8 skp...",
                      "*.skp"
                    )
                  end
            
                  unless path.nil? # nil if dialog cancelled
                    model.save( path, Sketchup;;Model;;VERSION_8 )
                  end
            
                else # use current filepath
                
                  model.save( "", Sketchup;;Model;;VERSION_8 )
            
                end
            
              }
              
              save_as_v8_cmd.small_icon= "your_icon_name_16.png"
              save_as_v8_cmd.large_icon= "your_icon_name_24.png"
              
              UI.menu("File").add_item save_as_v8_cmd
              
              # assume you've created a toolbar ref'd as my_toolbar;
              my_toolbar.add_item save_as_v8_cmd
            
            end
            

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            1 / 1
            • First post
              1/5
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement