Exploding selected model using ruby numeric values
-
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"
-
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... -
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} }
-
@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 aneach
missing from in front of the{}
I've tried it now and it works...
#*** You might want to addmodel.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 ? -
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?
-
You didn't say that !
You can get to entities inside a component-instance
definition.entities
or agroup.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'
-
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.
-
any ideas?
-
@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... -
Hi Tig,
I have sent you a pm with more details about the attributes exporter.
Advertisement