week 1, lab 1 getting computers set up with python 3, maya

3
Week 1, Lab 1 Getting Computers Set Up With Python 3, Maya, and Visual Studio Code Thanks to Dr. Ann McNamara for the main content of these instructions, and Jason Lee for important revisions 1. Download and install Autodesk Maya 2022 - you can select the educational version by providing your user id. (or you can download a 30-day free trial while you wait for your id to be approved.) https://www.autodesk.com/education/edu-software/overview? sorting=featured&page=1 https://www.autodesk.com/products/maya/free-trial? support=ADVANCED&plc=MAYA&term=1-YEAR&quantity=1 2. Download and install Visual Studio Code - this is a text editor that allows for extensive and specialized extensions/plugins that help speed up your workZlow. For reference, you can think of VSC as Notepad/TextEdit but with extendable functionality. https://code.visualstudio.com/download 3. Install MayaCode (click the green install button and open in Visual Studio Code) - This extension allows you to see the Maya hierarchy within VSC, colors the words of your script for readability (syntax highlighting), and provides intellisense (smart autocomplete) for MEL. https://marketplace.visualstudio.com/items? itemName=saviof.mayacode. Note: do NOT install any of the other suggested extensions, as they may conZlict with MayaCode. View of the MayaCode extension from within Visual Studio Code 4. Put the following line of code in a Zile called userSetup.mel commandPort -name "localhost:7001" -sourceType "mel";

Upload: others

Post on 08-May-2022

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Week 1, Lab 1 Getting Computers Set Up With Python 3, Maya

Week1,Lab1GettingComputersSetUpWithPython3,Maya,andVisualStudioCodeThankstoDr.AnnMcNamaraforthemaincontentoftheseinstructions,andJasonLeeforimportantrevisions

1. DownloadandinstallAutodeskMaya2022-youcanselecttheeducationalversionbyprovidingyouruserid.(oryoucandownloada30-dayfreetrialwhileyouwaitforyouridtobeapproved.)https://www.autodesk.com/education/edu-software/overview?sorting=featured&page=1https://www.autodesk.com/products/maya/free-trial?support=ADVANCED&plc=MAYA&term=1-YEAR&quantity=1

2. DownloadandinstallVisualStudioCode-thisisatexteditorthatallowsforextensiveandspecializedextensions/pluginsthathelpspeedupyourworkZlow.Forreference,youcanthinkofVSCasNotepad/TextEditbutwithextendablefunctionality.https://code.visualstudio.com/download

3. InstallMayaCode(clickthegreeninstallbuttonandopeninVisualStudioCode)-ThisextensionallowsyoutoseetheMayahierarchywithinVSC,colorsthewordsofyourscriptforreadability(syntaxhighlighting),andprovidesintellisense(smartautocomplete)forMEL.https://marketplace.visualstudio.com/items?itemName=saviof.mayacode.Note:doNOTinstallanyoftheothersuggestedextensions,astheymayconZlictwithMayaCode.

ViewoftheMayaCodeextensionfromwithinVisualStudioCode

4. PutthefollowinglineofcodeinaZilecalleduserSetup.mel

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

Page 2: Week 1, Lab 1 Getting Computers Set Up With Python 3, Maya

WhenyouputthisZileintherightdirectory,MayawillautomaticallyexecutethisZileeverytimeitopens-thecodebasicallytellsVSCodehowto“talk”toAutodeskMaya.YoucancreatetheZileinnotepadoranytexteditoryoulike(evenVSCode).

5. PutthefollowinglineofcodeinaZilecalleduserSetup.py

import maya.cmds as cmds

Whenthisisintherightdirectory,MayawillautomaticallyexecutethisZileonstartupwhenitopens.ThistellsPythontoloadtheMayaPythoncommands.ThiswillsaveusfromhavingtotypethislineofcodeeverytimeweexecuteaPythonscriptinMaya.

6. BecarefulwiththeZilenamestheyshouldbeEXACTLYastheyarelisted.

7. PlacebothuserSetup.melanduserSetup.pyintheMaya2022scriptsfolder.Sincethisfolderishidden,youcannotgettoitthroughthenormalbrowser.Instead

MAC:OpenaFinderwindow,theninthemenubarclickGo->GotoFolder,pasteinthefollowingline,andthenclickGo:/Users/username/Library/Preferences/Autodesk/maya/2022/scripts ForexampleonmyMacmyfolderiscalled/Users/dhouse/Library/Preferences/Autodesk/maya/2022/scripts

WINDOWS:ClickStart>Run,pasteinthefollowingline,thenclickRun:..\My Documents\maya\2022\scripts

Desktopviewof..\My Documents\maya\2022\scripts

8. WhenMayaupdatedfromversion2020toversion2022,theyupgradedfromPython2toPython3.ThisintroducedabugthatyoucanZixbymakingthefollowingmodiZicationstoMayaCode.FirstnavigatetotheVSCodeextensionsfolder.Sincethisfolderishidden,youcannotgettoitthroughthenormalbrowser.Instead

Page 3: Week 1, Lab 1 Getting Computers Set Up With Python 3, Maya

MAC:OpenaFinderwindow,theninthemenubarclickGo->GotoFolder,pasteinthefollowingline,andthenclickGo:~/.vscode/extensions/saviof.mayacode-1.4.0/out

WINDOWS:ClickStart>Run,pasteinthefollowingline,thenclickRun: %USERPROFILE%\.vscode\extensions\saviof.mayacode-1.4.0\out

Now,youshouldbeinthefolderwhereyouwillZindtheZileextension.jsDoubleclickthisZiletoopenitinatexteditor,andaroundline236youwillZindthelinecmd = `python("execfile('${posixPath}')")`;

Now,changethislinetothefollowingandsavetheeditedZile:

cmd = `python("exec(open('${posixPath}').read())")`;

9. OnceyouhavetheZilescorrectlyplaced,andMayaCodeedited,openbothMayaandVisualStudioCode.InVSCcreateanewPythonscript(File->New)-andenterthefollowingtwolinesofcode

cmds.polyCube(name='mycube') cmds.polySphere(n="mysphere")

andsavetheZileas test.py (File->SaveAs)-The.py extensionattheendoftheZilenametellsVSCodethatitisapythonZile.

10. Nowthemomentoftruth-Right-clickanywhereinyourscripttest.pywindowinVSCodeandyoushouldseeamenuitemMaya:SendPythonCodetoMayaorusethehotkeycombo:shift+alt+M(shift+option+MonMac),sinceyouwillbedoingthisallthroughoutthesemester.-theZirsttimeyoudothisyoumayneedtoscrolldowntothebottomandopenthecommandpalette.StarttypingMayaatthe>prompt,andthenselectMaya:SendPythonCodetoMaya.

11. IfyouhavefollowedalltheinstructionscarefullyyoushouldnowhaveacubeandasphereobjectdisplayedinMaya,withthenamesmysphereandmycube.YouwillonlyseethesphereinyourMayawindow,becausethecubeishiddeninsideit.Toseethecube,useMaya’sinterfacetoselectthesphereandmoveittoanewposition.

12. That’sitfortoday.InthenextlabwewillspendsometimegettingfamiliarwithPython,beforewegetintosomemoresophisticatedusesofPythonscriptinginMaya.