Maya Python development

Basic operation of Maya

Create Object, Maya Roam Alt+

At the bottom of Maya is Mel on the far right, with a small button

Maya script editor, Maya right-click operation sliding

Switch to point mode: right click to switch to fixed point mode Press F to switch to the center object mode of the object?

Maya scripting

Function

The Maya program runs in a serial structure, which is consistent with Unity; the UI button executes the script; the operation will be realized in the script editor

The logs displayed by the script editor are mel statements.

Check the help of maya, check the shortcut prompt in the command, and check the mel to look like a linux command

mel script execution of select -r select -add

When writing a script, if you encounter a command, complete it on the interface first, and then write python according to the mel script according to the prompt of the mel script. The script editor directly clicks to run will clear the following code, click "" to execute without clearing the content

Operate tranform to modify attributes. The most used in maya is setAttr to create a camera and modify the focal length of the camera.

The uniqueness of the name of the Object,

Drag in the middle to form a parent-child relationship, and find the only object through the path Problem: the same name cannot appear at the same level, and the name will be automatically changed inside Maya

mel to python

There are rules to follow, Maya is like a linux command or function,

import maya
#import maya.cmds as cmds

values = maya.cmds.ls()
maya.cmds.setAttr(...)

# mel转python可能的两种形式
# select -tgl xxx
maya.cmds.select('xxx', tgl=True)
#maya.cmds.select(tgl='xxx') # 有可能的形式,但是不一定正确

Single-step execution is not necessarily efficient with selective partial execution

Basic process

1. Do it once 2. Look at mel 3. mel to python

UI changes

Problem: child nodes

import maya
maya.cmds.setAttr("pShere2.vtx[251]", 10,10,10)

It is possible that there is in the mel,

question:

select_object = maya.cmds.ls(sl=True)

root node,

Plugins provide deeper interfaces

Node graph

Maya DAG, through a brother in the window to view the mesh node according to the attribute, pass it to the normal node, pass it to

Our plug-in needs to write nodes. With a certain input, the next step is to output, and the calculation is performed only when the current node is set to be dirty as defined by the protocol; how to write the plug-in to control the calculation.

speed problem

How to block useless nodes, edit - "delete all by type -" delete history, there is no way to make changes to him and can't delete history?

Maya's frame rate can be set

PyCharm configures the Maya development environment

Maya Python

Maya 2018 uses Python 2.7 by default. The functions supported by Python 2.7 can be supported by Maya through Python development.
In PyCharm, set the following settings

Settings->Project Interpreter->齿轮->Add local
System Interpreter->选择目录
C:\Program Files\Autodesk\Maya2018\bin\mayapy.exe

First add the path to the python path, PYTHONPATH=xxxx restart Maya, you can import the package name such as the tool shelf document/maya/2015-x/zh-cn/prefs/shelves

project inteprot pycharm systemEnv = mayapy.exe

Maya API Smart Tips

When we configure mayapy, we do not have intelligent code hints in PyCharm.

download devkit

First, download the Maya Developer Kit according to the following link , you need to log in to Autodesk, and enter Maya Developer Kit in the search box

setup devkit

Setting->Project Interpreter->齿轮->Show All...

Open the Project Interpreters window, click the bottom icon on the right to pop up the Interpreter Paths window, click +.

# 由于devkit放到build目录的配置如下
C:\build\maya-devkit\Maya2018-DEVKIT_Windows\devkitBase\devkit\other\pymel\extras\extras\completion\py\

Remove original prompt

In the Interpreter Paths window, find the C:\Program Files\Autodesk\Maya2018\Python\Lib\site-packagesoption and click Delete. Save all settings to pop up code prompts

After downloading, unzip it to any directory,

Debug plugin MayaCharm

MayaCharm

MayaCharm Go

PyCharm install MayaCharm

Setting it up in PyCharm

File->Settings->Plugins

Enter MayaCharm in the search box, click Web Search, click Install and restart PyCharm

Maya install service port

Create a file in the project, userSetup.pythe key is PYTHONPATH in the environment variable, and the value is the project directory

import logging
logging.info('Maya`s userSetup.py')

# MayaCharm Plugin
import maya.cmds as cmds
if not cmds.commandPort(':4434', q=True):
    cmds.commandPort(n=':4434')

# do something before maya run

Restart Maya, you can see the Maya Output Window input as follows

root : INFO : Maya`s userSetup.py
...

Indicates that userSetup.py is initialized successfully

MayaCharm debugging

Warning: Since the editor is using the PyCharm Professional version, the MayaCharm Debugger will be available
in PyCharm. After Run->Run/Debug Configurations->Add->MayaCharm Debugger is
created, you must select Attach Debug and execute file and select the Python file to be executed. Then you can run
Debug. You must first break the breakpoint, and then click to run debug. Note: The py file will not be executed directly here. It will jump to the server request first, and then jump to the subsequent breakpoint.

How to Write a Tool Shelf

Right-click on the far left to create a new tool shelf, you can edit the tool shelf, you can select the label of the icon, click Save All Tool Shelves, you can see the path of the tool shelf

WHAT

mel provided by the Maya interface

Independence

import maya
maya.cmd.window('test2')
maya.cmds.showWindow(test)

The new version can pass python, the old version can only use mel

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324390445&siteId=291194637