combining components into 1 component

combining components into 1 component

Postby ktkoh » Mon May 14, 2018 12:27 am

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
0

ktkoh 
PluginStore Author
PluginStore Author
 

Re: combining components into 1 component

Postby ktkoh » Mon May 14, 2018 12:50 pm

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.
0

ktkoh 
PluginStore Author
PluginStore Author
 

Re: combining components into 1 component

Postby sdmitch » Mon May 14, 2018 2:19 pm

ktkoh wrote: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


1. Create a group
2. Add instances of each component to the group and explode
3. Convert group to component.

Code: Select all
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"

0
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch 
PluginStore Author
PluginStore Author
 

Re: combining components into 1 component

Postby ktkoh » Tue May 15, 2018 2:44 pm

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.

Code: Select all
@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
0

ktkoh 
PluginStore Author
PluginStore Author
 

Re: combining components into 1 component

Postby sdmitch » Tue May 15, 2018 3:16 pm

ktkoh wrote: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().
0
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch 
PluginStore Author
PluginStore Author
 

Re: combining components into 1 component

Postby ktkoh » Wed May 16, 2018 1:24 pm

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
0

ktkoh 
PluginStore Author
PluginStore Author
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 4 guests

Visit our sponsors: