Skip to content

Instantly share code, notes, and snippets.

@dgovil
Last active October 21, 2018 04:29
Show Gist options
  • Save dgovil/307cb07db872c8a01d72 to your computer and use it in GitHub Desktop.
Save dgovil/307cb07db872c8a01d72 to your computer and use it in GitHub Desktop.
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