• Login
sketchucation logo sketchucation
  • Login
โš ๏ธ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Explode 1 level component

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 3 Posters 235 Views 3 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.
  • G Offline
    glro
    last edited by 8 Aug 2011, 17:55

    Hi,

    I have components containing components(nestled components? sub components?)

    I would like to explode only the first level of components, to keep the information contained in the sub components

    i tried this code

    
    ent = mod.entities
    
    	for e in ent
    		if e.is_a? Sketchup;;ComponentInstance 
    			e.explode
    		end
    	end
    
    

    but instead on exploding only the initial components once, it seems that sketchup explodes completely the first component, then the sub components of the first initial component, ...

    is there a way to explode only once the initial components?


    2 nestled components


    some components a exploded twice, and others never

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 8 Aug 2011, 18:39

      Use ents.to_a - that freezes the list; if you use ' ents' it keeps looking into what's available in the 'entities' and it will find some things that have just been added from the one you've just exploded !

      TIG

      1 Reply Last reply Reply Quote 0
      • G Offline
        glro
        last edited by 8 Aug 2011, 19:17

        @tig said:

        Use ents.to_a - that freezes the list; if you use ' ents' it keeps looking into what's available in the 'entities' and it will find some things that have just been added from the one you've just exploded !

        Yes, this is exactly what was happening

        i made the correction

        ents = mod.entities
        ents.to_a
        for e in ents.to_a
              if e.is_a? Sketchup;;ComponentInstance
                 e.explode
              end
           end
        
        

        and now it works perfectly

        Thank you very much; it took you a few seconds, while i had been looking for a solution the whole day...

        1 Reply Last reply Reply Quote 0
        • J Offline
          jolran
          last edited by 8 Aug 2011, 22:13

          @unknownuser said:

          it took you a few seconds, while i had been looking for a solution the whole day...

          ๐Ÿ˜„ I know the feeling

          Does this give the same result for you? I've heard iterators are a good bet.
          I'm just a hack, just something I picked up..
          Acctually looking for the contrary of what you are, exploding everything that's nested.
          So I will try the opposite of what TIG recommended for you. Good thread!

          ents.to_a.each{|e|
          	      next if not e.valid?
          	       e.explode if e.class==Sketchup;;ComponentInstance
          	   }
            end
          
          
          
          1 Reply Last reply Reply Quote 0
          • G Offline
            glro
            last edited by 8 Aug 2011, 22:43

            @jolran said:

            @unknownuser said:

            it took you a few seconds, while i had been looking for a solution the whole day...

            ๐Ÿ˜„ I know the feeling

            Does this give the same result for you? I've heard iterators are a good bet.
            I'm just a hack, just something I picked up..
            Acctually looking for the contrary of what you are, exploding everything that's nested.
            So I will try the opposite of what TIG recommended for you. Good thread!

            ents.to_a.each{|e|
            > 	      next if not e.valid?
            > 	       e.explode if e.class==Sketchup;;ComponentInstance
            > 	   }
            >   end
            > 
            > 
            

            No, what i get is:
            Error: #<SyntaxError: (eval):8:in `initialize': compile error
            (eval):8: syntax error, unexpected kEND, expecting $end
            end

            To explode nestled components, maybe you could try this
            http://www.smustard.com/script/Bomb

            1 Reply Last reply Reply Quote 0
            • J Offline
              jolran
              last edited by 9 Aug 2011, 05:09

              oh sorry typo. You need to incoperate it with the rest of your script and put "end".
              Never mind.. I probably to green to give any advice.
              Will have a look at that bomb, thanks!

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 9 Aug 2011, 11:27

                You have a superfluous 'end' after the '}'.
                The 'for...end' is similar to the '..each{...}'
                The block is '{...}' so the 'end' is not needed [unless of course it's part of a longer piece of text - e.g. it's needed to close a method 'def', an 'if' test etc]

                TIG

                1 Reply Last reply Reply Quote 0
                • J Offline
                  jolran
                  last edited by 9 Aug 2011, 13:19

                  So I was wrong in everything I said ๐Ÿ˜„

                  Yes it was part of some longer piece, I copy and pasted it wrong, sorry.

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  1 / 1
                  • First post
                    1/8
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement