Wow, this looks epic. I haven’t been able to try it yet and just wanted to say thanks in the mean time.

Just a thought, if you can code to meet the basic requirements, are you able to tweak the code to add a specific gap between parts? Like 10cm or something?

Answer:

```
mod = Sketchup.active_model
ent = mod.active_entities
sel = mod.selection
SKETCHUP_CONSOLE.clear
org = Geom::Point3d.new()
cis = ent.grep(Sketchup::ComponentInstance).each{|ci|
ci.transform! ci.transformation.inverse
vec = org-ci.transformation.origin; #p vec
ci.transform! Geom::Transformation.new(vec) if vec.length>0
if ci.bounds.width>ci.bounds.height
vec = org-ci.bounds.corner(2)
ci.transform! Geom::Transformation.new(vec)
ci.transform! Geom::Transformation.rotation(org,Z_AXIS,90.degrees)
end
if ci.bounds.depth>ci.bounds.width && ci.bounds.depth>ci.bounds.height
ci.transform! Geom::Transformation.rotation(org,X_AXIS,90.degrees)
end
org.offset!([ci.bounds.width+10.cm,0,0])
}
```

Revision by mitch (more comprehensive approach):

```
mod = Sketchup.active_model
ent = mod.active_entities
sel = mod.selection
SKETCHUP_CONSOLE.clear
org = Geom::Point3d.new(); spc = 10.cm
cdn = ent.grep(Sketchup::ComponentInstance).map{|ci|ci.definition.name}.uniq.sort
cdn.each{|n|
cis = ent.grep(Sketchup::ComponentInstance).each{|ci|
next unless ci.definition.name==n
ci.transform! ci.transformation.inverse
ci.transform! Geom::Transformation.translation(org-ci.transformation.origin)
if ci.bounds.width>ci.bounds.height
ci.transform! Geom::Transformation.translation(org-ci.bounds.corner(2))
ci.transform! Geom::Transformation.rotation(org,Z_AXIS,90.degrees)
end
if ci.bounds.depth>ci.bounds.width && ci.bounds.depth>ci.bounds.height
ci.transform! Geom::Transformation.rotation(org,X_AXIS,90.degrees)
end
if ci.bounds.min.y < org.y
ci.transform! Geom::Transformation.rotation(org,X_AXIS,180.degrees)
ci.transform! Geom::Transformation.translation(org-ci.bounds.corner(0))
end
org.offset!([ci.bounds.width+spc,0,0])
}
}
```