Skip to content

Instantly share code, notes, and snippets.

@robomojo
robomojo / renameObjectToDatablock.py
Created April 16, 2013 21:56
For blender. Renames object using the objects' datablock name, seeking the original if detected. #blender #python
import bpy
for each in bpy.context.selected_objects:
newName = each.data.name
hasOriginal = each.data.name.find('.')>0
if hasOriginal:
newName = each.data.name.split('.')[0]
each.name = newName
@robomojo
robomojo / mayaAutorun.py
Created September 6, 2013 03:57
for maya, import scripts module from the directory of the currently opened maya file.
import sys
import os
(filepath,filename) = os.path.split(maya.cmds.file(q=True,l=True)[0])
if 'scripts.py' in os.listdir(filepath):
if filepath not in sys.path: sys.path.append(filepath)
import scripts
@robomojo
robomojo / blenderAutoRun.py
Created September 6, 2013 04:07
For blender, import scripts from the current file directory
import bpy, sys
sys.path.append(bpy.path.abspath('//'))
import scripts
@robomojo
robomojo / blenderscripts.py
Created September 6, 2013 04:09
For blender, import scripts from a separate repository
import bpy,sys
print ('calling scripts...')
filepath=bpy.path.abspath('//')
path = open(filepath+'scripts.path').readline()
sys.path.append(path)
import init
init.path=path
@robomojo
robomojo / mayascripts.py
Created September 6, 2013 04:26
For maya, load in a separate repository. expects to import an 'init' module and a 'scripts.path' file to give the directory of the maya scripts repository.
import sys,os,maya
print ('calling maya scripts...')
(filepath,filename) = os.path.split(maya.cmds.file(q=True,l=True)[0])
path = open(filepath+'//scripts.path').readline()
sys.path.append(path)
import init
init.path=path
@robomojo
robomojo / errors.py
Created September 6, 2013 11:46
maya learning stuff
# ERRORS AND WARNINGS
# maya cmds
import maya.cmds as cmds
cmds.warning('this is an warning')
cmds.error('this is an error')
# openmaya mglobal
import maya.OpenMaya as om
om.MGlobal.displayError('this is a display error - code not interrupted')
@robomojo
robomojo / getParentHierarchy.py
Created September 19, 2013 23:56
gets a list of parent objects
# recurse through parents, building a list as we go
def getAllParents (parents):
parent = listRelatives(parents[len(parents)-1],allParents=True)
if len(parent)>0 :
parents.append(parent)
getAllParents(parents)
return parents
ap = getAllParents([selected()[0]])
@robomojo
robomojo / pointOnCurve.py
Created September 20, 2013 00:52
makes points on a nurbsCurve
def makePointsOnCurve (c,x,g):
select(clear=True)
g = group (name=g)
count = 300
for i in range(0,count):
p = spaceLocator()
percentage = ( float(i)/count*100 ) * 0.01
pos = pointOnCurve (c, parameter=percentage, turnOnPercentage=True)
p.setTranslation(pos)
rename(selected()[0],'node_'+str(i))
@robomojo
robomojo / makeNames.py
Created September 20, 2013 01:38
converts 40 to '00040'
def getNumberStringWithPreZeros(i,m):
name = str(i)
for i in range(0,max(m-len(name),0)): name = '0'+name
return name
print getNumberStringWithPreZeros(40,3)
@robomojo
robomojo / maya.py
Created September 22, 2013 14:13
ipython and pymel loader to call from mayapy
print 'maya.py is running!'
print 'importing pymel.core'
from pymel.core import *
import sys
sys.path.append('c:\\py')
def get (file):