Best way to delete entities
-
Almost all 'properly' structured models have ALL base geometry on 'Layer0'...[/quote]
I agree. 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.
-
Hi Clark,
There is such a plugin here:
http://forums.sketchucation.com/viewtopic.php?f=323&t=7638&hilit=default+layer
-
Excellent. Thanks Tig.
-
@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 likedefault_layer_geometry.rb
in the Plugins folder... -
[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 -
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!
-
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 -
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... -
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 -
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 theinstance.transformation
search for them - here's an example... http://sketchucation.com/forums/viewtopic.php?p=411972#p411972 -
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
-
The entities.erase_entities(array)
Expects an array NOT an entities collection, so adding .to_a resolves that.
BUT entites.clear! is even easier. -
great - that's what I was looking for anyway
Advertisement