• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Closing open groups via Ruby?

Scheduled Pinned Locked Moved Developers' Forum
15 Posts 8 Posters 1.0k Views 8 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
    shotgunefx
    last edited by 26 Feb 2011, 20:12

    Hi All,

    First post here. I'm wondering if there is a way to close any open groups when a tool is activated.

    I'm working on a texturing tool that operates outside of groups. You simply select the face you want, then select another face in the model and the texture is copied to that face and aligned properly (using plane intersection).

    The whole impetus for this is that I mainly work in Sketchup to map for Source games. When exporting to Source VMF format, a valid solid has to be a group of faces that makes a convex shape. So for the most part, you will be dealing with groups. So not being able to align textures across groups is a pretty big pain (as soon as you open a group, the other group's textures are replaced by a material color).

    So I was thinking it would be more polished if the tool could automatically (or at least optionally) be able to back out of all the open groups when you activate the tool.

    An example video of the tool in use can be found here.
    http://www.youtube.com/watch?v=hb63D7Cmt50

    Any ideas would be appreciated. Thanks!

    1 Reply Last reply Reply Quote 0
    • C Offline
      Chris Fullmer
      last edited by 27 Feb 2011, 22:45

      EDIT: I was way off....apparently there is a way to close groups! Sorry 'bout that,

      [deleted rubbish and misleading comments]... you could check if the user is inside a group when the script is activated and pop up an error saying that must not be in group edit mode and then exit the script so they can get out of group edit mode.

      That way they would be forced into only being able to use the script outside of all groups.

      Chris

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 28 Feb 2011, 02:20

        Use a test like

        until model.active_entities==model.entities
          model.close_active
        end
        

        this will close active group or component edits, including any nesting, back to the base model entities...

        You can't 'open' them BUT you can 'close' them.

        TIG

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 28 Feb 2011, 09:21

          @tig said:

          Use a test like

          until model.active_entities==model.entities
          >   model.close_active
          > end
          

          this will close active group or component edits, including any nesting, back to the base model entities...

          You can't 'open' them BUT you can 'close' them.

          Beware of this method!
          Normally when you close group in SU it adds the action to the Undo stack. But this method doesn't do this. So when you close the group and then decide to undo a few steps you'll get corrupted geometry as it offsets the modified geometry.

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

          1 Reply Last reply Reply Quote 0
          • S Offline
            shotgunefx
            last edited by 1 Mar 2011, 02:54

            Thank you for the replies. Given the issues involved, I think I'll either let them back out on their own, or at most go with a UI message.

            On a related subject, I've found something I never noticed before regarding groups. It seems that if you copy a group, it acts like a component until you modify it through one of the default tools.

            Example, I have a group containing an arch, I copy that group to another location. My tool (which adds the face under the cursor to a selection for visual feedback), will highlight that face in all instances as if it were a component. Though if I go to one of the instances and say... position the texture, it only affects the open group as expected.

            So I'm guessing that Sketchup does something similar to copy on write as far as groups. So what's the best way for me to do the same?

            I'm guessing depreciated or not, Group.make_unique is probably the way to go. So I'm guessing I'll have to walk up the entities to find the groups's Sketchup::ComponentDefinition, and if the instance's are greater than 1, make each unique, and the call pickhelper again to get the possible "new" face.

            Is there a better way to do this?

            Am I better off using an observer for this? (I've not used them before) and just make each group unique as they are created?

            Thanks!

            1 Reply Last reply Reply Quote 0
            • S Offline
              shotgunefx
              last edited by 1 Mar 2011, 21:45

              Well, Group.make_unique doesn't cut it. I get a warning that it's depreciated, but still the same behavior. I suppose I could make new groups and copy the entities over, delete the originals and insert them, but it seems like there should be an easier way. Obviously, at least internally, Sketchup has a way to do this.

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 1 Mar 2011, 23:00

                If you use group.make_unique on every copy you make they should each become 'individual' - there is still the misleading 'deprecated' error message that is plain 'wrong'!
                Are you using 'copy' and transforming the 'copy' or 'add_instance()' ??

                TIG

                1 Reply Last reply Reply Quote 0
                • S Offline
                  shotgunefx
                  last edited by 1 Mar 2011, 23:19

                  @tig said:

                  If you use group.make_unique on every copy you make they should each become 'individual' - there is still the misleading 'deprecated' error message that is plain 'wrong'!
                  Are you using 'copy' and transforming the 'copy' or 'add_instance()' ??

                  What I tried to do was something like this..

                  I call it on the face returned by picked_face

                  def GroupUniqueAsNeeded(ent)
                     while (ent.respond_to?('parent') )
                          if ((ent.is_a? Sketchup;;ComponentDefinition))
                              if ent.group?
                                  if ent.instances.length > 0
                                      ent.instances.each do |e|    
                                          e.make_unique
                                      end
                                      return 1
                                  end
                              # else component    
                              end
                          end
                          ent = ent.parent
                     end
                  end
                  

                  If it returns one, I redo the pick, getting (theoretically) the correct face. But in practice, sometimes when I assign a material to the face, it's still painting that face in all copies.

                  Perhaps I'm getting caught in this parent bug
                  http://forums.sketchucation.com/viewtopic.php?f=180&t=31318&p=275894#p275894

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    TIG Moderator
                    last edited by 1 Mar 2011, 23:49

                    Not sure about your code - I don't have time to test it tonight...
                    Here's a one-liner method to ensure that ALL groups in the model are unique [as they ought to be!] BEFORE you start doing anything
                    Sketchup.active_model.definitions.each{|d| d.instances[1..-1].each{|i| i.make_unique} if d.group? and d.instances[1]}

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • S Offline
                      shotgunefx
                      last edited by 2 Mar 2011, 00:09

                      @tig said:

                      @tig said:

                      Not sure about your code - I don't have time to test it tonight...
                      Here's a one-liner method to ensure that ALL groups in the model are unique [as they ought to be!] BEFORE you start doing anything
                      Sketchup.active_model.definitions.each{|d| d.instances[1..-1].each{|i| i.make_unique} if d.group? and d.instances[1]}

                      Thank you sir! That did the trick.

                      1 Reply Last reply Reply Quote 0
                      • J Offline
                        Jim
                        last edited by 22 Mar 2014, 10:39

                        Has this bug been squashed?

                        @thomthom said:

                        @tig said:

                        Use a test like

                        until model.active_entities==model.entities
                        > >   model.close_active
                        > > end
                        

                        this will close active group or component edits, including any nesting, back to the base model entities...

                        You can't 'open' them BUT you can 'close' them.

                        Beware of this method!
                        Normally when you close group in SU it adds the action to the Undo stack. But this method doesn't do this. So when you close the group and then decide to undo a few steps you'll get corrupted geometry as it offsets the modified geometry.

                        Hi

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          thomthom
                          last edited by 22 Mar 2014, 11:04

                          In SU2014, yes. We found a few more methods with this same issue, like Definitionlist.load*
                          Changelog got full details.

                          Sent from my LT25i using Tapatalk

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

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            dacastror
                            last edited by 25 Mar 2014, 19:54

                            @thomthom said:

                            In SU2014, yes.

                            What would be the best way to write this for Sketchup 8 or 2013?
                            (google translator)

                            1 Reply Last reply Reply Quote 0
                            • Dan RathbunD Offline
                              Dan Rathbun
                              last edited by 25 Mar 2014, 22:20

                              You can try this:

                              until model.active_entities==model.entities
                                tname = model.active_path.last.typename
                                ###
                                model.start_operation("Close #{tname} Edit")
                                  #
                                  model.close_active()
                                  #
                                model.commit_operation()
                                ###
                              end
                              

                              I'm not here much anymore.

                              1 Reply Last reply Reply Quote 0
                              • tt_suT Offline
                                tt_su
                                last edited by 26 Mar 2014, 12:37

                                @dacastror said:

                                @thomthom said:

                                In SU2014, yes.

                                What would be the best way to write this for Sketchup 8 or 2013?
                                (google translator)

                                In SU8 and SU2013 and older that method is bugged. No known workaround I'm afraid.

                                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