sketchucation logo sketchucation
    • Login
    ๐Ÿ›ฃ๏ธ Road Profile Builder | Generate roads, curbs and pavements easily Download

    [REQ] Name Layer from a group existing

    Scheduled Pinned Locked Moved Plugins
    16 Posts 3 Posters 2.3k 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.
    • pilouP Offline
      pilou
      last edited by

      Many thanks! ๐Ÿ‘

      Frenchy Pilou
      Is beautiful that please without concept!
      My Little site :)

      1 Reply Last reply Reply Quote 0
      • pilouP Offline
        pilou
        last edited by

        asuming that the file is renamed toto.rb, and working with for groups

        I add this at the end for have the right click Context

        
        if( not file_loaded?("toto.rb") )
          UI.add_context_menu_handler do |menu|
            menu.add_separator if ss[0].class != Sketchup;;Group
            menu.add_item("add Layer name") if ss[0].class != Sketchup;;Group
          end
        end
        file_loaded "toto.rb"
        

        All is always working fine in the Ruby console
        but I have nothing as Menu Contextual on the Right Click when a group is selected โ“

        Ps This Text editor is a little smaller for see a correct Code size's line ๐Ÿ˜’

        Frenchy Pilou
        Is beautiful that please without concept!
        My Little site :)

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          @unknownuser said:

          asuming that the file is renamed toto.rb, and working with for groups

          I add this at the end for have the right click Context

          
          > if( not file_loaded?("toto.rb") )
          >   UI.add_context_menu_handler do |menu|
          >     menu.add_separator if ss[0].class != Sketchup;;Group
          >     menu.add_item("add Layer name") if ss[0].class != Sketchup;;Group
          >   end
          > end
          > file_loaded "toto.rb"
          

          All is always working fine in the Ruby console
          but I have nothing as Menu Contextual on the Right Click when a group is selected โ“

          You also need to give the menu item an action {}

          Ps This Text editor is a little smaller for see a correct Code size's line ๐Ÿ˜’

          should be

          ...class == Sketchup::Group

          Should NOT be

          ...class != Sketchup::Group

          The ! negates it - i.e. "if class is NOT == Group", when you actually want "if class == Group" ! ๐Ÿค“

          TIG

          1 Reply Last reply Reply Quote 0
          • pilouP Offline
            pilou
            last edited by

            After hundred of try ๐Ÿ˜’
            (ruby console works always fine I have no syntax error message)
            but always nothing in the right click panel menu ๐Ÿ˜ณ
            I don't see very well what "action" I must put inside the {} (I had tested some many ๐Ÿ˜„
            Surely trivial but ๐Ÿ’š

            if(not file_loaded?("toto.rb")) 
              UI.add_context_menu_handler do |menu|
                menu.add_separator if ss[0].class == Sketchup;;Group
               menu.add_item("Add Name Layer"){layers.add(name)}if ss[0].class == Sketchup;;Group
              end
            end
            file_loaded "toto.rb"
            

            Frenchy Pilou
            Is beautiful that please without concept!
            My Little site :)

            1 Reply Last reply Reply Quote 0
            • pilouP Offline
              pilou
              last edited by

              Another thing that will be cool :
              put in the same time the object (goup/component) in the the layer created โ˜€

              Frenchy Pilou
              Is beautiful that please without concept!
              My Little site :)

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                If you go back to my earlier example

                def layer_name_from_group_name()...
                is the action to put in the {}
                So at the end of the file that loads layer_name_from_group_name add your context-menu test and run the action...

                TIG

                1 Reply Last reply Reply Quote 0
                • pilouP Offline
                  pilou
                  last edited by

                  hum hum ๐Ÿ˜ณ
                  Seems there is something again missing ๐Ÿ˜ฎ
                  (Console is Ok)

                  right Click context menu always unseen ๐Ÿ˜ณ

                  def layer_name_from_group_name()
                        model=Sketchup.active_model
                        ss=model.selection
                        if ss[0].class != Sketchup;;Group
                          UI.messagebox("Select a Group to Name a Layer after...")
                          return nil
                        end#if
                        name=nil
                        name=ss[0].name
                        if not name or name==""
                          UI.messagebox("Select a NAMED Group to Name a Layer after...")
                          return nil
                        end#if
                        layer_names=[];layers=model.layers
                        layers.each{|layer|layer_names<<layer.name}
                        if layer_names.include?(name)
                          UI.messagebox("A Layer with that Group's Name ["+name+"] already exists...")
                          return nil
                        end#if
                        new_layer=layers.add(name)
                        UI.messagebox("Layer '"+name+"' created.")
                      end#def
                  
                  if(not file_loaded?("layer_name_from_group_name.rb")) 
                    UI.add_context_menu_handler do |menu|
                      menu.add_separator if ss[0].class ==Sketchup;;Group
                     menu.add_item("Add Name Layer"){layer_name_from_group_name()}if ss[0].class==Sketchup;;Group
                    end
                  end
                  file_loaded ("layer_name_from_group_name.rb")
                  

                  Frenchy Pilou
                  Is beautiful that please without concept!
                  My Little site :)

                  1 Reply Last reply Reply Quote 0
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    if(not file_loaded?("layer_name_from_group_name.rb"))
                    ss=Sketchup.active_model.selection
                    UI.add_context_menu_handler do |menu|
                    menu.add_separator if ss[0].class ==Sketchup::Group
                    menu.add_item("Add Name Layer"){layer_name_from_group_name()}if ss[0].class==Sketchup::Group
                    end
                    end

                    The red text is needed to define ss as it was only defined inside the def... ๐Ÿค“

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • pilouP Offline
                      pilou
                      last edited by

                      Yep now that works fine! Many thx! โ˜€ ๐Ÿ‘
                      To do
                      Now second part : move in the same time the object clicked on the layer named

                      For the moment that works for a group or a component ๐Ÿ˜‰
                      Just select a group named or a component with Definition name
                      Right Click and a context menu appears : Add Name Layer from Group
                      or Add Name Layer from Component
                      (object is not moved on this version)

                      If your Right Click is broken you must enter on the ruby Console
                      layer_name_from_group_name or layer_name_from_component_name ๐Ÿ˜‰


                      layer_name_from_group_name.rb


                      layer_name_from_component_name.rb

                      Frenchy Pilou
                      Is beautiful that please without concept!
                      My Little site :)

                      1 Reply Last reply Reply Quote 0
                      • bagateloB Offline
                        bagatelo
                        last edited by

                        Is possible to do the inverse of this situation, like this:

                        Base Group (or components) Name from layer name? If yes, would be fantatisc to my workflow.

                        While the cat's away, the mice will play

                        1 Reply Last reply Reply Quote 0
                        • TIGT Offline
                          TIG Moderator
                          last edited by

                          Pilou - nascent scripter - yours I think... ๐Ÿ˜„

                          Iterate through model.definitions, if defn.group? then add if to a groups array and then iterate through groups and rename each group to match its group.layer.name, keep a list of all group names as you go [start by making a list of the groups' names and then remove old name and add new name as you go groups]. It a group name exists then increment it [tip: name="name#1";name=name.next if groupnames.include?(name)] - several groups could be on one layer and should them get named name#1,name#2,name#3 etc...

                          TIG

                          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