I am having some confusion, I’m hoping someone can help me.
I want to make a stack of copies of this world map and give each layer a time period.
However, when I copy the map and modify the time period, the time period isn’t lining up correctly.
If I try to delete the time from the previous map, the time period still isn’t lining up.
Here is the sketchup file containing a world map I found in the warehouse
world_map.skp (1.0 MB)
Thank you for any and all clues!
-j_jones
Here is my script so far
module JJones
def self.make_color(model,name,r,g,b,rgb_alpha=255, material_alpha=1.0)
color = Sketchup::Color.new(r,g,b,rgb_alpha)
material = model.materials.add("#{name} #{r} #{g} #{b}")
material.color = color
material.alpha = material_alpha
return material
end # make_color
def self.make_text(group, text, margin, txt_size=5)
print("make_text: #{text}")
tgroup = group.entities.add_group
#str, alignment, font, is_bold, is_italic, letter_height, tolerance, z, is_filled, extrusion)
txt = tgroup.entities.add_3d_text(text, TextAlignCenter, "Arial", true, false, txt_size, 0.0, 0.0, true, 0.25)
# move text to right side of group
gbounds = group.bounds
rfb_corner = gbounds.corner(1)
x,y,z = rfb_corner.to_a
target = Geom::Point3d.new(x+margin,y,z)
bounds = tgroup.bounds
xt = Geom::Transformation.translation(bounds.center.vector_to(target))
tgroup.transform!(xt)
tgroup.name = text
tgroup
end # make_text
def self.create_spectrum(rgb_alpha=255, material_alpha=1.0)
model = Sketchup.active_model
colors = {}
color_array = []
color_name = "magenta"
material = self.make_color(model, color_name, 135,63,191, rgb_alpha, material_alpha) #0
colors[color_name] = material
color_array << material
color_name = "pink"
material = self.make_color(model, color_name, 191,63,186, rgb_alpha, material_alpha) #1
colors[color_name] = material
color_array << material
color_name = "red"
material = self.make_color(model, color_name, 191,63,63, rgb_alpha, material_alpha)
colors[color_name] = material
color_array << material
color_name = "orange"
material = self.make_color(model, color_name, 191,124,63, rgb_alpha, material_alpha)
colors[color_name] = material
color_array << material
color_name = "yellow"
material = self.make_color(model, color_name, 191,186,63, rgb_alpha, material_alpha)
colors[color_name] = material
color_array << material
color_name = "green"
material = self.make_color(model, color_name, 73,191,63, rgb_alpha, material_alpha)
colors[color_name] = material
color_array << material
color_name = "turquoise"
material = self.make_color(model, color_name, 63, 191, 160, rgb_alpha, material_alpha)
colors[color_name] = material
color_array << material
color_name = "sky blue"
material = self.make_color(model, color_name, 63, 191, 191, rgb_alpha, material_alpha)
colors[color_name] = material
color_array << material
color_name = "blue"
material = self.make_color(model, color_name, 63, 114, 191, rgb_alpha, material_alpha)
colors[color_name] = material
color_array << material
color_name = "dark blue"
material = self.make_color(model, color_name, 63, 68, 191, rgb_alpha, material_alpha)
colors[color_name] = material
color_array << material
color_name = "purple"
material = self.make_color(model, color_name, 89, 63, 191, rgb_alpha, material_alpha)
colors[color_name] = material
color_array << material
return colors, color_array
end # create_spectrum
def self.get_group_color(group)
faces = group.definition.entities.grep(Sketchup::Face)
f = faces[0]
f.material
end # get_group_color
def self.get_year_txt(year)
year_txt = year.to_s + ((year < 0) ? " BCE" : " CE")
end # get_year_txt
def self.print_corners(bounds)
print("bounds corners (left front bottom) [0,0,0] : #{bounds.corner(0)}")
print("bounds corners (right front bottom) [1,0,0] : #{bounds.corner(1)}")
print("bounds corners (left back bottom) [0,1,0] : #{bounds.corner(2)}")
print("bounds corners (right back bottom) [1,1,0] : #{bounds.corner(3)}")
print("bounds corners (left front top) [0,0,1] : #{bounds.corner(4)}")
print("bounds corners (right front top) [1,0,1] : #{bounds.corner(5)}")
print("bounds corners (left back top) [0,1,1] : #{bounds.corner(6)}")
print("bounds corners (right back top) [1,1,1] : #{bounds.corner(7)}")
end # print_corners
def self.main(millennia, inter_map_distance, start_year, year_margin, erase_prior_year)
model = Sketchup.active_model
entites = model.active_entities
selection = model.selection
model.start_operation("copy upwards", true)
colors, color_array = create_spectrum(rgb_alpha=100, material_alpha=0.3)
num_colors = color_array.length
year = start_year
year_txt = get_year_txt(year)
print("year_txt: #{year_txt}")
if selection.empty?
UI.messagebox("Please select an object to copy.")
else
# select the map, make a copy, add the year, move it up by inter_map_distance
group = selection[0]
(0..millennia).each do |i|
print("millennia: #{i}")
old_color = get_group_color(group)
print("#{i}, #{year_txt}: old color: #{old_color}, #{old_color.class}, #{old_color.name}")
# debugging why the years are wacky
if erase_prior_year # remove last year text
last_year = group.entities.grep(Sketchup::Group).find_all{ |g| g.name==year_txt }
group.entities.erase_entities(last_year) if last_year[0]
end # if erase prior year
# add the year to the right side of the map
year_txt = get_year_txt(year)
tgroup = make_text(group, year_txt, year_margin)
# find front bottom left corner
bounds = group.bounds
x,y,z = bounds.corner(0).to_a
print_corners(bounds)
# calculate new position for the copy
new_pos = [x,y,z+inter_map_distance]
print("#{i}, #{year_txt}: new_pos: #{new_pos}")
# copy and move the map up to new position
transform = Geom::Transformation.new(new_pos)
new_group = entites.add_instance(group.definition, transform)
new_group.make_unique
# give new map a different color
color = color_array[i % num_colors]
new_group.material = color
faces = new_group.definition.entities.grep(Sketchup::Face)
faces.each do |f|
f.material = color
f.back_material = color
end
year += 1000
group = new_group
end # each millennia
end # if selection
model.commit_operation
end # main
end # module
millennia=3
inter_map_distance=36
year_margin=15
start_year=-14000
erase_prior_year=TRUE
JJones.main(millennia, inter_map_distance, start_year, year_margin, erase_prior_year)