Before writing an article that uses Python to traverse a folder, extend the code today and make it a Maya plugin with UI user interface that can run directly in Maya;
function is to display a list of files in the disk partition directory;
ImportOSdefChdisk (): CD= Mc.optionmenu (OP, V=1, Q=1) MLS=Os.listdir (CD)#switching between listsMc.textscrolllist (Directorylist, e=1, removeall=1) mc.textscrolllist (Directorylist, E=1, append=MLS)#get a list of any directorydefClick (diskname): DiskN=Os.listdir (diskname) listsize=Len (DISKN) forIinchRange (0, listsize, 1): PrintDiskn[i].decode ('GBK') #formMc.window (title = ('Disk View'). Decode ('GBK'), height=600) mc.columnlayout ()#Add drop-down menuop = Mc.optionmenu (label= ('Catalogue'). Decode ('GBK'), CC ="Chdisk ()") #options in the menuMc.menuitem (label ='c:\\') mc.menuitem (label='d:\\') mc.menuitem (label='f:\\')#Get directory listDirList1 = mc.textscrolllist (numberofrows = 1, append = Os.listdir ("c:\\")) DirList2= Mc.textscrolllist (numberofrows = 1, append = Os.listdir ("d:\\")) DirList3= Mc.textscrolllist (numberofrows = 1, append = Os.listdir ("f:\\"))#Test Printing F-disk listClick"f:\\") Mc.showwindow ()
The window is named "Disk View"-the effect is as follows:
The function of the plugin is to display the list of files in the disk partition directory;
If necessary, you can add the ability to click on the list name to display the subordinate file, similar to the effect of the resource manager.
Python can customize plug-ins for a variety of functions, accelerating production processes and increasing productivity.
Python writes a plugin for viewing directory listings in Maya