Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Plugin to run code in scene annotations when Softimage events occur.
Annotation.Parent3DObject.Properties('runOnEndFileImport').Parameters('flag1').Value = False
Annotation.Parent3DObject.Properties('runOnEndFileImport').Parameters('flag1').Value = True
def main():
if not Annotation.Parameters('flag1').Value:
Application.LogMessage('Processing Post Import Script!')
Annotation.Parameters('flag1').Value = True
SI_GLOBALS = globals().copy()
import traceback
from win32com.client import constants as c
xsi = Application
log = xsi.LogMessage
def XSILoadPlugin(reg):
reg.Author = "pboucher"
reg.Name = "CodeRunner"
reg.Major = 1
reg.Minor = 0
for eventName in ACTIVE_EVENTS:
funcName = _makeFuncNameFromEventName(eventName)
reg.registerEvent(funcName, getattr(c, eventName))
#RegistrationInsertionPoint - do not remove this line
return True
def processEvent(ctxt, eventName):
annotationName = 'run' + eventName[2:]
for note in _getAnnotations(annotationName):
log('Processing code in %s.' % note.FullName)
gbls = SI_GLOBALS.copy()
gbls['Annotation'] = note
code = note.Text.Value.replace('\r\n', '\n')
exec code in gbls
except Exception, err:
msg = 'An error occured processing code in %s.\n\n' % note.FullName
msg += traceback.format_exc()
log(msg, c.siError)
def _getAnnotations(name):
"""Bottom up walk of models"""
for model in _walkModel(xsi.ActiveSceneRoot):
for note in model.Properties:
if note.IsClassOf(c.siCustomPropertyID) and str(note.Name).startswith(name):
yield note
def _walkModel(model):
# Move yield to for top down
for subModel in model.Models:
for ret in _walkModel(subModel):
yield ret
yield model
# Create the event handling functions
def _makeFuncNameFromEventName(eventName):
return 'codeRunner' + eventName[2:]
def _makeEventHandlerFunction(eventName):
funcName = _makeFuncNameFromEventName(eventName) + '_OnEvent'
def eventHandler(ctxt):
processEvent(ctxt, eventName)
eventHandler.__name__ = funcName
return eventHandler
for eventName in ACTIVE_EVENTS:
eventHandler = _makeEventHandlerFunction(eventName)
globals()[eventHandler.__name__] = eventHandler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.