Hello folks. I’m sure you’ve heard about ChatGPT, an artificial inteligence able to deliver text and code. Well, the thing is I don’t know how to write a singe line of code, but after some requests, I finally get a fully functional ruby script made by the IA. It’s really simple, it paints the selected faces with random colors, but I find amazing how an AI can deliver a code that actually works.
ChatGPT delivered some code but it worked slow, so I asked if it was possible to improve it, and I got a faster and improved extension. What a time to be alive.
As a developers, what are your feelings about this kind of technology?
I’m attaching a .rbz file, and here’s the code I get from ChatGPT:
# Import the SketchUp API.
require "sketchup.rb"
# Define a class for the extension.
class RandomColorPaint
# This is a constant for the maximum value of a color component (256 in this case).
MAX_COLOR_VALUE = 256
# This is a custom method that will be called when the extension is activated.
def activate
# Get the current model and the selection set.
model = Sketchup.active_model
selection = model.selection
# Use the #grep method to find only the faces in the selection.
faces = selection.grep(Sketchup::Face)
# Select only the faces that are visible.
visible_faces = faces.select { |face| face.visible? }
# Loop over the visible faces and paint them with random colors.
visible_faces.each do |face|
# Generate a random color and set it as the material for the face.
color = generate_random_color
face.material = color
end
end
# This method generates a random color and returns it.
def generate_random_color
r = rand(MAX_COLOR_VALUE)
g = rand(MAX_COLOR_VALUE)
b = rand(MAX_COLOR_VALUE)
Sketchup::Color.new(r, g, b)
end
end
# Create a new instance of the RandomColorPaint class.
paint_tool = RandomColorPaint.new
# Get a reference to the Extensions menu.
extensions_menu = UI.menu("Extensions")
# Add a new menu item for your extension to the Extensions menu.
extensions_menu.add_item("Paint with random colors") do
# When the menu item is clicked, activate your extension.
paint_tool.activate
end
random-colors.rbz (813 Bytes)