Skip to content

Commit 421c002

Browse files
Release v0.0.1
1 parent 652ea4b commit 421c002

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

Piston_UI.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -27,52 +27,51 @@ def abspath(path):
2727
'generatePiston': abspath('icons/generatePiston.png'),
2828
'deleteNodes': abspath('icons/deleteNodes.png'),
2929
'pistonSolverNode': abspath('icons/pistonSolverNode.png'),
30-
'pistonVectorLength': abspath('icons/pistonVectorLengthNode.png')
30+
'pistonVectorLength': abspath('icons/pistonVectorLengthNode.png'),
31+
'flushUndo':abspath('icons/flushUndo.png')
3132
}
3233

3334
# Buttons commands for the shelf
3435

35-
def generateCommand():
36-
cmds.generatePiston()
36+
def generateCommand() :
37+
pm.generatePiston()
3738

3839

3940
def deletePluginNodes():
40-
"""
41-
Delete all the custom nodetypes created by the plugin
42-
:return:
43-
"""
4441
plugin_nodetypes = [
4542
'pistonVectorLength',
4643
'pistonNode'
4744
]
48-
4945
for type in plugin_nodetypes:
5046
nodes = pm.ls(type=type)
5147
if nodes:
5248
for i in range(len(nodes) - 1, -1, -1):
5349
if pm.objExists(nodes[i]):
5450
pm.delete(nodes[i])
5551
print(type, ' : {} nodes deleted'.format(len(nodes)))
52+
pm.flushUndo()
53+
5654

55+
def createSolver():
56+
pm.createNode('pistonNode')
5757

58-
def createSolver() :
59-
cmds.createNode('pistonNode')
58+
def flushUndo():
59+
pm.flushUndo()
6060

6161
def createVectorLength():
62-
cmds.createNode('pistonVectorLength')
62+
pm.createNode('pistonVectorLength')
6363

6464
# Generate the plugin Shelf
6565

6666
def generate_shelf():
67-
6867
# If the shelf exists delete it
6968
if pm.shelfLayout('Piston plugin', exists=True):
7069
print('Refreshing old shelf')
7170
if pm.shelfLayout('Piston plugin', query=True, ca=True):
7271
for each in pm.shelfLayout('Piston plugin', query=True, ca=True):
7372
print(each)
7473
pm.deleteUI(each)
75-
pm.deleteUI('Piston plugin')
74+
pm.deleteUI('Piston_plugin')
7675

7776
# Create the shelf
7877
plugin_shelf = pm.shelfLayout('Piston plugin', parent='ShelfLayout')
@@ -93,6 +92,13 @@ def generate_shelf():
9392
iol ='CLEAN',
9493
parent=plugin_shelf)
9594

95+
pm.shelfButton(annotation='flushUndo() command shortcut,\n'
96+
'in order to avoid crash when reloading plugin',
97+
command = flushUndo,
98+
image=icons['flushUndo'],
99+
iol='FLUSH',
100+
parent=plugin_shelf)
101+
96102
pm.shelfButton(annotation='Create pistonSolver in node editor',
97103
command=createSolver,
98104
image=icons['pistonSolverNode'],
@@ -106,5 +112,3 @@ def generate_shelf():
106112
# button that create the rig
107113

108114
# button that delete all plugin-type nodes
109-
generate_shelf()
110-

Piston_plugin.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
import pymel.core as pm
44
import importlib
55
import sys
6-
7-
for module in sys.modules.copy() :
8-
if module.startswith('Piston_UI') :
9-
del sys.modules[module]
106
import Piston_UI
117

128
maya_useNewAPI = True
@@ -353,6 +349,10 @@ def initializePlugin(plugin):
353349
:return:
354350
'''
355351
plugin_fn = OpenMaya.MFnPlugin(plugin, 'Baptiste Fraboul', '0.0.1')
352+
try :
353+
Piston_UI.generate_shelf()
354+
except :
355+
print(r'Couldn\'t create UI')
356356

357357
try:
358358
plugin_fn.registerCommand(generatePiston.kPluginCmdName,
@@ -394,6 +394,17 @@ def uninitializePlugin(plugin):
394394

395395
plugin_fn = OpenMaya.MFnPlugin(plugin)
396396

397+
# We completely unload modules to avoid error
398+
try :
399+
for module in sys.modules.copy():
400+
if module.startswith('Piston_UI'):
401+
del sys.modules[module]
402+
except :
403+
print('Cant\'t delete module Piston_UI')
404+
try :
405+
pm.deleteUI('Piston_plugin')
406+
except :
407+
print("Can't delete UI")
397408
try:
398409
plugin_fn.deregisterCommand(generatePiston.kPluginCmdName)
399410
plugin_fn.deregisterNode(pistonVectorLengthNode.type_id)

0 commit comments

Comments
 (0)