Tuesday 1 May 2018

Python Notes - Misc 01 - Blender/Maya


          -- LIST OF WHAT IS HERE FIRST --
(a long random assortment of python bits and pieces)
#----------------------------------------
#HOW TO Check python version IN BLENDER
#----------------------------------------
#A few useful imports
#ex: Imports Blender Python – properties/operators etc.
#ex1: math.sqrt #ex2: sqrt         
#----------------------------------------
#ex1: Create random number
#checking if a file exists 
#bpy.context # bpy.data
#----------------------------------------
#----------------------------------------
        #Maya examples:
        #maya.mel#import maya.OpenMayaUI # mel.eval
#----------------------------------------
#----------------------------------------
#Python Operators
#Comparisions
#Fals e#True
#----------------------------------------
#Bitwise
#1&0 is 0 | 1&1 is 1 | 0 & 0 is  1 # 1or0 is 1 | 1or1 is 1 | 0 or 0 is 0
#complement of (-x)-1 exclusive or = if identical = 0 otherwise 1
#bits shifted to the right by y bits shifted to the left by y
#----------------------------------------
#Boolean Operators
#if one or both are true #if both are true  #True id x is False   
#----------------------------------------
#Important Sequence Operators
#----------------------------------------
#True if x is in y #True if x is not in y
#----------------------------------------
#Concatenation of x and y #i’th in s (origin = 0)
#----------------------------------------
#Slice of s from x to z # slice of s from x  to z with step y
#slice first x of s #Length of s #Smallest item in s
#Index of first occurrence x #count the number of x’s
#equivalent to adding s to itself n times          
#----------------------------------------
#Comparison Operators
#identify (if it is)  if s is n: #negate (if it’s not)  if s is not n:
#less than  if s <  n: #less or equal  if s <= n: #greater than  if s > n:
#greater or equal  if s >= n: #equal  if s == n: #not equal  if s != n:
#----------------------------------------
#Conversions
#convert to integer #convert to floating point
#complex number re, real part re, im, imaginary part im. im default = 0
#method return complex conjugate() #absolute value or magnitude
#----------------------------------------
#Tuple Pair - (x//y, x%y) 
#----------------------------------------
# x to the y power
#----------------------------------------
#Basic Operators
# sum of x+y # difference of x&y # product of x&y # quotient of  x&y
# floored quotient of x&y # remainder of x&y # negated # unchanged
#----------------------------------------
#Indices
#--------------------------------------------------------------
#Copy selected objects to variable
#----------------------------------------
#Select a object Vert via a variable number
#----------------------------------------
#----------------------------------------
        #Maya examples:
        #Selected verts to variable 
#----------------------------------------
#----------------------------------------
#Parent one object to another – y’s parent = x
#----------------------------------------
#----------------------------------------
        #Maya examples:
        #Get child of selected object
        #Get parent of selected object
#----------------------------------------
#----------------------------------------
#Select an object(s) by name
#----------------------------------------
#Select an objects parent with one line
#Select an objects child with one line
#----------------------------------------
#Select an objects parent – alternative
#----------------------------------------
#set attribute for selected object
#----------------------------------------
#option -setattr
#----------------------------------------
#Loops – Examples
#----------------------------------------
#for loop - enumerate - use length(num of objects)
#----------------------------------------
#while  loop
#----------------------------------------
#----------------------------------------
        #Maya Loop example:
        #rename loop with frefix and suffix
#----------------------------------------
#----------------------------------------
#Copy attributes from one object to another
#----------------------------------------
#----------------------------------------
        #Maya Examples:
        #setAttr of selected object
        #Set Attr using xform
        #Set Attr using loop
        #Copy channel box Attributes from 1(selected obj[0]) to another(selected obj[1])
#----------------------------------------
#----------------------------------------
#Create a locator at the location of a vert (WIP)
#----------------------------------------
#----------------------------------------
        #Maya Examples:
        #place locator on selected vertex(s)
        #position to vertex - select Vert(Mov to) then Obj/Vert(Move from)
        #Find position of selected vertex
#----------------------------------------
#----------------------------------------
#LAMBDA - anonymous functions not bound to a name     
#squared
#times by
#addition
#subtration
#incrementor with lambda
#defin int values - filter(), map() + reduce()
#map()
#filter()
#reduce()
#prime numbers with lambda
#lambda – replace – nj with is
#split words using lambda - find num of letters in each
#range
#1 - loop from 0 to 20 -with  1/4 step *
#----------------------------------------
#----------------------------------------
        #Maya Example:
        #Maya Python UI button example
        #----------------------------------------
        #lock transform attributes of selected
        #unlock transform attributes of selected
#----------------------------------------
#lock or unlock attributes
#----------------------------------------
#----------------------------------------
        #Maya Examples:
        #set rotation of selected using xform
        #set translation of selected using xform
        #----------------------------------------
#----------------------------------------
#Copy attributes(ex:location), from one object to another
#----------------------------------------
#----------------------------------------
        #Maya Examples:
        #change the rotate order but preserve the overall transformation
        #display normals
        #increase normal size by 10
        #decrease normal size by 10
        #query viewport renderer (run whist viewport focused)
        #turn on/off display xray and wireframe in viewport in focus (run whist viewport focused)
        #query without being in panel focus (from script editor)
        #Get panel with focus
        #change time to frame to *55
        #Change time slider min max frame
        #Change time slider start/end frame
        #get list of keyframes on current selected object (exaple rotateX) attribute
   
#----------------------------------------
#----------------------------------------

#Check python version
import sys
print(sys.version_info)
print (sys.version_info.major)
#----------------------------------------
#A few useful imports
import bpy #ex: Imports Blender Python – properties/operators etc.
from functools import reduce
import math #ex1: math.sqrt
from math import *  #ex2: sqrt         
nj = (math.sin(math.radians(66))); print(nj * 55); #ex1
nj = (sin(radians(66))); print(nj * 55); #ex2
#----------------------------------------
import random#ex1: Create random number – random.randint
from random import randint #ex2: Create random number - randint
min=22; max=300;rnd = random.randint(min,max);print(rnd); #ex1:
min=22; max=300;rnd = randint(min,max);print(rnd); #ex2:
#----------------------------------------
import pathlib
from pathlib import Path #ex: For checking if a file exists 
filePath = Path("C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg");
if filePath.is_file():print((str(filePath)) + " exists as a file");
#----------------------------------------
#A few useful shortcuts
C = bpy.context #ex: assign context to C
#See: docs.blender.org/api/blender_python_api_2_73_release/bpy.context.html
D = bpy.data #ex: assign data to D
#See: docs.blender.org/api/blender_python_api_2_73_release/bpy.data.html
#----------------------------------------
#----------------------------------------
#Maya examples:
import maya.mel as mel
import maya.cmds as cmds
import maya.OpenMaya as OpenMaya
import maya.OpenMayaUI as OpenMayaUI
Source & Execute mel in python:
mel.eval('source "/MyDocument/username/maya/scripts/mymelscript.mel"')
mel.eval('mymelscript()')
#----------------------------------------
#----------------------------------------
#Python Operators
#Comparisions
x  = 10  y  = 12
print(x>y) #False
print(x<y) #True
print(x==y)#False
print(x!=y) #True
print(x>=y)#False
print(x<=y)#True
#----------------------------------------
#Bitwise
x  = 10  y  = 4
print (x&y) # = 0 - & = 1&0 is 0 | 1&1 is 1 | 0 & 0 is  1
print(x|y) # = 14 - or = 1or0 is 1 | 1or1 is 1 | 0 or 0 is 0
print(~x) # = -11 - complement of (-x)-1
print(x^y) # = 14 - exclusive or = if identical = 0 otherwise 1
print(x>>2) # = 2 - bits shifted to the right by y
print(x<<2) # = 40 - bits shifted to the left by y
#----------------------------------------
#Binary example:
128 64 32 16  8  4  2  1
  0    0   0    0  0  1  0  1    = 5(4+1)
#----------------------------------------
x =  12 | print("{0:b}".format( 12))   |   (~x)  =  -13  |  (-x)-1  |  1100 to -1101       
x = -12 | print("{0:b}".format(-12))  |   (~x)  =    11  |  (-x)- 1 | -1100 to 1011      
#----------------------------------------
x  = 27     y  = 49 
#----------------------------------------
print("{0:b}".format(27))    # =   1011
print("{0:b}".format(49))    # = 110001
print("{0:b}".format(x^y))   # = 101010
#----------------------------------------
print("{0:b}".format(38))    # = 100110
print("{0:b}".format(39))    # = 100111
print("{0:b}".format(x&y))   # = 100110 
#----------------------------------------
print("{0:b}".format(27))    # =  11011
print("{0:b}".format(49))    # = 110001
print("{0:b}".format(x&y))   # =  10001
#----------------------------------------
print("{0:b}".format(27))    # =  11011
print("{0:b}".format(49))    # = 110001
print("{0:b}".format(x|y))   # = 111011
#----------------------------------------
x  = 10 
print("{0:b}".format(10))       # = 001010 <<
print(x<<2)                     # = 40
print("{0:b}".format(40))       # = <<101000 span="">
#----------------------------------------
print("{0:b}".format(10))        # = >>1010
print(x>>2)                      # = 2
print("{0:b}".format(2))         # = 0010>>
#----------------------------------------
#Boolean Opperators
#----------------------------------------
x=27   y=34
#----------------------------------------
x or y #if one or both are true
if x > 55 or x < 33:
#----------------------------------------
x and y #if both are true 
if x > 3 and x < 33:
#----------------------------------------
x =False
not x #True id x is False   
if(not x):
#----------------------------------------
#Important Sequence Opperators
#----------------------------------------
s="bob"   x="bo"    y = s, x
#----------------------------------------
x in s  #True if x is in y
if x in s:
#----------------------------------------
x not in s #True if x is not in y
if x not in s:
#----------------------------------------
s + x  #Concatenation of x and y
print(s + " has " + x)  
#----------------------------------------
s[i] #i’th in s (origin = 0)
print(y[0] + " has " + y[1])      
#----------------------------------------
s = "Bobs BO is so bad that it caused an evacuation. Isn't that something"
#----------------------------------------
s[x:z]  #Slice of s from x to z
print(s[0:7] + s[47:59] + s[13:18]) # = Bobs Bo Isn’t that Bad
#----------------------------------------
s[x:y:z] # slice of s from x  to z with step y         
print(s[0:23:5])  # = BB aa
#----------------------------------------
s[:x] #slice first x of s 
print([:x]) # = Bobs Bo
#----------------------------------------
len(s) #Length of s
print(len(s)) # = 68
#----------------------------------------
s = "50", "40"
min(s) #Smallest item in s
print(min(s)) #=40
print(max(s)) #=50
#----------------------------------------
s = "looking for e in this string. Are there other e’s?"
x = "e"
s.index(x) #Index of first occurance x
print(s.index(x)) # = 12
#----------------------------------------
s.count(x) #count the number of x’s
print(s.count(x)) # = 6
#----------------------------------------
s = 8    n = 4
s*n,n*s #equivalent to adding s to itself n times         
print(s*n,n*s) #= 32 32
#----------------------------------------
#Comparison Operators
is  #identify (if it is)  if s is n:
is not  # negate (if it’s not)  if s is not n:
<  #less than  if s <  n:
<= #less or equal  if s <= n:
>  #greater than  if s > n:
>= #greater or equal  if s >= n:
== #equal  if s == n:
!= #not equal  if s != n:
#----------------------------------------
#Conversions
int(x) #convert to integer
float(x) #convert to floating point
complex(re,im) #complex number re, real part re, im, imaginary part im. im default = 0
c.conjugate() #method return complex conjugate()
abs(x) #absolute value or magnitude
#----------------------------------------
X=22(numerator)   y=8(denominator)
divmod(x,y) #Tuple Pair - (x//y, x%y) 
print(divmod(x,y)) = 2  6   print(x//y, x%y) =  2  6  quotient q and remainder r
#----------------------------------------
pow(x,y) # x to the y power
x**y #x to the y power
#----------------------------------------
#Basic Operators
x+y # sum of x+y
x-yy # difference of x&y
x* # product of x&y
x/y # quotient of  x&y
x//y # floored quotient of x&y
x%y # remainder of x&y
-x # negated
+x # unchanged
#----------------------------------------
#Indices
string value  abcde
indices  01234
tuple element  1  2  3  4  5
negative indices  -5 -4 -3 -2 -1
string value ”bobs here”, “oh no!, “Evacuate”
indices 012345678910
#--------------------------------------------------------------
#Copy selected objects to variable
selObj = C.selected_objects[0] #(C = bpy.context) |  print(selObj.name)
#----------------------------------------
#Select a object Vert via a variable number
import bpy
C  = bpy.context
bpy.ops.object.mode_set(mode = 'EDIT')
vertNum = 5
selObj = C.active_object
bpy.ops.mesh.select_all(action =  'DESELECT')    #only one vert - not added to selection
bpy.ops.object.mode_set(mode = 'OBJECT')
selObj.data.vertices[vertNum].select  = True
bpy.ops.object.mode_set(mode = 'EDIT')
#----------------------------------------
#----------------------------------------
#Maya examples:
Selected object to variable
Obj = cmds.ls(sl=True)[0] 
#Selected verts to variable
verts = cmds.ls(sl=True,fl=True)  
#----------------------------------------
#----------------------------------------
#Parent one object to another – y’s parent = x
import bpy
objects = bpy.data.objects
x = objects['Cube']
y = objects['Cube.001']
y.parent = x
y.matrix_parent_inverse = x.matrix_world.inverted() # avoid applying  parent's transformations #also - bpy.ops.object.parent_set()  parent_set()
#----------------------------------------
#----------------------------------------
#Maya examples:
#Get child of selected object
parObj = cmds.ls(sl=True)[0]
chldObj = cmds.listRelatives(parObj, c=True)
#Get parent of selected object
chldObj = cmds.ls(sl=True)[0]
parObj = cmds.listRelatives(chldObj, p=True)
#----------------------------------------
#----------------------------------------
#Select an object(s) by name
import bpy
a = bpy.data.objects['Cube']
b = bpy.data.objects['Cube.001']
bpy.ops.object.select_all(action='DESELECT')
a.select = True
b.select = True
#----------------------------------------
#Select an objects parent with one line
bpy.ops.object.select_hierarchy(direction='PARENT', extend=False)
#Select an objects child with one line
bpy.ops.object.select_hierarchy(direction='CHILD', extend=False)
#----------------------------------------
#Select an objects parent – alternative
import bpy
C = bpy.context
selObj = C.active_object
bpy.ops.object.select_all(action='DESELECT')
selObj.parent.select = True
#----------------------------------------
#set attribute for selected object
import bpy
C = bpy.context
selObj = C.active_object
#option 1
selObj.location = 1, 2, 3
#option 2 -setattr
setattr(selObj, "location", (1, 2, 3))  # translate
setattr(selObj, "scale", (1, 2, 3))  # scale
setattr(selObj, "rotation_euler", (1, 2, 3))  # rotate
#----------------------------------------
#Loops – Examples
#----------------------------------------
#1 - for loop
loopStart = 2;   loopEnd   = 8;
for x in range(loopStart, loopEnd):
       print((str(x)) +"   "+(str(loopStart + x)) +" through to "+(str(loopEnd + x)))
#----------------------------------------
objLots = ["keys",  "ball", "wire", "apple", "usb"]
#----------------------------------------
#2 – for loop -  use length(num of objects) 
for x in range(1, len(objLots)):
       print((str(x))  + "   " + objLots[x])
#----------------------------------------
#3 – for loop – in objects
for y in objLots:
print("x contains: ", y)
#----------------------------------------
#4 – for loop - enumerate
for i, y in enumerate(objLots):
print("x contains: ", y, " found at  ", i + 1)
#----------------------------------------
#5 –while  loop
x = 0
while x < len(objLots):
print(objLots[x] + " ", x)
x = x+1
#----------------------------------------
#6 –for  loop
for z in ( i*0.25 for y in range(8) ):
print(z)
#----------------------------------------
#7 –for  loop
for z in range (5):
t=z+1.5
print(t)
#----------------------------------------
#----------------------------------------
#Maya Loop example:
#rename loop with frefix and suffix
cnts = cmds.ls(sl=True)
prefix='pref_0'
suffix='_suf'
for (number, fllc) in enumerate(cnts):
    NmFllc=(prefix)
    cmds.rename(fllc, (prefix + (str(number+1)) + suffix))
#----------------------------------------
#----------------------------------------
#Copy attributes from one object to another
import bpy
C  = bpy.context
selObj = C.active_object
objLoc = (selObj, "location", (1, 2, 3))     
setattr(selObj, "location", objLoc[2])     
#----------------------------------------
#----------------------------------------
#Maya Examples:
#setAttr of selected object
selObj = cmds.ls(sl=True)
cmds.setAttr((selObj[0] + '.sx.'), 14)
#Set Attr using xform
selObj = (cmds.ls(sl=True, fl=True))
cmds.xform(selObj[0], a=True, ro=(0, 0, 0), t=(0, 0, 0), s=(1, 1, 1) )
#Set Attr using loop
attr = [ '.sx','.sy','.sz']
selObj = cmds.ls(sl=True)
for i in range(len(attr)):
    cmds.setAttr((selObj[0] + attr[i]),6)
#Copy channel box Attributes from 1(selected obj[0]) to another(selected obj[1])
attrCop = ['.tx','.ty','.tz','.rx','.ry','.rz','.sx','.sy','.sz']
selObj = cmds.ls(sl=True)
for v in range(len(attrCop)):
    cmds.setAttr((selObj[1] + attrCop[v]),cmds.getAttr(selObj[0]+ attrCop[v]))
#----------------------------------------
#----------------------------------------
#Create a locator at the location of a vert (WIP)
import bpy
C  = bpy.context
bpy.ops.object.editmode_toggle()
ob = C.active_object
ob = bpy.context.active_object
bpy.ops.object.editmode_toggle()
vert = [i.co for i in ob.data.vertices if i.select]
for vr in vert:
matxVert = ob.matrix_world * vr
bpy.ops.object.editmode_toggle()
bpy.ops.object.empty_add(type='PLAIN_AXES', location=matxVert)
bpy.ops.object.select_all(action='TOGGLE')
ob.select = True 
#----------------------------------------
#----------------------------------------
#Maya Examples:
#place locator on selected vertex(s)
selVrt = cmds.ls(sl=True, fl=True)
for i in range(len(selVrt)):
    pos = cmds.pointPosition(selVrt[i])
    c = cmds.spaceLocator(n="locNme_01" , p=(0, 0, 0) )
    cmds.xform(c, a=True, t=(pos[0], pos[1], pos[2]) )
#position to vertex - select Vert(Mov to) then Obj/Vert(Move from)
selObj = cmds.ls(sl=True)
vrtPos = cmds.pointPosition(selObj[0])
cmds.xform(selObj[1], a=True, t=(vrtPos[0], vrtPos[1], vrtPos[2]))
#Find position of selected vertex
selObj = cmds.ls(sl=True)
vrtPos = cmds.pointPosition(selObj[0])
print vrtPos
Align objects with diferent pivots
selObjs = cmds.ls(sl=True)
v = [ '.vtx[1]','.vtx[2]','.vtx[3]']
i=0
j=0
for i in range(len(selObjs)):
        for j in range(len(v)):
                   cmds.select(selObjs[i] + v[j], tgl=True)
cmds.Snap3PointsTo3Points()
#----------------------------------------
#----------------------------------------
#LAMBDA - anonymous functions not bound to a name     
# squared
#1
squr = lambda x: x**2
m = squr
print(m(8))#64
#2
def f (x): return x**2
print(f(8)) #64
# times by
multBy = lambda x: x*2
m = multBy
print(m(8)) #16
#addition
addition = lambda x,y: x+y
a = addition
print(a(3,4))#=7
#subtration
sub = lambda x,y: x-y
s = sub
print(s(3,4))#=-1
# incrementor with lambda
#1
def incr (n): return lambda x: x + n
f = incr(2)
g = incr(6)
print(f(42), g(42)) #44 48
#2
def increment (a): return lambda x: x + a
ben=increment(8)
bob=increment(24)
print(ben(12))
print(bob(12)) #20  36
#defin int values - filter(), map() + reduce()
foo = [2, 18, 9, 22, 17, 24, 8, 12, 27]
#map()
map_obj = (map(lambda x: x * 2 + 10, foo))    
num = list(map_obj) #list Converts the map obj to a list
print(num)  #[14, 46, 28, 54, 44, 58, 26, 34, 64]
#filter()
filter_obj =(list(filter(lambda x: x % 3 == 0, foo))) # list Converts the map obj to a list
print(filter_obj)  #[18, 9, 24, 12, 27]
#reduce()
from functools import reduce  #import reduce directly
print (reduce(lambda x, y: x + y, foo))    #139
#prime numbers with lambda
nums = range(2, 50)
for i in range(2, 8):
nums = list(filter(lambda x: x == i or x % i, nums))
print(nums) #[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
#lambda – replace – nj with is
words = ['a', 'huge', 'python[nj]', 'in' + ' the ', 'blender[nj]', 'with', 'lambda']
print(list(map(lambda x: str.replace(x, "[nj]", " is"), words)))
#split words using lambda - find num of letters in each
sentence = 'A python in a blender'
words = sentence.split()
print(words) #'A', 'python', 'in', 'a', 'blender'
print(list(map(lambda word: len(word), words)))#1,6, 2, 1, 7
#or
print(list(map(lambda w: len(w), 'A python in a blender'.split())))
#range
#1 - loop from 0 to 20 -with  1/4 step *
for x in (map(lambda i: i * 0.25, range(0,20))):
print(x)
#----------------------------------------
#----------------------------------------
#Maya Example:
#Maya Python UI button example
cmds.button(label="bobsUrUncle", c=lambda x:somedef())
#----------------------------------------
#lock transform attributes of selected
selObj = cmds.ls(sl=True, dag=True, tr=True)
att = ['.tx','.ty','.tz','.rx','.ry','.rz','.sx','.sy','.sz']
for ctr in range(len(att)):
    cmds.setAttr(selObj[0] + att[ctr], lock=True)
#unlock transform attributes of selected
selObj = cmds.ls(sl=True, dag=True, tr=True)
att = ['.tx','.ty','.tz','.rx','.ry','.rz','.sx','.sy','.sz']
for ctr in range(len(att)):
    cmds.setAttr(selObj[0] + att[ctr], lock=False)
#----------------------------------------
#----------------------------------------
#lock or unlock attributes
import bpy
C       = bpy.context
selObj = C.active_object
selObj.lock_scale[0]     = True   #False
selObj.lock_rotation[0] = True   # False
selObj.lock_location[0] = True   # False
#----------------------------------------
#----------------------------------------
#Maya Examples:
xform query
s = cmds.ls(sl=True, fl=True)
xQu=(cmds.xform(s[0], query=True, ws=True, t=True,))
print xQu
#set rotation of selected using xform
cmds.xform( r=True, ro=(5, 8, 6))
#set translation of selected using xform
cmds.xform( r=True, t=(5, 8, 6))
#----------------------------------------
#----------------------------------------
#Copy attributes(ex:location), from one object to another
import bpy
C = bpy.context
D = bpy.data
selObj = C.active_object
movObj = bpy.data.objects['nameOfObj2Mov']
OrigSel = selObj.matrix_world.to_translation()
movObj.location[0] = OrigSel [0] #move x location
movObj.location = OrigSel        #move x y z location
#----------------------------------------
#----------------------------------------
#Maya Examples:
#change the rotate order but preserve the overall transformation
cmds.xform( p=True, roo='yzx' )
#display normals
selObj = cmds.ls(sl=True,dag=True,s=True)
cmds.setAttr((selObj[0] + '.displayNormal'), 1)
#increase normal size by 10
selObj = cmds.ls(sl=True,dag=True,s=True)
cmds.setAttr((selObj[0] + '.displayNormal'), 1)
nz = cmds.getAttr(selObj[0] +'.normalSize')
cmds.setAttr((selObj[0] + '.normalSize'), (nz*10))
#decrease normal size by 10
selObj = cmds.ls(sl=True,dag=True,s=True)
cmds.setAttr((selObj[0] + '.displayNormal'), 1)
nz = cmds.getAttr(selObj[0] +'.normalSize')
cmds.setAttr((selObj[0] + '.normalSize'), (nz/10))
#query viewport renderer (run whist viewport focused)
print cmds.modelEditor( cmds.getPanel(wf=True), q=True, rnm=True )
#turn on display xray and wireframe in viewport in focus (run whist viewport focused)
#on
CurPan = cmds.getPanel(wf=True)
xraystr = 'setXrayOption true ' + CurPan + ' ;'
mel.eval(xraystr)
wirestr = 'setWireframeOnShadedOption true ' + CurPan + ' ;'
mel.eval(wirestr)
#off
CurPan = cmds.getPanel(wf=True)# print p
xraystr = 'setXrayOption false ' + CurPan + ' ;'
mel.eval(xraystr)
wirestr = 'setWireframeOnShadedOption false ' + CurPan + ' ;'
mel.eval(wirestr)
#query without being in panel focus (from script editor)
#----------------------------------------
import maya.cmds as cmds
import maya.OpenMaya as OpenMaya
import maya.OpenMayaUI as OpenMayaUI
view = OpenMayaUNI.M3dView.active3dView()
cam = OpenMaya.MDagPath()
#----------------------------------------
view.getCamera(cam)
camPath = cam.fullPathName()
print camPath
#Get panel with focus
cmds.getPanel(wf=True)
#change time to frame to *55
cmds.currentTime(55, edit=True)
#Change time slider min max frame
frange = (14,600)
cmds.playbackOptions( minTime=frange[0], maxTime=frange[-1] )
#Change time slider start/end frame
frange = (44,800)
(cmds.playbackOptions( ast=frange[0], aet=frange[-1] ))
#get list of keyframes on current selected object (exaple rotateX) attribute
fmNumLst=(cmds.keyframe( query=True, at='rx',timeChange=True ))
print fmNumLst
#----------------------------------------
#----------------------------------------

No comments:

Post a Comment