top of page

Maya | Python | How to setup Maya python in VScode

  • Writer: Max Liu
    Max Liu
  • Dec 9, 2024
  • 1 min read

Updated: Dec 17, 2024

Final result, auto completion and Send Python code to Maya

To Activate Sent to Maya function

In the Maya script editor MEL Tab.

commandPort -name "localhost:7001" -sourceType "mel" -echoOutput;

You can also select a block of code in the editor and Right-click -> Send Code to Maya, this is based on the current working language (Mel or Python).

Install Extension as the picture shows

https://aps.autodesk.com/developer/overview/maya  Download the Dev kit from this website,

Create env for enabling highlight in VScode.

Done.


December, 2024 Update: Add a button on shelf.

Copy the code down below and pasted it into script editor, click the save script to shelf button.
Copy the code down below and pasted it into script editor, click the save script to shelf button.


import maya.cmds as cmds



def openCommandPort(*args):

    # This function will be called when the button is clicked.

    # It executes the MEL command to open the commandPort.

    cmds.commandPort(name="localhost:7001", sourceType="mel", echoOutput=True)



# If a window with the same name exists, delete it before creating a new one.

if cmds.window("cmdPortWin", exists=True):

    cmds.deleteUI("cmdPortWin")



# Create a new window

cmds.window("cmdPortWin", title="Open Command Port", widthHeight=(200, 75))



# Place a column layout inside the window to hold the button

cmds.columnLayout(adjustableColumn=True)



# Create a button that, when clicked, calls the openCommandPort function

cmds.button(label="Open Port 7001", command=openCommandPort)



# Display the window

cmds.showWindow("cmdPortWin")

Comments


bottom of page