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

How to modify Default Layer Geometry Ruby

Scheduled Pinned Locked Moved Developers' Forum
4 Posts 2 Posters 874 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.
  • S Offline
    sorgesu
    last edited by 17 Dec 2008, 22:39

    I wanted to have an alternative version of this ruby script that defaults everything to a layer1 which I created.
    I altered the script so all references ( and the ruby file name) are changed to "layer1" instead of "layer" but I cannot actually figure out how to set the appropriate variable to actually do that.
    I am not a ruby programmer so I don't know anything.
    It looks to me that this bit :"layer=nil" is just keeping the layer that components and groups are associated with stay the same as is.
    So, what do I change please. Many thanks.
    This is TIG's script below with my changes:

    =begin

    Copyright 2008, TIG (c)
    Permission to use, copy, modify, and distribute this software for any
    purpose, and currently without fee, is hereby granted, provided that
    this text and the above copyright (c) notice appear in all copies.
    This software is provided "as is" and without any express or implied
    warranties, including, without limitation, the implied warranties of
    merchantability and fitness for a particular purpose.

    Name: default_layer1_geometry.rb
    Description: Defaults all layers for all selected geometry to layer1 ( susan sorger December 2008).
    Groups and Instances are not changed
    BUT their contents are zeroed
    Author: TIG
    Usage: 1. Select one of more entities.
    2. Activate the script from the Plugins Menu
    History: 1.0 20080310 First issue.
    =end
    #-----------------------------------------------------------------------------
    require 'sketchup.rb'
    class DefaultLayer1Geometry
    def to_default(entity)
    entity.definition.entities.each{|e|to_default(e)}if entity.typename=="ComponentInstance"
    entity.entities.each{|e|to_default(e)}if entity.typename=="Group"
    entity.layer=nil if entity.typename!="ComponentInstance" and entity.typename!="Group"
    ### only processes non-group or compo-def layers
    end#def to_default
    def process()
    Sketchup.active_model.selection.each{|e|to_default(e)}
    end#def process
    end#class

    def default_layer1_geometry
    if not Sketchup.active_model.selection[0]
    UI.messagebox("Default Layer1 Geometry:\nSelect Objects BEFORE Running.")
    return nil
    end#if
    Sketchup.active_model.start_operation("Default Layer1 Geometry")
    DefaultLayer1Geometry.new.process
    Sketchup.active_model.commit_operation
    end#def
    #-----------------------------------------------------------------------
    is_this_file=File.basename(FILE)
    if not file_loaded?(is_this_file)
    UI.menu("Plugins").add_item("Default Layer1 Geometry") {default_layer1_geometry}
    end#if
    #-----------------------------------------------------------------------
    file_loaded(is_this_file)

    Susan Sorger
    Former Seller Hand Rendered Entourage
    Former Canadian Authorized Training Centre, SketchUp

    1 Reply Last reply Reply Quote 0
    • S Offline
      sorgesu
      last edited by 18 Dec 2008, 17:41

      Oh that's amazing. Thanks so so much!

      Susan Sorger
      Former Seller Hand Rendered Entourage
      Former Canadian Authorized Training Centre, SketchUp

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 18 Dec 2008, 19:19

        See:

        entity.layer=nil

        Because 'nil' == "layer0" (or whatever the default layer might be called in another language)

        To set things to "layer1" you use...

        entity.layer="layer1"

        This assumes that 'layer1' already exists... if you want to make sure that it does first then add this line early on in the script...

        Sketchup.active_model.layers.add("layer1")

        .

        TIG

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 18 Dec 2008, 19:22

          ¡ No problema !

          Ask and ye shalt receive...

          Seasons greetings...

          TIG

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

          Advertisement