python maya 2018 setup note

Post on 28-Jan-2018

201 Views

Category:

Engineering

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

FOR MAYAInstruction of Installation guide

整理王. JP

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

3. WING IDE

Overview

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

1. COMPILE TO SIP WITH PYQT5.

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

1. Compile to sip with PyQt5.

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

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.

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.

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

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

1. Compile to sip with PyQt5.

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

1. Compile to sip with PyQt5.

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.

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

1. Compile to sip with PyQt5.

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

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.

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

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.

Building to SIP

• Go to your __sdkext in command prompt.

1. Compile to sip with PyQt5.

Building to SIP

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

1. Compile to sip with PyQt5.

• Checking to import sip in Maya2018

Building to PyQt5

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

1. Compile to sip with PyQt5.

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

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'"

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.

Building to PyQt5

• Testing PyQt5 in Maya2018.

1. Compile to sip with PyQt5.

• 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()

2. HOW TO SETTING UP WHEN YOU USING PYCHARM.

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.

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.

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.

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.

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

2. How to setting up When you using PyCharm.

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

2. How to setting up When you using PyCharm.

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

2. How to setting up When you using PyCharm.

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

2. How to setting up When you using PyCharm.

3. WING IDE

Overview

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

3. WING IDE FOR MAYA.

Install Wind-ide

3. WING IDE FOR MAYA.

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'

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

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)

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

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

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’

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

Configuration of User hot key3. WING IDE FOR MAYA.

Execution test

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

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.

top related