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

[REQ] Name Layer from a group existing

Scheduled Pinned Locked Moved Plugins
16 Posts 3 Posters 2.1k 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
    pilou
    last edited by 14 Oct 2009, 00:29

    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
    • T Offline
      TIG Moderator
      last edited by 14 Oct 2009, 11:45

      @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
      • P Offline
        pilou
        last edited by 14 Oct 2009, 14:06

        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
        • P Offline
          pilou
          last edited by 14 Oct 2009, 14:47

          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
          • T Offline
            TIG Moderator
            last edited by 14 Oct 2009, 15:26

            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
            • P Offline
              pilou
              last edited by 14 Oct 2009, 16:19

              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
              • T Offline
                TIG Moderator
                last edited by 14 Oct 2009, 18:37

                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
                • P Offline
                  pilou
                  last edited by 14 Oct 2009, 19:55

                  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 19 Dec 2009, 14:11

                    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
                    • T Offline
                      TIG Moderator
                      last edited by 19 Dec 2009, 16:54

                      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