Message 1 of 7
chatGPT writes a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm not a coder at all so I never got into MAXscript. But now that chatGPT can write code for you this is becoming very interesting to me. I've been experimenting with some things I want chatGPT to write for me and it looks great but there are small errors in the code which I cannot fix because I'm not a coder.
Do you guys have experience with chatGPT writing code for you and how did you solve the potential errors?
This is the code chatGPT wrote for me:
-- Create a window for the script
window = newRolloutFloater "Cube Grid Generator" 200 200
-- Create a rollout for the script
rollout = newRollout "Cube Grid Generator" window
-- Create a button to generate the cubes
generateButton = button rollout "Generate Cubes"
-- Create a button to set the spacing
spacingButton = button rollout "Set Spacing"
-- Create a button to open the material editor
materialButton = button rollout "Add Material"
-- Create variables for cube size, grid size, and spacing
global cubeSize = 10
global gridSize = 26
global spacing = 1
-- Create a function to generate the cubes
fn generateCubes =
(
-- Create an array of cubes
cubes = #()
-- Create the grid of cubes
for i = 0 to gridSize-1 do
(
for j = 0 to gridSize-1 do
(
-- Create a new cube
newCube = box()
-- Position the cube in the grid
newCube.pos.x = (i * (cubeSize + spacing)) + (spacing / 2)
newCube.pos.z = (j * (cubeSize + spacing)) + (spacing / 2)
-- Add the cube to the array
append cubes newCube
)
)
-- Create a new plane
newPlane = plane()
-- Scale the plane to the same size as the grid
newPlane.scale = [gridSize*(cubeSize+spacing),1,gridSize*(cubeSize+spacing)]
-- Position the plane on top of the cubes
newPlane.pos.y = (cubeSize + spacing) / 2
)
-- Create a function to set the spacing
fn setSpacing =
(
-- Get the new spacing value from the user
spacing = inputBox "Enter the spacing (in cm):" "Spacing"
-- Convert the spacing to a float
spacing = spacing as float
)
-- Create a function to open the material editor and assign a selected material to the plane
fn addMaterial =
(
-- Open the material editor
openMaterialEditor()
-- Assign the selected material to the plane
newPlane.material = getCurrentMaterial()
)
-- Add the functions to the buttons
on generateButton pressed do generateCubes()
on spacingButton pressed do setSpacing()
on materialButton pressed do addMaterial()
-- Add the buttons to the rollout
add generateButton rollout
add spacingButton rollout
add materialButton rollout
-- Add the rollout to the window
addRollout rollout window
So the first error you get is that rollout cannot be a variable name. I changed that but it still doesn't work.
-Joep