Posts

Showing posts from 2021

Windows PowerShell: List items in "Desktop" or "Documents"

Image
  Windows PowerShell Get a list of items in "Desktop" or "Documents" Creating a function. function testFunc($inarg){ cd ~ if($inarg -eq "Desktop"){cd "Desktop";} elseif($inarg -eq "Documents"){cd "Documents";} $items= ls; return $items; } Command line to print(echo) items(files and folders) in "Desktop". $items=Invoke-Command -ScriptBlock $function:testFunc -ArgumentList "Desktop";echo $items; Command line to print(echo) items(files and folders) in "Documents". $items2=Invoke-Command -ScriptBlock $function:testFunc -ArgumentList "Documents";echo $items2;

Windows PowerShell: Rename files in a folder

Right click "Start" and select Windows PowerShell. In the PowerShell, use "cd" to move to the directory(folder). e.g. cd C:\Users\[User Login]\Documents\test\ to move to "test" folder in your Documents folder. To rename files in this current folder, use PowerShell command like below. Get-ChildItem "*.jpg" | Sort Name | % { $i = 1} { $Newname = "rename_image" + $i.ToString("000") + $_.extension; Rename-item $_ $Newname; $i++ } This renames all jpg files to "renamed_image###".jpg If there are three jpg files, the files will be renamed_image001.jpg renamed_image002.jpg renamed_image003.jpg  

HIK: Getting current character and current source.

class HIK:     def getCurrentCharacter(self):         import maya.cmds as mc;         currentCharacterLabel= False;         currentCharacterIndex= mc.optionMenuGrp("hikCharacterList",q=1,sl=1);         items= mc.optionMenuGrp("hikCharacterList",q=1,itemListLong=1);         currentCharacterItem= items[currentCharacterIndex-1];         currentCharacterLabel= mc.menuItem(currentCharacterItem,q=1,label=1);         if not mc.objExists(currentCharacterLabel): currentCharacterLabel= None;         elif mc.nodeType(currentCharacterLabel)!="HIKCharacterNode": currentCharacterLabel= None;         return(currentCharacterLabel);     def getCurrentSource(self):         import maya.cmds as mc;         currentSourceLabel= False;         currentSou...

Python: Getting next available number

# Getting next available number.  def getFollowingNumber(inArgs):     ret= False;     current= inArgs[0];     array= inArgs[1];     num= len(array);     for i in range(0, num):         if array[i]==current:             k= current;             j= i;             for j in range(j, num):                 if k!=array[j]:                     ret= k;                     break;                 k+=1;             break;     if not ret: ret= current;     return(ret); current_number= 8; # Change this number numberList= [0,1,2,3,4,5,8,9,10,11,12,16,17,19,20,21,23,24,25,26,28,29,31]; new_number= getFollowingNumber...

Angle between 2 vectors using MEL in Python

Angle between 2 vectors using MEL in Python # Node positions pos0= cmds.xform(node0, q=1, ws=1, t=1); pos1= cmds.xform(node1, q=1, ws=1, t=1); pos2= cmds.xform(node2, q=1, ws=1, t=1); # 2 Vectors. pos0-pos1 and pos0-pos2. import maya.api.OpenMaya as om; vec0= om.MVector(pos0); vec1= om.MVector(pos1); vec2= om.MVector(pos2); vecA= vec0-vec1; vecB= vec0-vec2; # Radian and degree import maya.mel as mm; melVecFormatStrA= "<<"+str(vecA[0])+","+str(vecA[1])+","+str(vecA[2])+">>"; melVecFormatStrB= "<<"+str(vecB[0])+","+str(vecB[1])+","+str(vecB[2])+">>"; rad= mm.eval("angle "+melVecFormatStrA+" "+melVecFormatStrB); deg= mm.eval("rad_to_deg("+str(rad)+")");

Maya Python: IKHandle

Getting Start Joint and End Joint from ikHandle node  ikH= "ikHandle"; startJoint= cmds.listConnections(ikH+".startJoint")[0]; endJoint= cmds.listConnections(cmds.listConnections(ikH+".endEffector"),s=1,d=0)[0];