Problems with script
-
Can someone test this piece of code on the attached model?
For me it does not erase the entities (all text)
Any ideas?Sketchup.active_model.entities.each{|e| e.erase! if e.layer.name=='_4D_Finish_Text' || e.layer.name=='_4D_Start_Text' }
-
Hi,
It works, but to make it work you have to run the piece of code several times, until everything is erased.
entities method returns a collection of entities. When you have to erase more than one entity, better use 'erase_entities', like this:def xxx() arrayents=[] Sketchup.active_model.entities.each{|e| arrayents.push(e) if (e.layer.name=="_4D_Finish_Text" or e.layer.name=="_4D_Start_Text") } Sketchup.active_model.entities.erase_entities(arrayents) end endEverything's gone in one go
Hope this helps, -
Great! That works excellent.
I wonder why it does not delete everything with the method i suggested.I think i will need to review some of my code. Is erase the only method that gives this 'problem'?
Thx again Didier
-
You should NOT change a collection of entities you are iterating through...
NO-NO=Sketchup.active_model.entities.each{|e| e.erase! if e.layer.name=='_4D_Finish_Text' || e.layer.name=='_4D_Start_Text' }YES-YES=
Sketchup.active_model.entities.to_a.each{|e| e.erase! if e.layer.name=='_4D_Finish_Text' || e.layer.name=='_4D_Start_Text' }Note how the entities is made into frozen array [.to_a] before processing...
To remove such items from inside all definitions use
Sketchup.active_model.definitions.each{|d|d.entities.to_a.each{|e| e.erase! if e.layer.name=='_4D_Finish_Text' || e.layer.name=='_4D_Start_Text' })
EDIT: typo corrected '.to_a' added to final example

Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement