Skip to content

Instantly share code, notes, and snippets.

@alexschreyer
Created June 13, 2020 19:17
Show Gist options
  • Save alexschreyer/a8c2a2cf34222abb6ead74a47a772cb4 to your computer and use it in GitHub Desktop.
Save alexschreyer/a8c2a2cf34222abb6ead74a47a772cb4 to your computer and use it in GitHub Desktop.
Randomly position textures on faces in SketchUp
# Randomly position textures on faces
# To begin, select ungrouped faces and/or grouped objects, not components
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
# Get all ungrouped faces and those that are inside groups (from selection)
all_faces = []
# Ungrouped faces first
all_faces.push( *sel.grep( Sketchup::Face ) )
# Grouped faces next
sel.grep( Sketchup::Group ).each { |g|
g.make_unique # Need to do this, otherwise group copies share same definition
all_faces.push( *g.entities.grep( Sketchup::Face ) )
}
# Iterate through all faces and randomly arrange the textures
all_faces.each { |f|
pt_array = []
pt_array[0] = f.vertices[0].position
# Radomly scale based on face size
pt_array[1] = Geom::Point3d.new(rand * f.bounds.width,rand * f.bounds.height,0)
# Arrange both the front and the back face textures
f.position_material(f.material, pt_array, true)
f.position_material(f.back_material, pt_array, false)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment