2

On seeing Photoshop Action, I am curious to develop a macro tool for Maya using python. So I started working on it.

Here is my sample,

path = "C:/Desktop/file.txt"
a = open(path, 'w')
#cmds.scriptEditorInfo(ch = True, chf = True)
cmds.scriptEditorInfo( hfn=path, wh=True)
a.close()

I was able to record all the things. Here is my recorded information.

CreatePolygonPyramid;
performPolyPrimitive Pyramid 0;
setToolTo CreatePolyPyramidCtx;
optionVar -query toolMessageVisible;
optionVar -query toolMessageTime;
optionVar -query toolMessageVerticalOffset;
optionVar -query toolMessageHorizontalOffset;
headsUpMessage -time 0.7 -verticalOffset -40 -horizontalOffset 0 -viewport 1 -          uvTextureEditor 0"Drag on the grid.";
changeToolIcon;
polyPyramid -ch on -o on -w 10.727425 -cuv 3 ;
escapeCurrentTool;
autoUpdateAttrEd;
updateAnimLayerEditor("AnimLayerTab");
statusLineUpdateInputField;
changeToolIcon;

The problem is I was un-able to categories things (record only the required things). It just records all the information. I tried using the combination of various flags like se, sw, si, sr. But I was un-able to pick the required information.

Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
sasecse
  • 69
  • 4
  • 16
  • mmmh, the volume of information you need to sort is quite important. Depending on how many commands you want to ignore, you maybe will have to write one dedicated "treatment" per command written in the script editor... I am really interested to see if anyone here could have a solution. – Korchkidu Mar 09 '12 at 10:03

3 Answers3

0

If i may suggest an alternative, try to use the command repeatLast for mining your operations, its not perfect but beats filtering the echo. Unfortunately Autodesk has omitted the documentation of the command, presumably because they broke the mechanism as it doesn't know if the command is python or not.

You can use following to mine the repeat last structure:

import maya.cmds as mc

cmdsExecuted = mc.repeatLast(q=1, cl=1)

Maya even kindly provides a event RecentCommandChanged every time repeatLast structure changes. This makes this ideal for monitoring changes for a GUI just like Photoshop. The list in repeat last is much more concise than what you would get form a pure Maya echo, and guaranteed to work if you can figure out when a thing is python and what is not. But mostly you would record most menu items but not tool edits and repeats. Its easy and does not work for all situations but then a good monitoring tool that does everything is a bit convoluted to make.

Combine this with the undoInfo idea and you'll get a much better way to harvest things. As for the setAttr you can monitor those changes directly by listening in on nodes, but this gets complicated really fast.

joojaa
  • 4,354
  • 1
  • 27
  • 45
0

The output you are showing from recording looks like you have "Echo All Commands" enabled in the script editor. Are you sure thats necessary for the purpose of recording actions? "Echo All" always gives you the sub-commands that are executed from the initial command, which are usually redundant to calling the original command.

Maybe you can combine your script editor logging approach, with "Echo All" turned off, and also use the undo queue as an extra record: cmds.undoInfo(q=True, printQueue=True)
You would either have to clear the undo queue first when you start recording, or first run some NOOP command that creates a "marker" to know where you start in the queue. An operation like a "setAttr" leaves a blank named entry, but you would be able to look at your script editor record to know what was missing in between. Maybe with those two combined you would get a more accurate macro.

jdi
  • 90,542
  • 19
  • 167
  • 203
0

sasecse

I challenged to solve your problem.

#save your old settings
old_echoAllLines = cmds.optionVar(q='echoAllLines')
old_showLineNumbersIsOn = cmds.optionVar(q='showLineNumbersIsOn')
old_stackTraceIsOn = cmds.optionVar(q='stackTraceIsOn')
old_commandReportercmdScrollFieldReporter1SuppressResults = cmds.optionVar(q='commandReportercmdScrollFieldReporter1SuppressResults')
old_commandReportercmdScrollFieldReporter1SuppressInfo = cmds.optionVar(q='commandReportercmdScrollFieldReporter1SuppressInfo')
old_commandReportercmdScrollFieldReporter1SuppressWarnings = cmds.optionVar(q='commandReportercmdScrollFieldReporter1SuppressWarnings')
old_commandReportercmdScrollFieldReporter1SuppressErrors = cmds.optionVar(q='commandReportercmdScrollFieldReporter1SuppressErrors')  
old_commandReportercmdScrollFieldReporter1SuppressStackTrace = cmds.optionVar(q='commandReportercmdScrollFieldReporter1SuppressStackTrace')

#set environment
cmds.optionVar( iv=('echoAllLines', 0))
cmds.optionVar( iv=('showLineNumbersIsOn', 0))
cmds.optionVar( iv=('stackTraceIsOn', 0))
cmds.optionVar( iv=('commandReportercmdScrollFieldReporter1SuppressResults', 1))
cmds.optionVar( iv=('commandReportercmdScrollFieldReporter1SuppressInfo', 1))
cmds.optionVar( iv=('commandReportercmdScrollFieldReporter1SuppressWarnings', 1))
cmds.optionVar( iv=('commandReportercmdScrollFieldReporter1SuppressErrors', 1))
cmds.optionVar( iv=('commandReportercmdScrollFieldReporter1SuppressStackTrace', 1))

#your sample code

path = "C:/Desktop/file.txt"
a = open(path, 'w')
#cmds.scriptEditorInfo(ch = True, chf = True)
cmds.scriptEditorInfo( hfn=path, wh=True)
a.close()

#reset your settings
cmds.optionVar( iv=('echoAllLines', old_echoAllLines))
cmds.optionVar( iv=('showLineNumbersIsOn', old_showLineNumbersIsOn))
cmds.optionVar( iv=('stackTraceIsOn', old_stackTraceIsOn))
cmds.optionVar( iv=('commandReportercmdScrollFieldReporter1SuppressResults', old_commandReportercmdScrollFieldReporter1SuppressResults))
cmds.optionVar( iv=('commandReportercmdScrollFieldReporter1SuppressInfo', old_commandReportercmdScrollFieldReporter1SuppressInfo))
cmds.optionVar( iv=('commandReportercmdScrollFieldReporter1SuppressWarnings', old_commandReportercmdScrollFieldReporter1SuppressWarnings))
cmds.optionVar( iv=('commandReportercmdScrollFieldReporter1SuppressErrors', old_commandReportercmdScrollFieldReporter1SuppressErrors))
cmds.optionVar( iv=('commandReportercmdScrollFieldReporter1SuppressStackTrace', old_commandReportercmdScrollFieldReporter1SuppressStackTrace))

I shall be happy if I can be of any help to someone.

bye!