Skip to content

Instantly share code, notes, and snippets.

@tenadavila
Created February 25, 2021 18:57
Show Gist options
  • Save tenadavila/d6e8904e99170cdbb27de2c849d86c78 to your computer and use it in GitHub Desktop.
Save tenadavila/d6e8904e99170cdbb27de2c849d86c78 to your computer and use it in GitHub Desktop.
Sketchup -> Ruby transform model to tables
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
# cuadra en rojo (X)
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
if ci.bounds.depth>ci.bounds.width
ci.transform! Geom::Transformation.rotation(org,Y_AXIS,90.degrees)
ci.transform! Geom::Transformation.translation(org-ci.bounds.corner(0))
end
org.offset!([ci.bounds.width+spc,0,0])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment