• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Ruby Script question re soften certain lines only

Scheduled Pinned Locked Moved Plugins
6 Posts 2 Posters 868 Views
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.
  • P Offline
    pmolsen
    last edited by 11 Mar 2010, 10:00

    How hard would it be to write a Ruby Script that made all vertical lines in a model soft and smooth please?

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 11 Mar 2010, 10:32

      Easy.

      
      model = Sketchup.active_model
      
      model.entities.each { |e|
      	if e.is_a?(Sketchup;;Edge) && e.line[1].parallel?(Z_AXIS)
      		e.soft = true
      		e.smooth = true
      	end
      }
      model.definitions.each { |d|
      	if e.is_a?(Sketchup;;Edge) && e.line[1].parallel?(Z_AXIS)
      		e.soft = true
      		e.smooth = true
      	end
      }
      
      

      (Sorry - don't have time to wrap it up in menu system atm)

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • P Offline
        pmolsen
        last edited by 11 Mar 2010, 11:31

        Hey, thanks a lot for that quick response.

        Actually what I should really have asked is how do I select all vertical lines. Then I can do whatever I want with them.

        1 Reply Last reply Reply Quote 0
        • P Offline
          pmolsen
          last edited by 11 Mar 2010, 12:11

          Tried to finish it off but getting syntax error on the last line. Never created one before. Any ideas please? File is called softenv.rb and is in the plugins folder:

          Soften all vertical lines in a model

          require 'sketchup.rb'

          def soften_vert

          model = Sketchup.active_model

          model.entities.each { |e|
          if e.is_a?(Sketchup::Edge) && e.line[1].parallel?(Z_AXIS)
          e.soft = true
          e.smooth = true
          end
          }
          model.definitions.each { |d|
          if e.is_a?(Sketchup::Edge) && e.line[1].parallel?(Z_AXIS)
          e.soft = true
          e.smooth = true
          end
          }

          if( not file_loaded?("softenv.rb") )
          add_separator_to_menu("Plugins")
          UI.menu("Plugins").add_item("Soften vertical lines") { soften_vert }

          end

          file_loaded("softenv.rb")

          1 Reply Last reply Reply Quote 0
          • P Offline
            pmolsen
            last edited by 11 Mar 2010, 12:18

            Ok, I think I was missing an "end" on the last if statement. Fixed that and now get no syntax errors but the option does not appear on the Plugins menu when I restart SU...

            1 Reply Last reply Reply Quote 0
            • P Offline
              pmolsen
              last edited by 11 Mar 2010, 12:41

              Shuffled things around a bit by copying other scripts and got the menu item to appear. Not sure how. But when I select the option nothing happens:

              Soften all vertical lines in a model

              require 'sketchup.rb'

              def abc
              model = Sketchup.active_model

              model.entities.each { |e|
              if e.is_a?(Sketchup::Edge) && e.line[1].parallel?(Z_AXIS)
              e.soft = true
              e.smooth = true
              end
              }
              model.definitions.each { |d|
              if e.is_a?(Sketchup::Edge) && e.line[1].parallel?(Z_AXIS)
              e.soft = true
              e.smooth = true
              end
              }

              end

              name = "softenv.rb"
              unless file_loaded?(name)
              UI.menu("Plugins").add_item("Soften verticals") { abc }
              file_loaded name
              end

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

              Advertisement