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

    Edit group by ruby-code instead of a right mouse click

    Scheduled Pinned Locked Moved Developers' Forum
    16 Posts 6 Posters 3.0k Views 6 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.
    • A Offline
      Andreas
      last edited by

      Hi!

      Is it possible to edit a group by ruby-code instead of a right mouse click in contextmenu.

      Thanks...

      Andreas

      With best regards from Germany

      Andreas

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        Open a Group of Component - no. ๐Ÿ˜ž

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

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

          To 'edit' a group use group.entities
          You add-to or erase-from the set, or transform some of its entities etc - just as you would any other entities set... i.e. like model.entities etc... and the changes occur inside the group ๐Ÿ˜•

          You could simulate the 'edit group' command - set a shortcut e.g. ' Shift+Ctrl+Alt+G' to the 'edit group' menu item and then use ' win32ole.so' to run the key-stroke(s) to make that group active and then edit its entities to make your selection and then close the group using close_active... BUT it's pretty convoluted and would be PC dependent AND why do it? ๐Ÿ˜’

          TIG

          1 Reply Last reply Reply Quote 0
          • A Offline
            Andreas
            last edited by

            I would like to make a cutout in a wall (group) to insert a door or window.

            Andreas

            With best regards from Germany

            Andreas

            1 Reply Last reply Reply Quote 0
            • M Offline
              MartinRinehart
              last edited by

              @andreas said:

              I would like to make a cutout in a wall (group) to insert a door or window.

              Andreas

              That is definitely possible. The group has an Entities collection.

              Add a Rectangle to the groups Entities. Pushpull its face to the opposite side of the wall. Delete the face.

              Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by

                You work directly with the Group's entities, just like you would the model's entities. Having an editing context is a useful concept for people when modeling, but is not necessary when editing geometry using the Ruby API.

                This sample shows how you might get to a Group's entities.

                
                all_groups = Sketchup.active_model.entities.find_all{|e| e.class == Sketchup;;Group}
                my_group = all_groups.select{|g| g.name == "My Group"}
                my_entities = group.entities
                my_entities.add_face(...)
                
                

                Hi

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

                  When you add geometry it goes into an entities collection.
                  You have:-
                  model.entities = everything that's placed in the model
                  group.entities = everything that's placed in the group
                  definition.entities = everything that's placed in the component's definition
                  there is also
                  model.active_entities = everything that is placed in the current context - so this could be equal to the model.entities, OR if the user starts your tool whilst he is editing a group it would become the group.entities automatically.
                  Example - this code snippet adds a new [empty] group into the model, then it adds a line 1" tall into that group, it then adds a second [empty] group inside the first group and adds a line 10" long at the first line's end but in that new group.

                  model=Sketchup.active_model
                  group1=model.entities.add_group()
                  group1.entities.add_line([0,0,0],[0,0,1])
                  group2=group1.entities.add_group()
                  group2.entities.add_line([0,0,1],[10,0,1])
                  
                  

                  Run it [copy/paste the into a file in Plugins and use load"file.txt" in the Ruby Console] and see the results...
                  Hopefully this is helpful... ๐Ÿค“

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    Andreas
                    last edited by

                    @jim said:

                    You work directly with the Group's entities, just like you would the model's entities. Having an editing context is a useful concept for people when modeling, but is not necessary when editing geometry using the Ruby API.

                    This sample shows how you might get to a Group's entities.

                    
                    > all_groups = Sketchup.active_model.entities.find_all{|e| e.class == Sketchup;;Group}
                    > my_group = all_groups.select{|g| g.name == "My Group"}
                    > my_entities = group.entities
                    > my_entities.add_face(...)
                    > 
                    

                    my_entities = group.entities donยดt works.
                    I think it must be:
                    my_entities = my_group.entities
                    but that donยดt works too.

                    Can someone help me?

                    Thanks
                    Andreas

                    With best regards from Germany

                    Andreas

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

                      You first get a reference to the required group, then one to its entities, and then do stuff in that entities collection...
                      To see if each step is working add puts my_group etc after it's defined it should then print up the group-id in the ruby console or 'nil'!
                      It should be my_group in your code if you want to work inside that group.
                      Do you have a group with that specific name ?
                      Obviously the .add_face(...) needs expanding so the ... is a list of at least three coplanar points!!
                      It WILL work...
                      Why not test it using my method that adds a new group to model.active_entities with
                      my_group=model.active_entities.add_group()
                      NOW you are sure to have my_group... now add the face to my_group.entities

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • A Offline
                        Andreas
                        last edited by

                        @tig said:

                        You first get a reference to the required group, then one to its entities, and then do stuff in that entities collection...
                        To see if each step is working add puts my_group etc after it's defined it should then print up the group-id in the ruby console or 'nil'!
                        It should be my_group in your code if you want to work inside that group.
                        Do you have a group with that specific name ?
                        Obviously the .add_face(...) needs expanding so the ... is a list of at least three coplanar points!!
                        It WILL work...
                        Why not test it using my method that adds a new group to model.active_entities with
                        my_group=model.active_entities.add_group()
                        NOW you are sure to have my_group... now add the face to my_group.entities

                        Hello TIG,

                        I need access to an existing group to add a face. I would like to make a cutout in a wall (existing group) to insert a door or window.

                        Andreas

                        With best regards from Germany

                        Andreas

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

                          I only suggested the making a new group method so that you might understand how it works in a test... ๐Ÿ˜’
                          Did you try my 'puts' methods to report if you are actually getting the 'group' etc using your methods ?
                          Assuming you corrected the group >> my_group it should work IF the names match... ๐Ÿ˜•

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • A Offline
                            Andreas
                            last edited by

                            @tig said:

                            ...Assuming you corrected the group >> my_group it should work IF the names match... ๐Ÿ˜•

                            It does not work.

                            all_groups = Sketchup.active_model.entities.find_all{|e| e.class == Sketchup;;Group}
                            my_group = all_groups.select{|g| g.name == "G1"}
                            my_entities = my_group.entities
                            
                            

                            The result is:

                            all_groups = Sketchup.active_model.entities.find_all{|e| e.class == Sketchup::Group}
                            finds several groups
                            => [#Sketchup::Group:0x80db350, #Sketchup::Group:0x80db320, #Sketchup::Group:0x80db2f0, #Sketchup::Group:0x80e6768]

                            my_group = all_groups.select{|g| g.name == "G1"}
                            picks one of the groups
                            => [#Sketchup::Group:0x80e6768]

                            my_entities = my_group.entities
                            gives the following error
                            NoMethodError: (eval):1:in get_binding': undefined method entities' for [#Sketchup::Group:0x80e6768:Array]

                            I don`t understand that!!!

                            Is there anybody who can explain it to me?

                            With best regards from Germany

                            Andreas

                            1 Reply Last reply Reply Quote 0
                            • thomthomT Offline
                              thomthom
                              last edited by

                              all_groups.select{|g| g.name == "G1"} returns an array with a group - not just the group itself.

                              Since this line is suppose to filter out a single group we assume there will be only one item in the array and therefore extract the first item in the array.

                              my_group = all_groups.select{|g| g.name == "G1"}.first

                              So the whole lot would be:

                              
                              all_groups = Sketchup.active_model.entities.find_all{|e| e.class == Sketchup;;Group}
                              my_group = all_groups.select{|g| g.name == "G1"}.first
                              my_entities = my_group.entities
                              
                              

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

                              1 Reply Last reply Reply Quote 0
                              • A Offline
                                Andreas
                                last edited by

                                @thomthom said:

                                my_group = all_groups.select{|g| g.name == "G1"}.first

                                Thanks - thatยดs exactly what I need!!! ๐Ÿ˜„

                                With best regards from Germany

                                Andreas

                                1 Reply Last reply Reply Quote 0
                                • K Offline
                                  kaas
                                  last edited by

                                  @tig said:

                                  You could simulate the 'edit group' command - set a shortcut e.g. ' Shift+Ctrl+Alt+G' to the 'edit group' menu item and then use ' win32ole.so' to run the key-stroke(s) to make that group active..

                                  I'd like to dig up this old thread because I'm looking for a way (a tool started by a keypress) to drill down many nested groups up to the group with the face I picked, and have that group opened to start pushpulling / modifying etc.

                                  Normally I use the outliner to get to the right group but sometimes it's not clear and I have to double click a few times on the target face to drill down the hierarchy. I'd like to skip that double clicking by firing a tool and just pick the face.

                                  I tried making this into a small tool. With the pickhelper I can select the picked face but the group itself isn't opened.

                                  I also tried TIG's suggestion above in a tool but I can't find the 'edit group' command in the shortcuts so can't bind it to a keypress.

                                  Any suggestions??

                                  edit: turns out the shortcut list is generated dynamically. If I select a group and then open the shortcut preferences, I do get the option to assign a key.

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

                                    To set up a shortcut that is context-sensitive you must be in that selection-context.
                                    So to shortcut 'Edit Group' you first need to select a group to get that possibility in the context-menu and you must then open SketchUp's Preferences > Shortcuts and filter for 'Group'... - then set up the shortcut on that tool's command... then of course you'll need to mimic some key-presses etc in some third party code executed by Ruby - all as outlined earlier [PC only]...

                                    PS: This 'context' issue when making shortcuts applies to many selection-sensitive commands - like Reverse and Orient, which both need a face to be selected before they appear in the context-menu list...

                                    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