Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Allows a user to create custom markers in maya.Based off of this pastebin: http://pastebin.com/Uc8S4QPx (which may further be from createive Crash) and further work by https://github.com/achayan and his pasteBin http://pastebin.com/JGJZ5uu1
from PyQt4 import QtGui, QtCore
import maya.cmds as cmds
import maya.OpenMayaUI as mui
import sip
def convertToQT(controlName):
controlPoniter = mui.MQtUtil.findControl(controlName)
if controlPoniter is not None:
return sip.wrapinstance(long(controlPoniter), QtCore.QObject)
def getTimeline():
qtTimeline = convertToQT("timeControl1")
return qtTimeline
def getTimelineRange():
r = cmds.timeControl("timeControl1", query=True, ra=True)
return range(int(r[0]), int(r[1]))
class Markers(QtGui.QWidget):
def __init__(self, timeline=getTimeline()):
super(Markers, self).__init__(timeline)
layout = timeline.layout()
if not layout:
layout = QtGui.QVBoxLayout(timeline)
layout.setContentsMargins(0, 0, 0, 0)
timeline.setLayout(layout)
else:
for child in timeline.children():
if child.objectName() == "timelineMarkers":
child.deleteLater()
layout.addWidget(self)
self.setObjectName("timelineMarkers")
self.start = None
self.end = None
self.total = None
self.step = None
self.frames = []
self.colors = []
self.update()
def paintEvent(self, event):
self.draw()
def add(self):
color=[255, 0, 0]
for f in getTimelineRange():
if not f in self.frames:
self.frames.append(f)
self.colors.append(color)
else:
index = self.frames.index(f)
self.colors[index] = color
self.update()
def draw( self ):
self.start = cmds.playbackOptions(query=True, min=True)
self.end = cmds.playbackOptions(query=True, max=True)
self.total = self.width()
self.step = (self.total - (self.total * 0.01)) / (self.end - self.start + 1)
if not self.frames or not self.colors:
return
painter = QtGui.QPainter(self)
pen = QtGui.QPen()
pen.setWidth(self.step)
for f, c in zip(self.frames, self.colors):
color = QtGui.QColor('#fbc02d')
color.setAlpha(50)
pen.setColor(color)
pos = (f - self.start + 0.5) * self.step + (self.total * 0.005)
line = QtCore.QLineF(QtCore.QPointF(pos, 0), QtCore.QPointF(pos, 100))
painter.setPen(pen)
painter.drawLine(line)
def addMark():
global markers
try:
print markers
assert markers
except:
markers=Markers()
markers.add()
addMark()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment