Help w This Ruby Script for Orienting Components for Cut Sheet?

Hi Everyone!

I’m a long time sketchup user, but I don’t have any experience with Ruby scripts. I’m taking a break this afternoon to improve my work flow re: creating cut sheets. The ruby script offered by sdmitch on this discussion (copied below) is fantastic:

However, I’m stuck because I use the scale tool to speed my work vs. entering a group and pushing/pulling faces. Which results in variously scaled components which all revert to 1:1 scale upon running the ruby script.

So, would anyone be so kind as to show how to edit this script to maintain geometry scales?

Also, is there a more effective way to orient faces of flat components (plywood cabinet parts) to the ground? Is the best solution for me to re-orient the axis on all components?

After a lot of digging I haven’t been able to find an extension that performs the same function on mac and is current. I experimented with the Cut List extension, but rotating and orienting the geometry within Sketchup is preferred as I use Layout for shop drawings. If you have an extension to recommend that would be welcome!

I included a model. Many of the steel tube components get stretched after running the script in this example.

Thanks!!!
Kant

mod = Sketchup.active_model

ent = mod.active_entities

sel = mod.selection

SKETCHUP_CONSOLE.clear

org = Geom::Point3d.new(); spc = 2

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])

}

}

Edit: Code colourized & moved to Ruby API

Condiment Station Ruby Test.skp (316.5 KB)

Please post code correctly …

… and move to the Ruby API category. Thanx.

1 Like

Ok, will do thanks!

1 Like