top of page
  • Writer's pictureAlexandre Alin

Generate a Maya modeling tool with Chat GPT

Updated: Jun 30, 2023

Maya is a popular 3D modeling and animation software used by professionals in the film, gaming, and advertising industries. Python is one of the languages supported by Maya, and it provides a powerful way to automate repetitive tasks and extend the functionality of the software. In this blog, we'll explore how ChatGPT can help you create a Maya Python script that makes modeling easier by snapping two selected vertices together.

Before we dive into the details, let's take a quick look at what ChatGPT is and how it works. ChatGPT is a large language model developed by OpenAI that can generate human-like responses to natural language input. It's based on the GPT-3.5 architecture and has been trained on a massive dataset of text from the internet.

This makes it a powerful tool for generating code and scripts, among other things.

To create our Maya Python script, we'll start by defining the problem we want to solve. When working with 3D models, it's often necessary to align vertices or edges to create a smooth and seamless surface. In some cases, it can be challenging to get the alignment just right, especially when working with complex models.

Our goal is to create a tool that simplifies this process by snapping two selected vertices together in the middle of the distance between them.

import maya.cmds as cmds

# Get the selected vertices
selected =, flatten=True)

# Make sure we have exactly 2 vertices selected
if len(selected) != 2:
cmds.warning("Please select exactly 2 vertices.")
raise RuntimeError("Incorrect selection.")

# Get the positions of the selected vertices
pos1 = cmds.pointPosition(selected[0], world=True)
pos2 = cmds.pointPosition(selected[1], world=True)

# Calculate the midpoint between the two vertices
midpoint = [(pos1[0] + pos2[0])/2, (pos1[1] + pos2[1])/2, (pos1[2] + pos2[2])/2]

# Move the vertices to the midpoint position
cmds.move(midpoint[0], midpoint[1], midpoint[2], selected, absolute=True)

To use this code, simply copy and paste it into the Script Editor in Maya and run it while two vertices are selected. The selected vertices will then be snapped together at the midpoint of their distance.

268 views0 comments

Recent Posts

See All
bottom of page