- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, i’m having some trouble with the color() command using the rgbColor flag. When I reference more than one of the same file that uses it into a scene, save the scene and reopen, only the first reference seems to display correct, the rest displays as black.
Here’s some code that shows the error (be aware that it will create a new file without saving your work, and it creates 2 new files in a subfolder in your default workspace (circles.mb and tworefs.mb)):
from pymel.core import *
import os
out_dir = os.path.join(internalVar(uwd=True), 'color_command')
def makeCircleFile():
"""makes 3 circles, color them and saves the file"""
newFile(f=1)
# make 3 circles, space them out and color them
circlergb = circle(name='rgbColor', constructionHistory=0)
circlergb[0].translateX.set(3)
# color circle using rgbColor
color(circlergb[0], rgbColor=[1, 0, 0])
circleud = circle(name='userDefined', constructionHistory=0)
circleud[0].translateX.set(-3)
# color circle using userDefined color
color(circleud[0], userDefined=1)
circledefault = circle(name='defaultColor', constructionHistory=0)
group(
circlergb[0], circleud[0], circledefault[0], world=True,
name='circle_GRP')
# save file
if not os.path.exists(out_dir):
os.makedirs(out_dir)
filename = 'circles.mb'
f = os.path.join(out_dir, filename)
saveAs(f)
return(f)
def referencecircles(f):
"""References rf twice, moves references apart"""
newFile(f=1)
ns = os.path.basename(rf).split('.')[0]
ref1 = system.createReference(f, namespace=ns)
PyNode(ns + ':circle_GRP').translateZ.set(3)
ref2 = system.createReference(f, namespace=ns)
filename = 'tworefs.mb'
f2 = os.path.join(out_dir, filename)
saveAs(f2)
return(f2)
def makeConfirmWindow():
"""Make a window with a label and an Ok Button that runs okPushed"""
if window('confirmOpen', exists=True):
deleteUI('confirmOpen')
w = window(
'confirmOpen', title='Reopen File', w=100, h=400, mxb=False,
sizeable=False)
rcLayout = rowColumnLayout(nc=1)
confirmtext = (
"A file with 3 circles have been created; one green using " +
"color(ud=1), one defaultColor, and one red using " +
"color(rgbColor=[1,0,0]. This have been referenced twice into a new " +
"scene and saved. The colors still look as expected. Click OK to " +
"reOpen the scene. Notice the colors of circles1:rgbColor now appear" +
"black.")
windowtext = text(
label=confirmtext, ww=True, align='center', w=250)
spacer = text(label='')
button(w=220, h=25, label='OK', c=okPushed)
showWindow(w)
window(w, edit=True, w=250, h=150)
def okPushed(*args):
"""opens the newly created file"""
openFile(sf, force=True)
try:
deleteUI('confirmOpen')
except:
pass
rf = makeCircleFile()
sf = referencecircles(rf)
makeConfirmWindow()
Note the rgb color flag was new to maya2015ext1, so it doesn't work in older verisons
How do people normally color controllers in their rigs etc? I would really like to stay away from drawingOverrides so the animators can play with those if needed, and I feel the userDefined(1-8) colors are waay too muddy for this purpose by default, and are user defined (duh
), so wouldn't always display the same.
-cheers
Solved! Go to Solution.