python maya 2018 setup note

45
FOR MAYA Instruction of Installation guide 整理王. JP

Upload: lee-jungpyo

Post on 28-Jan-2018

201 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Python maya 2018 setup note

FOR MAYAInstruction of Installation guide

整理王. JP

Page 2: Python maya 2018 setup note

1. Compile to sip with PyQt5.2. How to setting up When you using PyCharm.

3. WING IDE

Overview

Page 3: Python maya 2018 setup note

List of Equipment.PyQt5 build

Python 2.7.11SIP 4.19.4PyQt gpl 5.9.1Install script as command scriptVisual studio 2015 or 2017 as visual studio command prompt.

PyCharm IDE setup for MayaMayaCharm

python connection of open port scriptpython connection of remote debug open port script

VSCode Setup for MayaPTVSD 3.0.0VSCode python extension

Overview

Page 4: Python maya 2018 setup note

1. COMPILE TO SIP WITH PYQT5.

Page 5: Python maya 2018 setup note

Install python version of 2.7.11• https://www.python.org/downloads/release/python-2711/

1. Compile to sip with PyQt5.

Page 6: Python maya 2018 setup note

Make Symbolic python.exe mayapy.exe

1. Compile to sip with PyQt5.

1. Run the command console as administrator.

2. Go to “C:\Program Files\Autodesk\Maya2018\bin”

3. Command : mklink python.exe mayapy.exe

Page 7: Python maya 2018 setup note

Install to Autodesk® Maya 2018 - Developer Kit (aka devkit)

• https://apps.autodesk.com/MAYA/en/Detail/Index?id=5525491636376351277&appLang=en&os=Win64&autostart=true

1. Compile to sip with PyQt5.

Page 8: Python maya 2018 setup note

Install to Autodesk® Maya 2018 - Developer Kit (aka devkit)

• List of Replacement directory

• All directory of devkitBase to MayaRoot

1. Compile to sip with PyQt5.

Page 9: Python maya 2018 setup note

Install to Autodesk® Maya 2018 - Developer Kit (aka devkit)

• C:\Program Files\Autodesk\Maya2018\devkit

1. Compile to sip with PyQt5.

Page 10: Python maya 2018 setup note

Modify to qt.confC:\Program Files\Autodesk\Maya2018\bin\qt.conf

1. Compile to sip with PyQt5.

Page 11: Python maya 2018 setup note

Your Maya environments pathhttps://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/Maya/files/GUID-228CCA33-4AFE-4380-8C3D-18D23F7EAC72-htm.html

MAYA_LOCATION

C:\Program Files\Autodesk\Maya2018

1. Compile to sip with PyQt5.

Page 12: Python maya 2018 setup note

Building to SIP• Check to exist this bat file as vcvarsall.bat

1. Compile to sip with PyQt5.

Page 13: Python maya 2018 setup note

Create setup.bat

1. Compile to sip with PyQt5.

@echo off

set MAYAVERSION=2018set ADSKQTVERSION=5.6.1set SIPVERSION=4.19.4set PYQTVERSION=5.9.1set MAYADRIVE=m:set BUILDDRIVE=v:

if exist %MAYADRIVE%\nul subst %MAYADRIVE% /dsubst %MAYADRIVE% "C:\Program Files\Autodesk\Maya%MAYAVERSION%"set MAYA_LOCATION=%MAYADRIVE%

set MAYAPYQTBUILD=%~dp0rem Removing trailing \set MAYAPYQTBUILD=%MAYAPYQTBUILD:~0,-1%

if exist %BUILDDRIVE%\nul subst %BUILDDRIVE% /dsubst %BUILDDRIVE% "%MAYAPYQTBUILD%"

set SIPDIR=%BUILDDRIVE%\sip-%SIPVERSION%set PYQTDIR=%BUILDDRIVE%\PyQt5_gpl-%PYQTVERSION%rem set ADSKQTDIR=%BUILDDRIVE%\qt-%ADSKQTVERSION%set QTDIR=%MAYA_LOCATION%

set PATH=%QTDIR%\bin;%PATH%set MSVC_VERSION=2015set MSVC_DIR=C:\Program Files (x86)\Microsoft Visual Studio 14.0set QMAKESPEC=%QTDIR%\mkspecs\win32-msvc%MSVC_VERSION%set _QMAKESPEC_=win32-msvc%MSVC_VERSION%

if ["%LIBPATH%"]==[""] call "%MSVC_DIR%\VC\vcvarsall" amd64

set INCLUDE=%INCLUDE%;%MAYA_LOCATION%\include\python2.7set LIB=%LIB%;%MAYA_LOCATION%\lib

Page 14: Python maya 2018 setup note

Building to SIP• Download to sip-4.19.4• https://sourceforge.net/projects/pyqt/files/sip/sip-4.19.4/• Create new directory as name of __sdkext into your “D” drive.

D:\__sdkext Uncompress sip-4.19.4 into __sdkext foler.

1. Compile to sip with PyQt5.

Page 15: Python maya 2018 setup note

Building to SIP• Create sip.bat

1. Compile to sip with PyQt5.

@echo offset XXX=%~dp0if ["%MAYAPYQTBUILD%"]==[""] call"%XXX%setup.bat"

pushd %SIPDIR%rem "%MAYA_LOCATION%\bin\mayapy" configure-ng.py --spec %_QMAKESPEC_%"%MAYA_LOCATION%\bin\mayapy" configure.pynmakenmake installpopd

Page 16: Python maya 2018 setup note

Building to SIP

• Install to Visual studio 2015 or 2017• Run to visual studio command prompt as administrator mode.

1. Compile to sip with PyQt5.

Page 17: Python maya 2018 setup note

Building to SIP

• Go to your __sdkext in command prompt.

1. Compile to sip with PyQt5.

Page 18: Python maya 2018 setup note

Building to SIP

• Execute setup.bat in command prompt• Execute sip.bat

1. Compile to sip with PyQt5.

• Checking to import sip in Maya2018

Page 19: Python maya 2018 setup note

Building to PyQt5

• Download PyQt5 source code.• https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.9.1/

1. Compile to sip with PyQt5.

Page 20: Python maya 2018 setup note

Building to PyQt5

• Create pyqt.bat

1. Compile to sip with PyQt5.

@echo offset XXX=%~dp0if ["%MAYAPYQTBUILD%"]==[""] call "%XXX%setup.bat"

set QMAKESPEC=%QTDIR%\mkspecs\%_QMAKESPEC_%if not exist "%QMAKESPEC%\qmake.conf" (

echo "You need to uncompress %MAYA_LOCATION%\mkspecs\qt-5.6.1_vc14-mkspecs.tar.gz !"goto end

)if not exist "%MAYA_LOCATION%\include\Qt\QtCore\qdir.h" (

echo "You need to uncompress %MAYA_LOCATION%\include\qt-5.6.1_vc14-include.tar.gz in %MAYA_LOCATION%\include\Qt !"goto end

)findstr /L /C:"Headers=include/Qt" "%MAYA_LOCATION%\bin\qt.conf" >nul 2>&1if ERRORLEVEL 1 (

echo "You need to edit %MAYA_LOCATION%\bin\qt.conf to use 'Headers=include/Qt'"goto end

)findstr /L /C:"-lqtmain -lshell32" "%QTDIR%\mkspecs\common\msvc-desktop.conf" >nul 2>&1if ERRORLEVEL 1 (

echo "You need to edit %QTDIR%\mkspecs\common\msvc-desktop.conf to use 'QMAKE_LIBS_QT_ENTRY = -lqtmain -lshell32'"goto end

)if not exist "%MAYA_LOCATION%\include\Qt\qtnfc.disabled" (

echo "You need to rename %MAYA_LOCATION%\include\Qt\qtnfc to %MAYA_LOCATION\include\Qt\qtnfc.disabled"goto end

)

pushd %PYQTDIR%rem "%MAYA_LOCATION%\bin\mayapy" configure-ng.py --spec %_QMAKESPEC_%"%MAYA_LOCATION%\bin\mayapy" configure.py --spec %QMAKESPEC% LIBDIR_QT="%QTDIR%\lib" INCDIR_QT="%QTDIR%\include\Qt" MOC="%QTDIR%\bin\moc.exe" --sip="%QTDIR%\Python\sip.exe" --sip-incdir="%QTDIR%\Python\include" -w --no-designer-pluginnmakenmake installpopd

:end

Page 21: Python maya 2018 setup note

Building to PyQt5

• Must check item.

1. Compile to sip with PyQt5.

"You need to rename %MAYA_LOCATION%\include\Qt\qtnfc to %MAYA_LOCATION\include\Qt\qtnfc.disabled"

C:\Program Files\Autodesk\Maya2018\include\Qt\qtnfc

Folder name to qtfnc.disabled

"You need to edit %QTDIR%\mkspecs\common\msvc-desktop.conf to use 'QMAKE_LIBS_QT_ENTRY = -lqtmain -lshell32'"

Page 22: Python maya 2018 setup note

Building to PyQt5

• Build to PyQt5 via visual studio command prompt.• Asking to license about python then just type to “yes”.

1. Compile to sip with PyQt5.

Page 23: Python maya 2018 setup note

Building to PyQt5

• Testing PyQt5 in Maya2018.

1. Compile to sip with PyQt5.

Page 24: Python maya 2018 setup note

• Testing PyQt5 in Maya2018.

1. Compile to sip with PyQt5.

import sys from PyQt5.QtWidgets import (QWidget, QToolTip, QPushButton) from PyQt5.QtGui import QFontclass Example(QWidget):def __init__(self):super(Example,self).__init__()self.initUI()

def initUI(self):QToolTip.setFont(QFont('SansSerif', 10))self.setToolTip('This is a <b>QWidget</b> widget')btn = QPushButton('Button', self)btn.setToolTip('This is a <b>QPushButton</b> widget')btn.resize(btn.sizeHint())btn.move(50, 50) self.setGeometry(300, 300, 300, 200)self.setWindowTitle('Tooltips')self.show()ex = Example()

Page 25: Python maya 2018 setup note

2. HOW TO SETTING UP WHEN YOU USING PYCHARM.

Page 26: Python maya 2018 setup note

Connecting to port

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

2. How to setting up When you using pycharm.

Page 27: Python maya 2018 setup note

Installing to MAYA CHARM.Using Alt+F7 to open properties window then go to Plugins.Go to Browse repositories.Searching to MayaCharm then install.

2. How to setting up When you using pycharm.

Page 28: Python maya 2018 setup note

Copy script then using into the Maya.import maya.cmds as cmdsif not cmds.commandPort(':4434', q=True):

cmds.commandPort(n=':4434')

2. How to setting up When you using pycharm.

Page 29: Python maya 2018 setup note

Select to interpreter from maya bin folder as python.exe Already We make link via mklink command between python and mayapy

2. How to setting up When you using pycharm.

Page 30: Python maya 2018 setup note

Additional setup your interpreter. Go to More… then organizing to Interpreter path like below.

2. How to setting up When you using PyCharm.

Page 31: Python maya 2018 setup note

MayaCharm Python Remote debugger setting.Go to “Run” then open to “Edit Configurations…”

2. How to setting up When you using PyCharm.

Page 32: Python maya 2018 setup note

MayaCharm Python Remote debugger setting.Adding to new configuration of MayaCharm Debugger

2. How to setting up When you using PyCharm.

Page 33: Python maya 2018 setup note

MayaCharm Python Remote debugger setting.Execute Debug Maya2018 via Alt + F5

2. How to setting up When you using PyCharm.

Page 34: Python maya 2018 setup note

3. WING IDE

Overview

Page 35: Python maya 2018 setup note

Install Wind-ide• https://wingware.com/

3. WING IDE FOR MAYA.

Page 36: Python maya 2018 setup note

Install Wind-ide

3. WING IDE FOR MAYA.

Page 37: Python maya 2018 setup note

1. Click to lower left side small bug icon then enable to Accept debug connections.2. Execute connection code via simple python code below.

3. WING IDE FOR MAYA.

import wingdbstubreload(wingdbstub)try:wingdbstub.Ensure()print 'Connected to WingIDE 6.0'except ValueError:print 'Could NOT connect to wingIDE'

Page 38: Python maya 2018 setup note

Create server script into your %MAYA_SCRIPT_PATH%mayaWingServer.py

3. WING IDE FOR MAYA.

import sysimport socketimport threading

import maya.utils as muimport maya.OpenMaya as om

import executeWingCode

#Global variablesPORT = 6000 # Needs to be the same value as authored in wingHotkeys.py below.SIZE = 1024BACKLOG = 5

#Functionsdef processDataInMaya(data):try:# If we don't evaluate in maya.util.executeInMainThreadWithResult(), Maya can crash, and that's no good.mu.executeInMainThreadWithResult(executeWingCode.main, data)except Exception, e:om.MGlobal.displayError('Encountered exception: %s'%e)

def server(processFunc=processDataInMaya, port=PORT, backlog=BACKLOG, size=SIZE):host = ''s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)try:s.bind((host,port))except:print 'Tried to open port %s, but failed: Its probably already open\n'%portreturn

s.listen(backlog)print 'Starting Python server, listening on port %s...\n'%portwhile True:client, address = s.accept() # client is a socket objectdata = client.recv(size)if data:processFunc(data)client.close()

def startServer():threading.Thread(target=server).start()

Page 39: Python maya 2018 setup note

Start python server via simple python script at below.

3. WING IDE FOR MAYA.

import maya.cmds as cmdscmds.evalDeferred('import mayaWingServer; mayaWingServer.startServer()', lowestPriority=True)

Page 40: Python maya 2018 setup note

Configuration of User hot key3. WING IDE FOR MAYA.

Create wingHotkeys.py into ‘C:\Users\<your_username>\AppData\Roaming\Wing IDE 6\scripts\‘import wingapiimport socketimport osimport tempfiledef getWingText():editor = wingapi.gApplication.GetActiveEditor()if editor is None:returndoc = editor.GetDocument()start, end = editor.GetSelection()txt = doc.GetCharRange(start, end)return txtdef send_to_maya(language):# The port the sever is listening on in mayaWingServer.py :commandPort = 6000if language != 'mel' and language != 'python':raise ValueError('Expecting either 'mel' or 'python'')txt = getWingText()if language == 'mel':if not txt.endswith(';'):txt += ';'# Cross-platform way to get a temp dir:tempDir = tempfile.gettempdir()tempFile = os.path.join(tempDir, 'wingData.txt')f = open(tempFile, 'w')f.write(txt)f.close()mSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # works in 2013...# Now ping Maya over the command-porttry:mSocket.connect(('localhost', commandPort)) # 2016, mac# Send our code to Maya:# It is intercepted via the function processDataInMaya(), created via mayaWingServer.pymSocket.send(language)except Exception, e:print 'Send to Maya fail:', emSocket.close()def python_to_maya():send_to_maya('python')def mel_to_maya():send_to_maya('mel')

Page 41: Python maya 2018 setup note

Configuration of User hot key3. WING IDE FOR MAYA.

Create executeWingCode.py into %MAYA_SCRIPT_PATH%

import __main__import osimport tempfileimport maya.OpenMaya as omdef main(codeType):# Cross-platform way to get a temp dir:tempDir = tempfile.gettempdir()tempFile = os.path.join(tempDir, 'wingData.txt').replace('\\', '/')if os.access(tempFile , os.F_OK):# Print the lines from the file in Maya:with open(tempFile, 'r') as f:for line in f.readlines():print line.rstrip()print '\n',if codeType == 'python':# execute the file contents in Maya:with open(tempFile , 'r') as f:exec(f, __main__.__dict__, __main__.__dict__)elif codeType == 'mel':melCmd = 'source %s'%tempFileom.MGlobal.executeCommand(melCmd, True, True)else:print 'No Wing-generated temp file exists: ' + tempFile

Page 42: Python maya 2018 setup note

Configuration of User hot key3. WING IDE FOR MAYA.

Go to Keyboard Personality -> Configure Tab Key…Press to Insert then set up to Key with Command.Command is ‘python_to_maya’

Page 43: Python maya 2018 setup note

Configuration of User hot key3. WING IDE FOR MAYA.

Go to Maya command line to type to code at below because When you receive from Wing-Ide that must open port local host with port of 6000.

cmds.commandPort(name="127.0.0.1:6000", close=True, echoOutput=True)

cmds.commandPort(name="127.0.0.1:6000", close=True, echoOutput=True)

Closing port command at below

Page 44: Python maya 2018 setup note

Configuration of User hot key3. WING IDE FOR MAYA.

Execution test

import maya.cmds as cmdscmds.polySphere(r=5)

Page 45: Python maya 2018 setup note

Auto Complete.3. WING IDE FOR MAYA.

Go to ‘Edit > Preferences > Source Analysis’

In the ‘Interface File Path‘, add the ‘pi‘ folder you find inside the pymel you just extracted. TO be precise, it can be found in ’devkit/other/pymel/extras/completion/py’. For added measure, I added both sub-folders inside the pi folder as well.