sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Ruby Script question re soften certain lines only

    Scheduled Pinned Locked Moved Plugins
    6 Posts 2 Posters 868 Views 2 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.
    • P Offline
      pmolsen
      last edited by

      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
      • thomthomT Offline
        thomthom
        last edited by

        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

          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

            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

              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

                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
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement