Combining components into 1 component
-
I am bringing 3 parts (components) which are placed such that if all 3 are exploded and then all selected and made a single component. I have not been able to accomplish this with the API. Any suggestions
Keith
-
I worked on this some more and found a Solution.
Created a new layer
added each comp to that layer
exploded each comp
cleared selection
added all entities on the layer to the selection
added selection to new group
cleared selection
added group to selection
I could now make the group a solid I did not need a component at this point. -
@ktkoh said:
I am bringing 3 parts (components) which are placed such that if all 3 are exploded and then all selected and made a single component. I have not been able to accomplish this with the API. Any suggestions
Keith
- Create a group
- Add instances of each component to the group and explode
- Convert group to component.
mod = Sketchup.active_model ent = mod.active_entities sel = mod.selection SKETCHUP_CONSOLE.clear grp = ent.add_group cmp = grp.entities.add_instance(mod.definitions["component#1"],IDENTITY);cmp.explode cmp = grp.entities.add_instance(mod.definitions["component#2"],IDENTITY);cmp.explode cmp = grp.entities.add_instance(mod.definitions["component#3"],IDENTITY);cmp.explode cmp = grp.to_component;cmp.definition.name="Cmps1-3"
-
I will try Mitch's code. Question there are 2 constantans I am not familiar with in your code. SKETCHUP_CONSOLE.clear and IDENTITY.
The problem with my version is that the entities that make up the final are on the Components layer not layer0. In the code I thought I was moving them back to layer0 but it didn't work and it didn't flag an error.
@sss.clear ents = [] @entities.each { |e| ents << e if (e.layer.name == @assy_Name) && ( ! e.is_a?(Sketchup;;Group) && ! e.is_a?(Sketchup;;ComponentInstance) )} ents.each { |e| e.layer.name = "Layer0" } @ss.add(ents) copedRail = @entities.add_group(@ss) @ss.clear; @ss.add copedRail copedRail.layer = @assy_Name
Thanks
Keith -
@ktkoh said:
I am not familiar with in your code. SKETCHUP_CONSOLE.clear and IDENTITY.
SKETCHUP_CONSOLE.clear simply clears the Ruby Console so any errors that occur will be more obvious.
IDENTITY is the same as Geom::Transformation.new().
-
Thanks Mitch your code worked very well once I figured out the transformation I needed. The code also left the component entities on Layer0 which was a problem for my code.
The forum is an amazing source of info thanks to the many people who are willing to share their knowledge.
Keith
Advertisement