Hi Ryan, I want to understnad how the self.GetRegexMatch(0) works.
I am adding process handling for vray for maya and when I use self.GetRegexMatch(1) I get errors. But when I look in the mayabatch plugin, the mental ray handler uses self.GetRegexMatch(1)
could you enlighten me a bit please?
Hey Sylvain,
The index passed on to self.GetRegexMatch() is the index of the matches that were found. 0 returns the entire matched string, and 1, 2, etc returns the matched substrings (matches that are surrounded by round brackets). If there isn’t a corresponding substring, you’ll get an error (note that 0 is always a valid index). For example:
self.AddStdoutHandler( "WARNING:.*", self.HandleStdoutWarning )
self.AddStdoutHandler( "ERROR:(.*)", self.HandleStdoutError )
In HandleStdoutWarning(), 0 is the only valid index because there is no substring in round brackets in the regular expression. In HandleStdoutError(), 0 and 1 are valid. 0 will return the entire matched string, whereas 1 will return the substring in the round brackets.
Cheers,
Thanks for the clarification… now it makes sense.
got it… here is my progress handling for Vray for maya in the mayaBatch plugin
in the MayaBatchProcess class add the following variable
vrayRenderingImage = False
Then the handler
self.AddStdoutHandler( “V-Ray: Building light cache*”, self.HandleVrayMessage )
self.AddStdoutHandler( “V-Ray: Prepass ([0-9]+) of ([0-9]+)", self.HandleVrayMessage )
self.AddStdoutHandler( "V-Ray: Rendering image”, self.HandleVrayMessage )
self.AddStdoutHandler( “V-Ray: +([0-9]+)%*”, self.HandleVrayProgress )
finally the handler functions
def HandleVrayMessage ( self ):
progressStatus = None
errorMessage = self.GetRegexMatch(0)
if( errorMessage.find( “V-Ray: Building light cache” ) != -1 ):
progressStatus = ‘Building light cache.’
elif( errorMessage.find( “V-Ray: Prepass” ) != -1 ):
progressStatus = self.GetRegexMatch(0)
elif( errorMessage.find( “V-Ray: Rendering image” ) != -1 ):
progressStatus = self.GetRegexMatch(0)
self.vrayRenderingImage = True
if progressStatus is not None:
SetStatusMessage(progressStatus)
def HandleVrayProgress ( self ):
if self.vrayRenderingImage == True:
startFrame = GetStartFrame()
endFrame = GetEndFrame()
if( endFrame - startFrame + 1 != 0 ):
SetProgress( ( float(self.GetRegexMatch(1)) + self.FinishedFrameCount * 100 ) / ( endFrame - startFrame + 1 ) )
I use a variable because the progress message is always the same for all the rendering phases… so the progress only runs when the rendering image message is captured.
Awesome, thanks! It is possible for you to zip up the .py file and post it? All the indents were lost in the code, and since it’s python, it’s not obvious what the indents should be.
Thanks!
Yes sure, but note that my mayaBatch.py have other modification that would not work in a standard install. I have modified the plugin a bit, I have new options, mel scripts, etc that are called and will crash with the default plugin.
MayaBatch.rar (9.49 KB)
Gotcha! I was just using it to refer to the vray regex functions. Thanks again!
yeah I know… but I was mentioning it if other users take the file and simply replace the default one with…they would get surprises