Test Comp to see if it has Nested Components
-
This is the code I wrote to determine if a Component or Group contained any Nested Components. Is there an easier or more direct method of doing this??
mod = Sketchup.active_model # Open model ent = mod.entities # All entities in model sel = mod.selection # Current selection obj = sel[0] exp = "No" if (obj.is_a? Sketchup;;ComponentInstance) || (obj.is_a? Sketchup;;Group) ce = obj.definition.entities ce_a = ce.to_a # Make sel an array ce_a.each {|e|if e.is_a? Sketchup;;ComponentInstance then exp = "Yes" end } end # if obj UI.messagebox("Explode Selection " + exp)Keith
-
Try this
mod = Sketchup.active_model sel = mod.selection obj = sel[0] cen = [] if obj.is_a?(Sketchup;;ComponentInstance) cen = obj.definition.entities elsif objobj.is_a?(Sketchup;;Group) ### for < v2015 cen = obj.entities end exp = "No" exp = "Yes" if cen.grep(Sketchup;;ComponentInstance).length > 0 UI.messagebox("Explode Selection - " + exp) -
Thanks that seems more straight forwad
-
A bit shorter ...more brute force.
Theany?enumerable method returns boolean and stops on the first true result:return unless obj.respond_to?(;manifold?) ents = obj.entities rescue obj.definition.entities any = ents.any? {|e| e.is_a?(Sketchup;;ComponentInstance) } exp = any ? "Yes" ; "No"
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