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

    Exploding selected model using ruby numeric values

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 2 Posters 654 Views 2 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.
    • S Offline
      simonstaton
      last edited by

      Hi,

      I just wanted to check if there is a numeric values for exploding the selected model. I checked on the sketchup ruby api "http://code.google.com/apis/sketchup/docs/ourdoc/sketchup.html" however could not find one but I have done it in the past but now the numeric values have changed and it is not working.

      here is the explode function so far I have it selecting all the models next I need it to explode the select:

       cmd = UI::Command.new("Explode") { 
       Sketchup.send_action(21101)
       Sketchup.send_action(EXPLODE NUMERIC VALUE HERE)
       }
       cmd.small_icon = "finished.png"
       cmd.large_icon = "finished.png"
      
      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        You don't need to ' select all' or do a ' send_action': assuming it's groups/component-instances you want to explode then you can select all of them using
        insts=[]; model.definitions.each{|d|insts << d.instances}; insts.flatten!
        Now you have an array of all component instances and groups, iterate through it and use .explode on them, thus
        insts.each{|inst|inst.explode}
        Untried, but you get the idea... πŸ€“

        TIG

        1 Reply Last reply Reply Quote 0
        • S Offline
          simonstaton
          last edited by

          Hmm it didnt seem to work but I dont think I have placed it correctly, any chance you could check this over for me:

           cmd = UI::Command.new("Explode") { 
           insts=[]; model.definitions{|d|insts << d.instances}; insts.flatten!
           insts.each{|inst|inst.explode}
           }
          
          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            @simonstaton said:

            Hmm it didnt seem to work but I dont think I have placed it correctly, any chance you could check this over for me:
            cmd = UI::Command.new("Explode") {
            insts=[]; model.definitions{|d|insts << d.instances}; insts.flatten!
            insts.each{|inst|inst.explode}
            }

            
            model=Sketchup.active_model
            cmd = UI;;Command.new("Explode"){insts=[]; model.definitions.each{|d|insts << d.instances}; insts.flatten!; 
            insts.each{|inst|inst.explode} }#***
            

            It was a'snippet' - model isn't explicitly defined and there was an each missing from in front of the {}
            I've tried it now and it works...
            #*** You might want to add model.definitions.purge_unused at the end, so that the component-browser is emptied ?
            You can filter the 'definitions' so you get only components or groups or images - this explodes everything ?

            TIG

            1 Reply Last reply Reply Quote 0
            • S Offline
              simonstaton
              last edited by

              ok that works perfect however this is where it gets a little complicated.

              For some reason when I used to use a numeric value it only exploded once, the way my components work is each model has a component inside a component and its the one inside that we need to keep as this has attributes we need to read.

              is there anyway we can only have it exploded the outside component and not the inside component?

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

                You didn't say that ! πŸ˜’

                You can get to entities inside a component-instance definition.entities or a group.entities collection, and if one of the contained entities is an instance itself then read its attributes - all without exploding anything at all... πŸ˜•

                However, let's assume you only want to explode the placed components within the model and retain their contents unexploded - try this:

                
                model=Sketchup.active_model
                cmd = UI;;Command.new("Explode"){model.entities.to_a.each{|e|e.explode if e.class==Sketchup;;Group or e.class==Sketchup;;ComponentInstance} }#***
                
                

                This 'freezes' the model's entities list by making it an array ( .to_a), otherwise later changes will affect entities that have appeared out of explosions. It doesn't need to compile a list as it simply explodes as it goes, leaving any new instances that come out of an explosion etc in the model, intact... If you only want to explode component-instances but leave groups alone then adjust the 'if class' test without the 'or'
                πŸ€“

                TIG

                1 Reply Last reply Reply Quote 0
                • S Offline
                  simonstaton
                  last edited by

                  I know apologies,

                  your second method worked perfectly however if you click the toolbar explode button more than once then it explodes again πŸ˜„ so I think your first method might be the best however woosh thats gone straight over my head lol.

                  ill explain a bit more about what I am doing. I have used an attributes plugin in sketchup where I can right click on a component and assign it a price and name however as soon as I save the sketchup file the attributes are lost unless you put this component inside another component. so all of the components are inside another component and unless you explode the first component, when you go to plugins>attributes exporter nothing is shown.

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    simonstaton
                    last edited by

                    any ideas?

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

                      @simonstaton said:

                      I know apologies,

                      your second method worked perfectly however if you click the toolbar explode button more than once then it explodes again πŸ˜„ so I think your first method might be the best however woosh thats gone straight over my head lol.

                      ill explain a bit more about what I am doing. I have used an attributes plugin in sketchup where I can right click on a component and assign it a price and name however as soon as I save the sketchup file the attributes are lost unless you put this component inside another component. so all of the components are inside another component and unless you explode the first component, when you go to plugins>attributes exporter nothing is shown.

                      What kind of rubbish attribute-adder are you using ?
                      I could easily write you one that adds attributes to specific component-instances that are remembered across sessions [provided you saved the model!]
                      An attribute resides with its host ?
                      PM me with what you are using - this seems a real "sledge hammer to crack a walnut" problem... πŸ˜’

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        simonstaton
                        last edited by

                        Hi Tig,

                        I have sent you a pm with more details about the attributes exporter.

                        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