[maya] scriptJob は実行中には中断できません。のエラーを回避する方法

scriptJob でMayaの状態を監視することができるが、その監視を終わらせる際にエラーが出る
日本語のエラー:scriptJob は実行中には中断できません。 #
英語のエラー:scriptJob cannot be killed while it is running. #

実行中のそれを回避するために、evalDeferredでコマンドを囲って遅延させて実行させる。

import maya.cmds as cmds

class ScriptJobber():
    def starter(self):
    
        #scriptJoblistEvents=cmds.scriptJob(listEvents=True)
        #print(scriptJoblistEvents)
    
        #for EventName in scriptJoblistEvents:
        #    print(EventName)
        
        
        
        #self.jobNum = cmds.scriptJob(event=("idle", 'Class_ins.idleTimeFunc()'))
        self.jobNum = cmds.scriptJob(event=("SceneOpened", 'Class_ins.SceneOpenedTimeFunc()'))
        #self.jobNum = cmds.scriptJob(event=("SceneOpened", 'Class_ins.SceneOpenedTimeFunc()'),runOnce = True, killWithScene = True)
        print("self.jobNum= "+str(self.jobNum))
    
    
    def SceneOpenedTimeFunc(self):
        print("SceneOpenedTimeFunc")
        print("SceneOpenedTimeFunc self.jobNum= "+str(self.jobNum))
        #cmds.scriptJob( kill=Class_ins.jobNum, force=True)
        cmds.evalDeferred("cmds.scriptJob( kill=Class_ins.jobNum, force=True)")
    
    def idleTimeFunc(self):
        print("idleTimeFunc")
        print("idleTimeFunc self.jobNum= "+str(self.jobNum))
        #cmds.scriptJob( kill=self.jobNum, force=True)
        cmds.evalDeferred("cmds.scriptJob( kill=Class_ins.jobNum, force=True)")
        
Class_ins=ScriptJobber()
Class_ins.starter()


"""
linearUnitChanged
timeUnitChanged
angularUnitChanged
Undo
undoSupressed
Redo
customEvaluatorChanged
serialExecutorFallback
timeChanged
currentContainerChange
quitApplication
idleHigh
idle
idleVeryLow
RecentCommandChanged
ToolChanged
PostToolChanged
ToolDirtyChanged
ToolSettingsChanged
tabletModeChanged
DisplayRGBColorChanged
animLayerRebuild
animLayerRefresh
animLayerAnimationChanged
animLayerLockChanged
animLayerBaseLockChanged
animLayerGhostChanged
cteEventKeyingTargetForClipChanged
cteEventKeyingTargetForLayerChanged
cteEventKeyingTargetForInvalidChanged
teClipAdded
teClipModified
teClipRemoved
teCompositionAdded
teCompositionRemoved
teCompositionActiveChanged
teCompositionNameChanged
teMuteChanged
cameraChange
cameraDisplayAttributesChange
SelectionChanged
PreSelectionChangedTriggered
LiveListChanged
ActiveViewChanged
SelectModeChanged
SelectTypeChanged
SelectPreferenceChanged
DisplayPreferenceChanged
DagObjectCreated
transformLockChange
renderLayerManagerChange
renderLayerChange
displayLayerManagerChange
displayLayerAdded
displayLayerDeleted
displayLayerVisibilityChanged
displayLayerChange
renderPassChange
renderPassSetChange
renderPassSetMembershipChange
passContributionMapChange
DisplayColorChanged
lightLinkingChanged
lightLinkingChangedNonSG
UvTileProxyDirtyChangeTrigger
preferredRendererChanged
polyTopoSymmetryValidChanged
SceneSegmentChanged
PostSceneSegmentChanged
SequencerActiveShotChanged
ColorIndexChanged
deleteAll
NameChanged
symmetricModellingOptionsChanged
softSelectOptionsChanged
SetModified
xformConstraintOptionsChanged
metadataVisualStatusChanged
undoXformCmd
redoXformCmd
freezeOptionsChanged
linearToleranceChanged
angularToleranceChanged
nurbsToPolygonsPrefsChanged
nurbsCurveRebuildPrefsChanged
constructionHistoryChanged
threadCountChanged
SceneSaved
NewSceneOpened
SceneOpened
SceneImported
PreFileNewOrOpened
PreFileNew
PreFileOpened
PostSceneRead
workspaceChanged
nurbsToSubdivPrefsChanged
PolyUVSetChanged
PolyUVSetDeleted
selectionConstraintsChanged
startColorPerVertexTool
stopColorPerVertexTool
start3dPaintTool
stop3dPaintTool
DragRelease
ModelPanelSetFocus
modelEditorChanged
MenuModeChanged
gridDisplayChanged
interactionStyleChanged
axisAtOriginChanged
CurveRGBColorChanged
SelectPriorityChanged
snapModeChanged
activeHandleChanged
ChannelBoxLabelSelected
texWindowEditorImageBaseColorChanged
texWindowEditorCheckerDensityChanged
texWindowEditorCheckerDisplayChanged
texWindowEditorDisplaySolidMapChanged
texWindowEditorShowup
texWindowEditorClose
colorMgtOCIORulesEnabledChanged
colorMgtUserPrefsChanged
RenderSetupSelectionChanged
colorMgtEnabledChanged
colorMgtConfigFileEnableChanged
colorMgtConfigFilePathChanged
colorMgtConfigChanged
colorMgtWorkingSpaceChanged
colorMgtPrefsViewTransformChanged
colorMgtPrefsReloaded
colorMgtOutputChanged
colorMgtPlayblastOutputChanged
colorMgtRefreshed
selectionPipelineChanged
playbackRangeChanged
playbackSpeedChanged
playbackModeChanged
playbackRangeSliderChanged
glFrameTrigger
currentSoundNodeChanged
graphEditorChanged
graphEditorParamCurveSelected
graphEditorOutlinerHighlightChanged
graphEditorOutlinerListChanged
EditModeChanged
RenderViewCameraChanged
texScaleContextOptionsChanged
texRotateContextOptionsChanged
texMoveContextOptionsChanged
polyCutUVSteadyStrokeChanged
polyCutUVEventTexEditorCheckerDisplayChanged
polyCutUVShowTextureBordersChanged
polyCutUVShowUVShellColoringChanged
shapeEditorTreeviewSelectionChanged
poseEditorTreeviewSelectionChanged
sculptMeshCacheBlendShapeListChanged
sculptMeshCacheCloneSourceChanged
RebuildUIValues
cteEventClipEditModeChanged
teEditorPrefsChanged

"""

URL
https://forums.cgsociety.org/t/scriptjob-problems/942387

関連記事

コメント

この記事へのコメントはありません。

TOP