ChatGPT - Maya city generator v001

PHOTO EMBED

Thu Dec 08 2022 12:37:24 GMT+0000 (Coordinated Universal Time)

Saved by @HiveHD #python #maya2023

import maya.cmds as cmds
import random
import math

# Create the City_GRP group
cmds.group(name="City_GRP", empty=True)

# Create 2000 cubes with random X, Z, and Y scale
for i in range(1, 2001):
    # Create a cube with the "Building_####_GEO" name
    cube = cmds.polyCube(w=1, h=1, d=1, name="Building_{:04d}_GEO".format(i))

    # Generate random X and Z coordinates with a maximum distance of 100 units from the world origin
    x_coord = random.uniform(-100, 100)
    z_coord = random.uniform(-100, 100)

    # Calculate the distance of the cube from the origin using the Pythagorean theorem
    distance = math.sqrt(x_coord**2 + z_coord**2)

    # Generate random scale values for the X, Z, and Y axes, with a max X and Z scale of 6 and a max Y scale of 20
    x_scale = random.uniform(1, 6) / (distance / 10)
    z_scale = random.uniform(1, 6) / (distance / 10)
    y_scale = random.uniform(1, 20) / (distance / 10)

    # Randomize the cube's scale using the cmds.scale command
    cmds.scale(x_scale, y_scale, z_scale, cube)

    # Position the cube at the random X and Z coordinates
    cmds.setAttr(cube[0] + ".translateX", x_coord)
    cmds.setAttr(cube[0] + ".translateZ", z_coord)

    # Add the cube to the City_GRP group
    cmds.parent(cube[0], "City_GRP")
content_copyCOPY

Base script for generating a city in Maya 2023

https://chat.openai.com/chat