Can it be to achieve?
-
Everyboby,I want to have a replacement on components
in model by the ruby script at the same time.Can it be to achieve?
Thanks -
Do you really need for a script to do what you want?
Look at the image here...
-
I think you can get the transformation of the component you want to replace,
then erase it
add the new component and apply the transformation -
Here are some clues...
### first let's assume you know the component-definition you want 'to go' and you also know the component-definition you want 'to add' in its place... component_to_go.instances.each{|e|e.definition=component_to_add} ### this swaps ALL instances of one for the other, leaving them in place with the same, rotation, scaling, materials etc ### now let's assume that you only have details of one instance of the type that's 'to go' - perhaps you initially got it by selecting it (instance_to_go=SketchUp.active_model.selection[0])... instance_to_go.definition.instances.each{|e|e.definition=component_to_add} ### now let's assume you only want to swap those in a selection and leave any others unchanged... SketchUp.active_model.selection.each{|e|e.definition=component_to_add if e.typename=="ComponentInstance" and e.definition=component_to_go} ###
How might you be getting the info on the 'to go' and the 'to add' component definitions ?
-
Is the idea very difficult? My boss ask me to do that.
-
You can also do it without Ruby...
Try this way...
In the model select the component instances you want to be replaced - either by manually picking them (in which case they can even be a mixture of several types) OR by using the Component Browser (model-tab) and then right-clicking over the definition's icon that you want to have selected and pick 'Select Instances' - that way all of its active instances are selected.
Now use the Component Browser - either in the model-tab to use components that are already within the model, or from any other 'external' location for components that are currently not yet loaded into the project - again you right-click over the definition's icon that you want 'to add' and pick 'Replace Selected'.
Now the components you selected have been replaced by the component you wanted...It's possible to script it BUT it might be as easy to do it this way... There are already several component swapping scripts too...
-
Thanks !I fell a warm in the community forums!
-
@tig said:
You can also do it without Ruby...
Try this way...
In the model select the component instances you want to be replaced - either by manually picking them (in which case they can even be a mixture of several types) OR by using the Component Browser (model-tab) and then right-clicking over the definition's icon that you want to have selected and pick 'Select Instances' - that way all of its active instances are selected.
Now use the Component Browser - either in the model-tab to use components that are already within the model, or from any other 'external' location for components that are currently not yet loaded into the project - again you right-click over the definition's icon that you want 'to add' and pick 'Replace Selected'.
Now the components you selected have been replaced by the component you wanted...It's possible to script it BUT it might be as easy to do it this way... There are already several component swapping scripts too...
It can be done using the Component Browser, but when you have lots of components, it can be easier to select a desired component on-screen rather than hunting through the browser. Though I wrote ApplyTo before the Component Browser offered that functionality, it retains its relevance for this reason.
Advertisement