Git Product home page Git Product logo

vscode-maya's Introduction

Maya Extension for Visual Studio Code

Version Installs Downloads Ratings

Average time to resolve an issue Percentage of issues still open

A Visual Studio Code extension with support for coding for Maya.

Features

  • Syntax Highlight MEL scripts.

  • Hierarchical document tree in the outline view.

  • Breadcrumbs support.

  • Autocomplete MEL commands as you type ( along with flag info )

    Autocomplete MEL commands as you type

  • Autocomplete MEL variables as you type

    Autocomplete MEL variables as you type

  • Send code to Maya via command port (MEL or Python).

    Send code to Maya via command port

  • Support auto closing brackets, quotes and ticks

    Syntax Highlight MEL scripts

Useful commands

Open the Command Palette (Command+Shift+P on macOS and Ctrl+Shift+P on Windows/Linux) and type in one of the following commands:

Command Description
Maya: Send Python Code to Maya Send Python code from current editor in Maya.
Maya: Send MEL Code to Maya Send MEL code from current editor in Maya.

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).

Update for Maya 2022 and above.

Option for Maya 2022 and above

Opening the correct ports for Send to Maya Commands.

To open the correct ports in maya, you can use the following code.

Note: If your using a extension version higher than 0.9, then MEL and Python code use the same port in maya.

In the Maya script editor MEL Tab.

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

Snippets

Prefixes Description
if Code snippet for an if statement
if/else Code snippet for an if statement with else
elseif Code snippet for an else if
else Code snippet for an else
do/while Code snippet for a do while loop
switch/case Code snippet for a switch case
proc Code snippet for a procedure
proc(global) Code snippet for a global procedure
for/in Code snippet for a for loop
for Code snippet for a for loop with counter
while Code snippet for a for while loop

Requirements

Autodesk Maya tested using Maya 2016 Windows and Linux but should work with all versions.

Issues, feature requests, and contributions

  • If you come across a problem with the extension, please file an issue
  • Contributions are always welcome!
  • Any and all feedback is appreciated and welcome!
    • If someone has already filed an issue that encompasses your feedback, please leave a 👍/👎 reaction on the issue
    • Otherwise please file a new issue

Release Notes

See CHANGELOG.md

See Recent Releases

Enjoy!

vscode-maya's People

Contributors

artbycrunk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-maya's Issues

possible to expose a user definable setting to send to port other than 7001?

hi,

great extension! thanks!

i ran into an issue where trying to open port 7001 resulted in a windows 10013 error. turns out that it could have been antivir or firewalls but it ended up being that a sentinel keys server program was also occupying ports 7001 and 7002 to do its thing for one of my graphics programs using the sentinel system (maybe fusion?).

anyway, if i disable the key server, i can use your extension to send stuff to maya no problem. but i was wondering if it was possible to allow the user to define other ports in your extension since all kinds of hardware and software can take ownership of ports and not leave it available to maya.

anyway, thanks again for a great extension!

jin

Better setup tutorial

I see that it could be a cool plugin from the videos, but for a newbie to VS Code it is not apparent how to get this to work. A setup tutorial with example files would be greatly appreciated!

Thanks

If the script exists Chinese, when sent to maya will be garbled, how to fix it?

code like here:
print '这是中文'

send python code to maya:

MayaCode [09:47:06][INFO]	 Already active : Port 7001 on Host localhost for python
MayaCode [09:47:06][INFO]	 Sending selected python code to maya
MayaCode [09:47:06][INFO]	 Writing text to C:/Users/lingy/AppData/Local/Temp/MayaCode.py...
MayaCode [09:47:06][INFO]	 Executing python("execfile('C:/Users/lingy/AppData/Local/Temp/MayaCode.py')")...
MayaCode [09:47:06][INFO]	 python("execfile('C:/Users/lingy/AppData/Local/Temp/MayaCode.py')")
MayaCode [09:47:06][INFO]	 Sent python code to Maya...
MayaCode [09:47:06][RESPONSE]	 
MayaCode [09:47:06][RESPONSE]	 杩欐槸涓枃

Maya code send pythone

Hi
It looks like in maya code "Send Python to Maya" doesnt work. On other hand "Send MEL to Maya works" . Do you know maybe for any workarond or fix ?

Thank you

Add support for Maya 2022 with Python 3.7

When I try to execute Send Python Code to Maya I get this error.

`

# Exception happened during processing of request from# ---------------------------------------- # ---------------------------------------- ('127.0.0.1', 63876) # Traceback (most recent call last): # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 316, in _handle_request_noblock self.process_request(request, client_address) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 347, in process_request self.finish_request(request, client_address) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 360, in finish_request self.RequestHandlerClass(request, client_address, self) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 720, in __init__ self.handle() # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\maya\app\general\CommandPort.py", line 134, in handle self.wfile.write(self.server.commandMessageQueue.get() + self.resp_term) # # File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 799, in write self._sock.sendall(b) # TypeError: a bytes-like object is required, not 'str'
`

f-string line send python to maya 2023 does not work

In maya 2023 ( python 3.9) f-string is not working when using Send Python Code to Maya

To Reproduce
Steps to reproduce the behavior:

  1. open maya 2023 and open ports
  2. run
MC.commandPort(name=":7001", sourceType="mel", echoOutput=True)
MC.commandPort(name=":7002", sourceType="python",echoOutput=True)
  1. send this from vscode
x=1
print(f"your value: {x}")

and error is

# Error: line 1: invalid syntax
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
#   File "<string>", line 3
#     print(f"your value: {x}")
#                            ^
# SyntaxError: invalid syntax # 

Expected behavior
print your value: 1

Screenshots
N.A

Desktop (please complete the following information):

  • OS: centos 7.9

Provide a configuration to modify editorLangId == 'mel' in when column when configuring hotkeys

I am setting file association in vscode for *.mel to c as a trick to use all the features like ctrl+alt+o and jump to mel global proc definition by ctrl+click, but it stops me from being able to use the hotkeys. As in vscode the shortcuts configuration page, the When column is hardcoded to be editorTextFocus && editorLangId == 'mel'

Screenshot from 2023-04-11 23-26-50

Screenshot from 2023-04-11 23-31-29

I hope the plugin configuration can offer a setting which allows me to choose what langid to use for the when, so that even for c language type, I can still use hotkey to send code to maya.

Compatibility issue with Maya 2022

Description

There seems to be issues when running this through maya 2022. I tested with maya 2020 and it works just fine, but 2022 blocks at an error code and can't send through commands to Maya.

To Reproduce
Steps to reproduce the behavior:

  1. Execute "commandPort -name "localhost:7001" -sourceType "mel" -echoOutput;" in maya's script editor
  2. Go to visual studio code
  3. Type a test code print("hello")
  4. First time around: See code output in script editor along with error code
  5. Any further attempts: Error code

Expected behavior
Command output in the script editor

Result

 # TypeError: a bytes-like object is required, not 'str'
# ----------------------------------------
# ----------------------------------------
# Exception happened during processing of request from('127.0.0.1', 50484)
# Traceback (most recent call last):
# #   File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 316, in _handle_request_noblock
    self.process_request(request, client_address)
# #   File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 347, in process_request
    self.finish_request(request, client_address)
# #   File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
# #   File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 720, in __init__
    self.handle()
# #   File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\maya\app\general\CommandPort.py", line 134, in handle
    self.wfile.write(self.server.commandMessageQueue.get() + self.resp_term)
# #   File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 799, in write
    self._sock.sendall(b)

Additional context
The code did go through once, but I couldn't get it to print "hello" after, even after rebooting maya, visual studio code and resetting the port using the command found in visual studio code when I close maya:
commandPort -n "localhost:7001" -stp "mel" -echoOutput;

Settings

Windows
Edition: Windows 10 Home
Version: 21H2
OS build: 19044.1706

Maya
Version: Autodesk MAYA 2022

MayaCode
Version: v1.5.0

Cannot import maya module

I reseted my computer, installed maya 2020 and vscode with the extensions I used to have.

But when I create the python file in vscode

the module "maya could not be resolved"
so I cannot make use of the autocomplete function of the extension, I tried multiple times and even tried on other clean windows intalls to not avail

I have tried:
commandPort -n "localhost:7001" -stp "mel" -echoOutput;

2023-06-23 17_06_10-Test_Maya_01 py - VS Code (Workspace) - Visual Studio Code

Sending Maya is not working

Describe the bug

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

----------------------------------------# ----------------------------------------

Exception happened during processing of request from('127.0.0.1', 56580)

Traceback (most recent call last):

# File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 316, in _handle_request_noblock

self.process_request(request, client_address)

# File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 347, in process_request

self.finish_request(request, client_address)

# File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 360, in finish_request

self.RequestHandlerClass(request, client_address, self)

# File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 720, in init

self.handle()

# File "C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\maya\app\general\CommandPort.py", line 137, in handle

self.wfile.write(self.server.commandMessageQueue.get() + self.resp_term)

# File "C:\Program Files\Autodesk\Maya2022\Python37\lib\socketserver.py", line 799, in write

self._sock.sendall(b)

TypeError: a bytes-like object is required, not 'str'

To Reproduce
Steps to reproduce the behavior:

  1. Installed MayaCode extension
  2. Click on 'Send Python code to Maya'
  3. See error

Expected behavior

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser chrome
  • Version 10.0.22621 Build 22621

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

An unicode error on new version of maya,(like 2024.1)

I am a long time user since maya 2018.

for now, I changed my maya, update to 2024 version 1.

software lang environment was english.
windows unicode is GB2312/GBK
my code was useing UTF-8

I just type alt+m, send those UTF-8 code to maya. there was appeared.

Error: line 1: UnicodeDecodeError: file line 1: 'gbk' codec can't decode byte 0xaa in position 1026: illegal multibyte sequence

I need your help.
mayabe there was some things I have been missed. you can ask any thing what I can do.

cheers.

Maya 2024.1

Please make it work with the latest maya version (at the moment it's 2024.1)
Thanks

Auto complete for command parameters is not working

I just set up the extension on a new windows machine using the late Code release. I have Maya 2024 installed on the same machine.

While I get suggestions for commands, I don't get them for the commands parameters.

To reproduce the issue:

  • type sphe, accept sphere command suggestion with enter
  • attempting to do the same with parameters for the sphere, by typing -, will just show suggestions for mel commands instead

I am expecting to get parameter suggestions for the sphere command such as edit, query, name etc etc

I recorded an example of my screen:
|300

Any help would be greatly appreciated!

Is there any way to use this extension at Maya start up?

Is your feature request related to a problem? Please describe.
This extension works. But need to setup every time new session.

Describe the solution you'd like
If I don't need to manually run the line of code to open port every time open a new Maya or vs code session that will be great!

If there already a way to do it like setup a user setup file etc. please let me know.

Error: line 1: Could not create command port: localhost:7001 (name is invalid).

Describe the bug
When trying to open the port on Mac OS with Maya LT, I receive this error.
Error: line 1: Could not create command port: localhost:7001 (name is invalid).

To Reproduce
Steps to reproduce the behavior:

  1. Open the script editor:
    Run this command:
    commandPort -name "localhost:7001" -sourceType "mel" -echoOutput;

Desktop (please complete the following information):

  • OS: Mac OS
  • Maya LT 2020 and Maya LT 2019
  • Version [e.g. 22]

I feel like if the port was already in use, I could find a workaround, but the name is invalid is weird for me.

Thanks in advance.

How can I enable formatting with this extension...

I am just wondering how to code format with this extension in vscode, can't figure it out. Does this extension include formatting?

I posted a question on stackoverflow https://stackoverflow.com/questions/65288089/format-another-language-type-mel-using-js-formatting-in-vscode

Trying to use formatting of other languages on .mel files doesn't seem to work, I tried to use Perl, TCL but nothing seems to get formatting to work in vscode for .mel files. I just keep getting "no formatter installed for .mel" etc.
Any pointers would be great, thanks.
Alan.

NameError: name 'python' is not defined

Hi~ i use the extension with maya2020 , and i got the message after i sent the code: "NameError: name 'python' is not defined".

I have checked your source code and found that you warpped the executed code with "python()" after code type checking, is that the reason maya cannot run with it. Not so familiar with maya python, thx for your great job and hope for reply~

Add autocomplete for MEL variables

feedback from a user by email.
As in SublimeText, could you add a function, which when we type a variable
name the extension proposes the names of variables already existing in our script.

Send All Code To Maya

I would like to send all of the code to Maya without having to select lines, is that possible?

Print statements not appearing in MayaCharm

I want to know if there is a way to print the translation information from Maya that I code in Visual Studio Code. I was able to send command to Maya to create some geometry stuffs. I do not see any output from print statements. If I were to run Python embedded in Maya, I would see the print statements. But not the external editor of VSC, your advice will be appreciated. I think the problem is that I was not able to receiving info from Maya to VSC but I was able to send information to Maya.

Thanks in advance

Output from Maya in VSCODE and debug capabilities

First, I want you to know that I like this extension a lot.
I have 2 questions:

  1. Is it possible to see the output from Maya inside VSCODE?
  2. Is there any plan to add MEL debugging capabilities to this extension?

I created a file named userSetup.mel in folder C:\Users\<username>\Documents\maya\2020\scripts\ containing
commandPort -name "localhost:7001" -sourceType "mel" -echoOutput;
commandPort -name "localhost:7001" -sourceType "python" -echoOutput;
but I can't see the output inside VSCODE.

Also, it would be GREAT to be able to debug MEL scripts.

Thank you.

Output line numbers are off by 1

Describe the bug
In the output window, for Code or for Maya, whenever line numbers are mentioned for python scripts they are always off by 1.

To Reproduce

  1. Open a new python script
  2. Type asdasdasd
  3. Send script to Maya
  4. Read output line number and compare to line number in script

Expected behavior
The line numbers should match

Screenshots
image

Additional context
It's because of the utf8 encoding header written to MayaCode.py

Strange log output in Maya

I'm seeing this output in the Maya script editor when trying to debug:

// Error: Content-Length: 79; //
// Error: Line 1.15: Syntax error //
// Error: {"command":"disconnect","arguments":{"restart":false},"type":"request","seq":2}; //
// Error: Line 1.10: Syntax error //
// Error: //
// Error: Line 2.0: Syntax error //
// Error: Content-Length: 346; //
// Error: Line 1.15: Syntax error //
// Error: {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"python","pathFormat":"pa€ //
// Error: Line 1.10: Syntax error //
// Error: //
// Error: Line 2.0: Syntax error //

Not sure what it is happening here.

issue importing the maya script editor

I was trying to us the MEL command
commandPort -name "localhost:7001" -sourceType "mel" -echoOutput;
.IT seems to work except when I try to use the send to maya in visual studio it gives me this error message. I am still new to this stuff so I'm not sure if its something I did

----------------------------------------

Exception occurred during processing of request from ('127.0.0.1', 51457)

Traceback (most recent call last):

# File "C:\Program Files\Autodesk\Maya2025\Python\Lib\socketserver.py", line 317, in _handle_request_noblock

self.process_request(request, client_address)

# File "C:\Program Files\Autodesk\Maya2025\Python\Lib\socketserver.py", line 348, in process_request

self.finish_request(request, client_address)

# File "C:\Program Files\Autodesk\Maya2025\Python\Lib\socketserver.py", line 361, in finish_request

self.RequestHandlerClass(request, client_address, self)

# File "C:\Program Files\Autodesk\Maya2025\Python\Lib\socketserver.py", line 755, in init

self.handle()

# File "C:\Program Files\Autodesk\Maya2025\Python\Lib\site-packages\maya\app\general\CommandPort.py", line 134, in handle

self.wfile.write(self.server.commandMessageQueue.get() + self.resp_term)

# File "C:\Program Files\Autodesk\Maya2025\Python\Lib\socketserver.py", line 834, in write

self._sock.sendall(b)

TypeError: a bytes-like object is required, not 'str'

----------------------------------------

ctrl+shift+o go to symbol support ?

Is your feature request related to a problem? Please describe.
When scrubbing long files, a go to symbol feature might be handy

Describe the solution you'd like
support it like other languages

Describe alternatives you've considered

Additional context

not running code properly

Hi! I have a simple code, that suppose to create a set of references.
Once I run it directly in Maya or from sublime it works fine, but once I send it through VScode it doesn't create a reference although part of the code run well.
turntable.zip

Maya command highlighting within .py

Hi there I'm a newb when it comes to code writing and same to Visual Studio Code. I was wondering if there is a way to be working in a python script and still get the highlighting and the mel definitions and stuff. For me it only works inside a mel command. I'm sure there's a way and I'm just a fool for not finding it. I've tried googling it and I can't figure out the right question to ask. Sorry if this is posted in the wrong spot!

can't send Non-ASCII character, even though they're in the comments

code like here:
print("python code") # 這是中字
send python code to maya, error in maya script editor:
# Error: line 1: SyntaxError: file <maya console> line 1: Non-ASCII character '\xe6' in file C:/Users/Lee/AppData/Local/Temp/MayaCode.py on line 6, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details #
maybe its the solution:
when send code to maya, temporarily remove all comments.

Incorrect MEL procedure name extraction for some proc types

When listing a MEL file's procedures in the Outline view panel, the name of a proc seems to be retrieved incorrectly for some procedure return types. For example: "proc float myFloatFunction(float $input)" will have its name listed as "float" instead of "myFloatFunction". The same applies for float[], int, int[], bool, bool[]. "string" and "string[]" type procs do detect the proc name though.

Maybe it's related to this line in extension.ts? (Line 116)

let procTypes = ["string", "string[]"]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.