@Dave-R I felt like a complete idiot, I knew there was this function but I couldn't use it, I haven't used Sketchup lately.
Best posts made by bagatelo
-
RE: "Transforming Colors into Materials: A Plugin Inspired by Adobe Kuler"
-
Automate Color Variations in SketchUp with Ease
Automate color variations in SketchUp with ease
This simple SketchUp script is designed to help you easily generate and visualize color variations for a selected object. The script creates three sets of variations: luminance, hue, and saturation. Each set forms a circle of rectangles around the original object, illustrating different levels of brightness, color, and saturation changes. Just select a face with any desired color and run the script to see the variations. It's a simple tool that can help you explore color options more effectively in your models.
require 'sketchup' module CombinedVariations extend self def create_variations create_luminance_variations create_color_variations create_saturation_variations end def create_luminance_variations puts "Iniciando a criação de variações de luminância..." model = Sketchup.active_model selection = model.selection unless selection.length == 1 && selection[0].is_a?(Sketchup::Face) puts "Por favor, selecione apenas um objeto com uma cor só." return end puts "Objeto selecionado encontrado." original_color = selection[0].material.color center_point = selection[0].bounds.center circle_radius = 400.cm puts "Cor original do objeto: #{original_color}" puts "Criando retângulos com variações de luminância..." colors = generate_luminance_colors(original_color) create_rectangles_around_object(center_point, circle_radius, colors, 'LUM') puts "Variações de luminância criadas com sucesso." end def generate_luminance_colors(original_color) puts "Gerando variações de luminância..." colors = [] hsl_color = rgb_to_hsl(original_color.red, original_color.green, original_color.blue) original_hue, original_saturation, original_lightness = hsl_color[:h], hsl_color[:s], hsl_color[:l] luminance_stages = (0..100).map { |i| i / 100.0 } selected_luminance_stages = luminance_stages.select.with_index { |_, i| i.even? } selected_luminance_stages.each do |lightness| color = hsl_to_rgb(original_hue, original_saturation, lightness) colors << Sketchup::Color.new(color[:r], color[:g], color[:b]) end colors end def create_color_variations puts "Iniciando a criação de variações de cores..." model = Sketchup.active_model selection = model.selection unless selection.length == 1 && selection[0].is_a?(Sketchup::Face) puts "Por favor, selecione apenas um objeto com uma cor só." return end puts "Objeto selecionado encontrado." original_color = selection[0].material.color center_point = selection[0].bounds.center circle_radius = 500.cm puts "Cor original do objeto: #{original_color}" puts "Criando retângulos com variações de cores..." colors = generate_color_variations(original_color) create_rectangles_around_object(center_point, circle_radius, colors, 'HUE') puts "Variações de cores criadas com sucesso." end def generate_color_variations(original_color) puts "Gerando variações de cores..." hue_step = 360.0 / 64.0 colors = [] hsv_color = rgb_to_hsv(original_color.red, original_color.green, original_color.blue) original_hue, original_saturation, original_value = hsv_color[:h], hsv_color[:s], hsv_color[:v] 64.times do |i| hue = (original_hue + i * hue_step) % 360 color = hsv_to_rgb(hue, original_saturation, original_value) colors << Sketchup::Color.new(color[:r], color[:g], color[:b]) end colors end def create_saturation_variations puts "Iniciando a criação de variações de saturação..." model = Sketchup.active_model selection = model.selection unless selection.length == 1 && selection[0].is_a?(Sketchup::Face) puts "Por favor, selecione apenas um objeto com uma cor só." return end puts "Objeto selecionado encontrado." original_color = selection[0].material.color center_point = selection[0].bounds.center circle_radius = 300.cm puts "Cor original do objeto: #{original_color}" puts "Criando retângulos com variações de saturação..." colors = generate_saturation_colors(original_color) create_rectangles_around_object(center_point, circle_radius, colors, 'SAT') puts "Variações de saturação criadas com sucesso." end def generate_saturation_colors(original_color) puts "Gerando variações de saturação..." colors = [] hsl_color = rgb_to_hsl(original_color.red, original_color.green, original_color.blue) original_hue, original_saturation, original_lightness = hsl_color[:h], hsl_color[:s], hsl_color[:l] saturation_stages = (0..35).map { |i| i / 35.0 } saturation_stages.each do |saturation| color = hsl_to_rgb(original_hue, saturation, original_lightness) colors << Sketchup::Color.new(color[:r], color[:g], color[:b]) end colors end def rgb_to_hsl(r, g, b) r, g, b = r / 255.0, g / 255.0, b / 255.0 max = [r, g, b].max min = [r, g, b].min delta = max - min l = (max + min) / 2.0 if delta == 0 h = 0 s = 0 else s = delta / (1 - (2 * l - 1).abs) h = if max == r ((g - b) / delta) % 6 elsif max == g (b - r) / delta + 2 else (r - g) / delta + 4 end h *= 60 h += 360 if h < 0 end { h: h, s: s, l: l } end def hsl_to_rgb(h, s, l) c = (1 - (2 * l - 1).abs) * s x = c * (1 - ((h / 60.0) % 2 - 1).abs) m = l - c / 2.0 r, g, b = case h when 0..60 then [c, x, 0] when 60..120 then [x, c, 0] when 120..180 then [0, c, x] when 180..240 then [0, x, c] when 240..300 then [x, 0, c] else [c, 0, x] end { r: ((r + m) * 255).round, g: ((g + m) * 255).round, b: ((b + m) * 255).round } end def rgb_to_hsv(r, g, b) r, g, b = r / 255.0, g / 255.0, b / 255.0 max = [r, g, b].max min = [r, g, b].min delta = max - min h = if max == min 0 elsif max == r 60 * (((g - b) / delta) % 6) elsif max == g 60 * (((b - r) / delta) + 2) else 60 * (((r - g) / delta) + 4) end s = max == 0 ? 0 : delta / max v = max { h: h, s: s, v: v } end def hsv_to_rgb(h, s, v) h = h / 60.0 i = h.floor f = h - i p = v * (1 - s) q = v * (1 - f * s) t = v * (1 - (1 - f) * s) r, g, b = case i % 6 when 0 then [v, t, p] when 1 then [q, v, p] when 2 then [p, v, t] when 3 then [p, q, v] when 4 then [t, p, v] when 5 then [v, p, q] end { r: (r * 255).to_i, g: (g * 255).to_i, b: (b * 255).to_i } end def create_rectangles_around_object(center_point, circle_radius, colors, prefix) puts "Criando retângulos em torno do objeto..." model = Sketchup.active_model entities = model.active_entities rectangle_size = [35.cm, 35.cm] angle_step = 2 * Math::PI / colors.length current_angle = 0 k = 0 colors.each do |color| x = center_point.x + circle_radius * Math.cos(current_angle) y = center_point.y + circle_radius * Math.sin(current_angle) position = Geom::Point3d.new(x, y, center_point.z) group = entities.add_group pt1 = position pt2 = Geom::Point3d.new(x + rectangle_size[0], y, center_point.z) pt3 = Geom::Point3d.new(x + rectangle_size[0], y + rectangle_size[1], center_point.z) pt4 = Geom::Point3d.new(x, y + rectangle_size[1], center_point.z) face = group.entities.add_face(pt1, pt2, pt3, pt4) face.reverse! material_name = "#{prefix}_#{'%02d' % k}_#{color.red}_#{color.green}_#{color.blue}" material = model.materials[material_name] || model.materials.add(material_name) material.color = color face.material = material current_angle += angle_step k += 1 end puts "Retângulos criados." end end UI.menu("Edit").add_item("Create Combined Variations") { CombinedVariations.create_variations }
Latest posts made by bagatelo
-
Automate Color Variations in SketchUp with Ease
Automate color variations in SketchUp with ease
This simple SketchUp script is designed to help you easily generate and visualize color variations for a selected object. The script creates three sets of variations: luminance, hue, and saturation. Each set forms a circle of rectangles around the original object, illustrating different levels of brightness, color, and saturation changes. Just select a face with any desired color and run the script to see the variations. It's a simple tool that can help you explore color options more effectively in your models.
require 'sketchup' module CombinedVariations extend self def create_variations create_luminance_variations create_color_variations create_saturation_variations end def create_luminance_variations puts "Iniciando a criação de variações de luminância..." model = Sketchup.active_model selection = model.selection unless selection.length == 1 && selection[0].is_a?(Sketchup::Face) puts "Por favor, selecione apenas um objeto com uma cor só." return end puts "Objeto selecionado encontrado." original_color = selection[0].material.color center_point = selection[0].bounds.center circle_radius = 400.cm puts "Cor original do objeto: #{original_color}" puts "Criando retângulos com variações de luminância..." colors = generate_luminance_colors(original_color) create_rectangles_around_object(center_point, circle_radius, colors, 'LUM') puts "Variações de luminância criadas com sucesso." end def generate_luminance_colors(original_color) puts "Gerando variações de luminância..." colors = [] hsl_color = rgb_to_hsl(original_color.red, original_color.green, original_color.blue) original_hue, original_saturation, original_lightness = hsl_color[:h], hsl_color[:s], hsl_color[:l] luminance_stages = (0..100).map { |i| i / 100.0 } selected_luminance_stages = luminance_stages.select.with_index { |_, i| i.even? } selected_luminance_stages.each do |lightness| color = hsl_to_rgb(original_hue, original_saturation, lightness) colors << Sketchup::Color.new(color[:r], color[:g], color[:b]) end colors end def create_color_variations puts "Iniciando a criação de variações de cores..." model = Sketchup.active_model selection = model.selection unless selection.length == 1 && selection[0].is_a?(Sketchup::Face) puts "Por favor, selecione apenas um objeto com uma cor só." return end puts "Objeto selecionado encontrado." original_color = selection[0].material.color center_point = selection[0].bounds.center circle_radius = 500.cm puts "Cor original do objeto: #{original_color}" puts "Criando retângulos com variações de cores..." colors = generate_color_variations(original_color) create_rectangles_around_object(center_point, circle_radius, colors, 'HUE') puts "Variações de cores criadas com sucesso." end def generate_color_variations(original_color) puts "Gerando variações de cores..." hue_step = 360.0 / 64.0 colors = [] hsv_color = rgb_to_hsv(original_color.red, original_color.green, original_color.blue) original_hue, original_saturation, original_value = hsv_color[:h], hsv_color[:s], hsv_color[:v] 64.times do |i| hue = (original_hue + i * hue_step) % 360 color = hsv_to_rgb(hue, original_saturation, original_value) colors << Sketchup::Color.new(color[:r], color[:g], color[:b]) end colors end def create_saturation_variations puts "Iniciando a criação de variações de saturação..." model = Sketchup.active_model selection = model.selection unless selection.length == 1 && selection[0].is_a?(Sketchup::Face) puts "Por favor, selecione apenas um objeto com uma cor só." return end puts "Objeto selecionado encontrado." original_color = selection[0].material.color center_point = selection[0].bounds.center circle_radius = 300.cm puts "Cor original do objeto: #{original_color}" puts "Criando retângulos com variações de saturação..." colors = generate_saturation_colors(original_color) create_rectangles_around_object(center_point, circle_radius, colors, 'SAT') puts "Variações de saturação criadas com sucesso." end def generate_saturation_colors(original_color) puts "Gerando variações de saturação..." colors = [] hsl_color = rgb_to_hsl(original_color.red, original_color.green, original_color.blue) original_hue, original_saturation, original_lightness = hsl_color[:h], hsl_color[:s], hsl_color[:l] saturation_stages = (0..35).map { |i| i / 35.0 } saturation_stages.each do |saturation| color = hsl_to_rgb(original_hue, saturation, original_lightness) colors << Sketchup::Color.new(color[:r], color[:g], color[:b]) end colors end def rgb_to_hsl(r, g, b) r, g, b = r / 255.0, g / 255.0, b / 255.0 max = [r, g, b].max min = [r, g, b].min delta = max - min l = (max + min) / 2.0 if delta == 0 h = 0 s = 0 else s = delta / (1 - (2 * l - 1).abs) h = if max == r ((g - b) / delta) % 6 elsif max == g (b - r) / delta + 2 else (r - g) / delta + 4 end h *= 60 h += 360 if h < 0 end { h: h, s: s, l: l } end def hsl_to_rgb(h, s, l) c = (1 - (2 * l - 1).abs) * s x = c * (1 - ((h / 60.0) % 2 - 1).abs) m = l - c / 2.0 r, g, b = case h when 0..60 then [c, x, 0] when 60..120 then [x, c, 0] when 120..180 then [0, c, x] when 180..240 then [0, x, c] when 240..300 then [x, 0, c] else [c, 0, x] end { r: ((r + m) * 255).round, g: ((g + m) * 255).round, b: ((b + m) * 255).round } end def rgb_to_hsv(r, g, b) r, g, b = r / 255.0, g / 255.0, b / 255.0 max = [r, g, b].max min = [r, g, b].min delta = max - min h = if max == min 0 elsif max == r 60 * (((g - b) / delta) % 6) elsif max == g 60 * (((b - r) / delta) + 2) else 60 * (((r - g) / delta) + 4) end s = max == 0 ? 0 : delta / max v = max { h: h, s: s, v: v } end def hsv_to_rgb(h, s, v) h = h / 60.0 i = h.floor f = h - i p = v * (1 - s) q = v * (1 - f * s) t = v * (1 - (1 - f) * s) r, g, b = case i % 6 when 0 then [v, t, p] when 1 then [q, v, p] when 2 then [p, v, t] when 3 then [p, q, v] when 4 then [t, p, v] when 5 then [v, p, q] end { r: (r * 255).to_i, g: (g * 255).to_i, b: (b * 255).to_i } end def create_rectangles_around_object(center_point, circle_radius, colors, prefix) puts "Criando retângulos em torno do objeto..." model = Sketchup.active_model entities = model.active_entities rectangle_size = [35.cm, 35.cm] angle_step = 2 * Math::PI / colors.length current_angle = 0 k = 0 colors.each do |color| x = center_point.x + circle_radius * Math.cos(current_angle) y = center_point.y + circle_radius * Math.sin(current_angle) position = Geom::Point3d.new(x, y, center_point.z) group = entities.add_group pt1 = position pt2 = Geom::Point3d.new(x + rectangle_size[0], y, center_point.z) pt3 = Geom::Point3d.new(x + rectangle_size[0], y + rectangle_size[1], center_point.z) pt4 = Geom::Point3d.new(x, y + rectangle_size[1], center_point.z) face = group.entities.add_face(pt1, pt2, pt3, pt4) face.reverse! material_name = "#{prefix}_#{'%02d' % k}_#{color.red}_#{color.green}_#{color.blue}" material = model.materials[material_name] || model.materials.add(material_name) material.color = color face.material = material current_angle += angle_step k += 1 end puts "Retângulos criados." end end UI.menu("Edit").add_item("Create Combined Variations") { CombinedVariations.create_variations }
-
RE: "Transforming Colors into Materials: A Plugin Inspired by Adobe Kuler"
I got what I wanted, but I had to do a python script to get what I wanted. Chatgpt helped me a lot. See the zip file attached in the link. There are the scripts, the images downloaded from the Adobe Color website, and an skp file with the results of everything I wanted.
https://www.dropbox.com/scl/fi/r02n9htl725rajx9ywtco/adobe.zip?rlkey=34xiw9xw8dykpest4g7lcq3va&dl=0
-
RE: "Transforming Colors into Materials: A Plugin Inspired by Adobe Kuler"
I tried to create the desired script with chatgpt, but I didn't get the desired result, the colors are simply not obtained from the desired points. As a goal this script should do this, but it cannot. Can anyone fix it?
This script extracts colors from a selected image in SketchUp. It resizes the image to 100cm x 150cm, moves it to the origin (0, 0, 0), and defines specific points in centimeters where colors will be extracted. It then converts the image to PPM format, reads the colors at the specified points, and creates materials in the SketchUp model based on these colors. Additionally, it adds guide points for debugging purposes. Finally, it provides a menu item under "Plugins" in SketchUp to execute the color extraction process.
require 'sketchup.rb' require 'tempfile' module ColorExtractor def self.extract_colors(image_path, points, width, height) colors = [] Tempfile.open(['image', '.ppm']) do |tempfile| # Converte a imagem para PPM usando o ImageMagick system("convert \"#{image_path}\" -resize 1600x2400! -depth 8 PPM:#{tempfile.path}") # Verifica se o arquivo foi criado corretamente unless File.exist?(tempfile.path) && !File.zero?(tempfile.path) UI.messagebox("Failed to convert image to PPM format.") return [] end # Lê o arquivo PPM File.open(tempfile.path, 'rb') do |file| header = file.readline # Tipo PPM (ex. P6) img_width, img_height = file.readline.split.map(&:to_i) # Dimensões da imagem max_value = file.readline # Valor máximo de cor # Converte os pontos em cm para pixels, considerando a origem no canto superior esquerdo pixel_points = points.map do |x, y| pixel_x = (x * img_width / width).to_i pixel_y = (y * img_height / height).to_i [pixel_x, img_height - pixel_y - 1] end # Extrai as cores dos pontos específicos pixel_points.each do |x, y| file.seek(3 * (y * img_width + x), IO::SEEK_SET) rgb = file.read(3) if rgb.nil? || rgb.size < 3 UI.messagebox("Failed to read color at point (#{x}, #{y}).") next end r, g, b = rgb.bytes colors << { :color => [r, g, b], :point => [x, y] } end end end colors end def self.create_materials_from_colors(model, colors, image_filename) materials = model.materials colors.each_with_index do |color_data, index| color = color_data[:color] point = color_data[:point] material_name = "#{image_filename}_Point#{index + 1}_#{point[0]}_#{point[1]}" material = materials.add(material_name) material.color = Sketchup::Color.new(color[0], color[1], color[2]) end end def self.create_guide_points(model, points) points.each do |x, y| point = Geom::Point3d.new(x.cm, (150 - y).cm, 0) # Ajustando para considerar o canto superior esquerdo model.active_entities.add_cpoint(point) end end def self.run model = Sketchup.active_model selection = model.selection if selection.empty? || selection.length != 1 || !selection.first.is_a?(Sketchup::Image) UI.messagebox("Please select a single imported image.") return end image_entity = selection.first image_path = image_entity.path image_filename = File.basename(image_path, ".*") unless File.exist?(image_path) UI.messagebox("The image file does not exist.") return end # Redimensiona a imagem para 100cm x 150cm image_entity.width = 100.cm image_entity.height = 150.cm # Move a imagem para a origem (0, 0, 0) tr = Geom::Transformation.new(ORIGIN) image_entity.transform!(tr) # Pontos em cm onde as cores serão extraídas, considerando a origem no canto superior esquerdo points = [ [18, 25], [50, 25], [82, 25], [18, 85], [50, 85] ] # Adiciona pontos guia para depuração create_guide_points(model, points) colors = extract_colors(image_path, points, 100, 150) if colors.empty? UI.messagebox("No colors extracted from the image.") return end create_materials_from_colors(model, colors, image_filename) UI.messagebox("Materials created from image colors.") end unless file_loaded?(__FILE__) UI.menu("Plugins").add_item("Extract Colors from Image") { self.run } file_loaded(__FILE__) end end
-
RE: "Transforming Colors into Materials: A Plugin Inspired by Adobe Kuler"
@Dave-R I felt like a complete idiot, I knew there was this function but I couldn't use it, I haven't used Sketchup lately.
-
"Transforming Colors into Materials: A Plugin Inspired by Adobe Kuler"
I would like a plugin that extracts the colors from a figure and transforms them into materials, but without images, just the pure colors. See the figures on the Adobe Kuler website.![alt text]
-
RE: [Plugin] Import OBJ with Materials v2.1 20131118
The inverse option, for export obj files from SU is possible?
Thanks anyway.... -
RE: [Plugin] Layers Panel 1.2.1
Can you reply the features of this plugin for 3dsmax to sketchup?
-
RE: [Plugin][$] JointPushPull Interactive - v4.8a - 30 Mar 24
Very good job! Thanks!
And about to make the object like before the operation by this plug in? Will be great... -
RE: [Plugin] Axis Cam v1.0.4
@renderiza said:
What would you suggest the controls would be for keyboard?
'w,a,s,d' for moving and mouse pointer for the target?Thanks!
I don't know if this is possible, but I want something that moves and rotate camera and the target at same time, up/down, left/right, front/behind, and rotate camera in the blue axis... All this with keyboard shortcuts, like the idea that I have send message to you before.