sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Selectionobserver

    Scheduled Pinned Locked Moved Developers' Forum
    13 Posts 4 Posters 698 Views 4 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      As Dan says, make a list of the selected items, remove them from the selection and then erase them ?

      I hadn't spotted the method you used - .onBulk... is the one to use - the others are foobar...

      TIG

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

        first of all, thank you guys.
        ok, the ...BulkChange observer responds.
        is it possible to delete instead of the entities in the selection every entity on a certain layer?

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

          model=Sketchup.active_model layers=model.layers layername="Layer1"

          you decide which layer to use!

          model.active_entities.to_a.each{|e| next if not e.valid?; e.erase! if e.layer==layers[layername] }

          note how we make an array [.to_a] of the entities -

          you can't work on the entities directly AND change it - weird results will happen!

          the active_entities erases just things in that entities collection -

          that need not be model.entities, but could be group.entities or even definition.entities

          the e.valid? test avoids a crash -

          e.g. if you've erased an edge so its face no longer exists when we come to look at it!

          TIG

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

            works with the faces, but all the lines aren't erased. any idea why?

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

              @tig said:

              model=Sketchup.active_model layers=model.layers layername="Layer1"

              you decide which layer to use!

              model.active_entities.to_a.each{|e| next if not e.valid?; e.erase! if e.layer==layers[layername] }

              note how we make an array [.to_a] of the entities -

              you can't work on the entities directly AND change it - weird results will happen!

              the active_entities erases just things in that entities collection -

              that need not be model.entities, but could be group.entities or even definition.entities

              the e.valid? test avoids a crash -

              e.g. if you've erased an edge so its face no longer exists when we come to look at it!

              It'd be faster to fetch the reference to the layer you want to erase from before the loop. Retrieving a reference to a layer by looking up a string reference is slower.

              <span class="syntaxdefault">model&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br />layer&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">layers</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'Layer1'</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_a</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault">  e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase</span><span class="syntaxkeyword">!</span><span class="syntaxdefault"> if e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">valid</span><span class="syntaxkeyword">?</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">layer&nbsp;</span><span class="syntaxkeyword">==&nbsp;</span><span class="syntaxdefault">layer<br /></span><span class="syntaxkeyword">}</span><span class="syntaxdefault"> </span>
              

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

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

                @kiesewetter said:

                works with the faces, but all the lines aren't erased. any idea why?

                The edges aren't on the same layer?

                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

                  They are not on the layer ?
                  To find an object's layer Select it and open Entity Info...
                  The code snippet I offered erases everything on a particular layer - it is not careful about things like if the edge goes so does its face even if that face is NOT on that layer...
                  It was a simplistic example - you can add all sorts of checks too.
                  If you only want to layer faces but erase their edges then use something like...
                  Firstly change it to
                  layer=layers[layername] ### as tt recommends...

                  then inside the 'each' loop...

                  ...

                  if e.class==Sketchup;;Face and e.layer==layer
                    edges=e.edges
                    e.erase!
                    edges.each{|ed| ed.erase! if not ed.faces[0] }
                  end
                  

                  ...
                  which erases the face if it's on the specified layer... AND having made a list of that face's edges, it erases any of them that are now 'faceless' as a result...

                  TIG

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

                    the edges were on the same layer (tested it with test=e.layer; puts test)

                    could it be that lines only can be deleted, if they don't border a face?

                    i executed the script to delete the entities twice, in the first step only the faces were deleted. in the second step the lines were erased.

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

                      @kiesewetter said:

                      could it be that lines only can be deleted, if they don't border a face?

                      Erasing an edge will also erase any connected faces.

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

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

                        hmmm... ok. in this case i don't understand why the lines behaved like that. not that important.
                        ok, thanks to you once again. 😄

                        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