sketchucation logo sketchucation
    • Login
    ⚠️ Attention | Having issues with Sketchucation Tools 5? Report Here

    Closing open groups via Ruby?

    Scheduled Pinned Locked Moved Developers' Forum
    15 Posts 8 Posters 1.1k 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

      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
      • TIGT Offline
        TIG Moderator
        last edited by

        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

          @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
          • TIGT Offline
            TIG Moderator
            last edited by

            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

              @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

                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

                  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

                    @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

                      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

                        @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