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

    Best way to delete entities

    Scheduled Pinned Locked Moved Developers' Forum
    19 Posts 9 Posters 7.1k Views 9 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.
    • daikuD Offline
      daiku
      last edited by

      Excellent. Thanks Tig.

      Clark Bremer
      http://www.northernlightstimberframing.com

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

        @daiku said:

        Almost all 'properly' structured models have ALL base geometry on 'Layer0'...

        I agree.
        @unknownuser said:

        Is there a ruby out there that will "sanitize" you model to enforce this "rule"? It would ignore groups and comps, but any base geometry would be moced to layer0. CB.

        See this: http://forums.sketchucation.com/viewtopic.php?p=115749#p115749
        copy/paste the code into a file called something like default_layer_geometry.rb in the Plugins folder...

        TIG

        1 Reply Last reply Reply Quote 0
        • artmusicstudioA Offline
          artmusicstudio
          last edited by

          [quote="thomthom"]To delete one entity: use Entity.erase!

          entity = Sketchup.active_model.active_entities[0] entity.erase!

          hi tig,

          in my first ruby i have already managed it to copy one master-component (created with ruby at [0,0,0] and copying it, where ever i want.

          after placing it in all places wanted, i would like

          to DELETE this particular master-component.

          i found your code:

          entity = Sketchup.active_model.active_entities[0]
          entity.erase!

          but how can i define , which component is to be deleted? is there a name somewhere? or index, i could "memorize" while creating the master component? is the [0] maybe a place for a definition?

          thanx a lot for helping!
          stan

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

            @Stan

            How are you making the initial component instance?
            How are you 'copying' it ?
            To have done that you must have had a 'reference' to its definition - let's say it's called ' defn'...
            To find that definition's first instance and then to delete it use:
            defn.instances.first.erase!

            TIG

            1 Reply Last reply Reply Quote 0
            • artmusicstudioA Offline
              artmusicstudio
              last edited by

              hi tig,
              probably i have a mistake in the component-description.

              i define a master component (two tubes).

              #DEF PFOSTEN MASTER COMPONENT

                 model = Sketchup.active_model
                 entities = model.active_entities  
              
                 pfm1 = [0, 0, 0+thickness]
                 pfm2 = [0, 0, 0+thickness+sl-((5/faktor)/100)]
                 pfm3 = [0, 0, 0+thickness+sl-((5/faktor)/100)]
                 pfm4 = [0, 0, 0+thickness+sl]        
                 
                 group = entities.add_group
                 
                 entities2 = group.entities
                        
                 new_line = entities2.add_line pfm1, pfm2
                              length = new_line.length
                              centerpoint = pfm1
                              vector = pfm2
                              vector = vector.normalize!
                               
                              edges = entities2.add_circle centerpoint, vector, pradius
                              kreis = entities2.add_face edges
                              kreis.pushpull length
                   
                   
                 new_line2 = entities2.add_line pfm3, pfm4
                              length2 = new_line2.length 
                              centerpoint2 = pfm4
                 	            vector2 = pfm3
                          vector2 = vector.normalize!
              		                     
              	    edges2 = entities2.add_circle centerpoint2, vector2, pradius/3
              	    kreis2 = entities2.add_face edges2
                              kreis2.pushpull -length2
                              
                 masterpfostenl = group.to_component
              

              and then copy it to different places to ponits pf1,2,3:

              componentinstance =
              entities.add_instance(masterpfostenl.definition, pf1)
              componentinstance =
              entities.add_instance(masterpfostenr.definition, pf3)
              componentinstance =
              entities.add_instance(mittelpfostenm.definition, pf5)

              after all components are placed, i will try the

              defn.instances.first.erase! (have still to find out, how to point the right "instances-group"

              thanx
              stan

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

                You have got it !

                defn = masterpfostenl.definition

                The masterpfostenl is a reference to the first 'instance' of the new 'definition'...

                Then see my previous example...

                BUT to delete it it use masterpfostenl.erase!
                Because you already have a reference to it, which you have set up early on...

                TIG

                1 Reply Last reply Reply Quote 0
                • artmusicstudioA Offline
                  artmusicstudio
                  last edited by

                  yes sir,
                  it works perfectly. so this deletes the master-component.
                  i just wonder, how then can be identified the ,daughter'-components.

                  per x,y,z ?

                  anyway, thank you very much for this solution.
                  stan

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

                    @stan

                    Assuming 'defn' is a reference to the component's definition then
                    defn.instances
                    gives you a list of all current instances, in the order of their creation.
                    let's say you want to find the first one [remember that arrays start at 0 NOT 1 !]
                    instance = defn.instances[0]
                    To find out where it is in its current context use
                    point = instance.transformation.origin
                    There are also other transformation properties available to get the orientation of the objetc's x/y/zaxis too...
                    There are also some methods available to get rotations, scaling etc from the instance.transformation search for them - here's an example... http://sketchucation.com/forums/viewtopic.php?p=411972#p411972

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • Al HartA Offline
                      Al Hart
                      last edited by

                      I couldn't get this to work:

                      
                      model = Sketchup.active_model
                      entities = model.active_entities
                      model.active_entities.erase_entities entities
                      
                      

                      I get thi error:

                      Error: #<TypeError: wrong argument type (expected Sketchup::Entity)>
                      <main>:in `erase_entities'

                      But I was able to get this to work: (adding .to_a which probably serves to isolate the entities array)

                      
                      model = Sketchup.active_model
                      entities = model.active_entities
                      model.active_entities.erase_entities entities.to_a
                      
                      

                      Al Hart

                      http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                      IRender nXt from Render Plus

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

                        The entities.erase_entities(array)
                        Expects an array NOT an entities collection, so adding .to_a resolves that.
                        BUT entites.clear! is even easier.

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • Al HartA Offline
                          Al Hart
                          last edited by

                          great - that's what I was looking for anyway

                          Al Hart

                          http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                          IRender nXt from Render Plus

                          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