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.


Recommended