• 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 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
                • thomthomT 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