Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Name: crowd.rb
# Date: May 27, 2008
# Description: copy selected component randomly throughout an area
# Copyright: John Jacobsen, NPX Designs, Inc.
# http://www.johnj.com
# Permission to use, copy, modify, and distribute this software for
# any purpose and without fee is hereby granted, provided that the above
# copyright notice appears in all copies.
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
require 'sketchup.rb'
class Crowd
@@copies = 10
@@size = 100
def Crowd::crowd(number, size)
model = Sketchup.active_model
selection = Sketchup.active_model.selection[0]
entities = model.active_entities
definition = selection.definition
number.times {
x=size*rand
y=size*rand
z=0
point = Geom::Point3d.new(x, y, z)
transform = Geom::Transformation.new point
newcopy = entities.add_instance definition, transform
}
end
def Crowd::crowd_with_prompts
prompts = ["Number of copies: ",
"Size of area"]
values = [@@copies, @@size]
results = inputbox prompts, values, "Copy to Crowd"
return if not results
@@copies = results[0]
@@size = results[1]
crowd(@@copies, @@size)
end
end # Class Crowd
if (not file_loaded?("crowd.rb"))
UI.menu("Plugins").add_item("Copy to Crowd") { Crowd.crowd_with_prompts }
end
file_loaded("crowd.rb")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment