Skip to content

Instantly share code, notes, and snippets.

@oglops
Forked from dgovil/mayaCustomMarkers.py
Created April 19, 2017 21:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save oglops/1980115d24bf7d3622f1e6d29d47a7ed to your computer and use it in GitHub Desktop.
Save oglops/1980115d24bf7d3622f1e6d29d47a7ed 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