@@ -274,6 +274,23 @@ def _checkAllShapeValidity(self, shapeNames):
274274 missingNames .append (shapeName )
275275 return missingNames , len (attrs )
276276
277+
278+ @classmethod
279+ def _removeExtraShapeNodes (cls , tfm ):
280+ shapeNodes = cmds .listRelatives (tfm , shapes = True , noIntermediate = True )
281+ if len (shapeNodes ) > 1 :
282+ keeper = None
283+ todel = []
284+ for sn in shapeNodes :
285+ tfmChk = '' .join (sn .rsplit ('Shape' , 1 ))
286+ if tfmChk == tfm :
287+ keeper = sn
288+ else :
289+ todel .append (sn )
290+ if keeper is not None :
291+ cmds .delete (todel )
292+
293+
277294 def preLoad (self , simp , simpDict , create = True , pBar = None ):
278295 """
279296
@@ -293,21 +310,24 @@ def preLoad(self, simp, simpDict, create=True, pBar=None):
293310
294311 """
295312 cmds .undoInfo (state = False )
296- if pBar is not None :
297- pBar .setLabelText ("Loading Connections" )
298- QApplication .processEvents ()
299- ev = simpDict ["encodingVersion" ]
313+ try :
314+ if pBar is not None :
315+ pBar .setLabelText ("Loading Connections" )
316+ QApplication .processEvents ()
317+ ev = simpDict ["encodingVersion" ]
300318
301- shapeNames = simpDict .get ("shapes" )
302- if not shapeNames :
303- return
319+ shapeNames = simpDict .get ("shapes" )
320+ if not shapeNames :
321+ return
304322
305- if ev > 1 :
306- shapeNames = [i ["name" ] for i in shapeNames ]
323+ if ev > 1 :
324+ shapeNames = [i ["name" ] for i in shapeNames ]
325+
326+ toMake , nextIndex = self ._checkAllShapeValidity (shapeNames )
307327
308- toMake , nextIndex = self ._checkAllShapeValidity (shapeNames )
328+ if not toMake :
329+ return
309330
310- if toMake :
311331 if not create :
312332 if pBar is not None :
313333 msg = "\n " .join (
@@ -332,24 +352,33 @@ def preLoad(self, simp, simpDict, create=True, pBar=None):
332352 pBar .setValue (0 )
333353 QApplication .processEvents ()
334354
355+ baseShape = cmds .duplicate (self .mesh )[0 ]
356+ cmds .delete (baseShape , constructionHistory = True )
357+ self ._removeExtraShapeNodes (baseShape )
358+
335359 for i , shapeName in enumerate (toMake ):
336360 if pBar is not None :
337361 pBar .setLabelText ("Creating Empty Shape:\n {0}" .format (shapeName ))
338362 pBar .setValue (i )
339363 QApplication .processEvents ()
340364
341- newShape = cmds .duplicate ( self . mesh , name = shapeName )[ 0 ]
342- cmds . delete ( newShape , constructionHistory = True )
365+ baseShape = cmds .rename ( baseShape , shapeName )
366+
343367 index = self ._firstAvailableIndex ()
344368 cmds .blendShape (
345- self .shapeNode , edit = True , target = (self .mesh , index , newShape , 1.0 )
369+ self .shapeNode , edit = True , target = (self .mesh , index , baseShape , 1.0 )
346370 )
347371 weightAttr = "{0}.weight[{1}]" .format (self .shapeNode , index )
348372 thing = cmds .ls (weightAttr )[0 ]
373+
349374 cmds .connectAttr ("{0}.weights[{1}]" .format (self .op , nextIndex ), thing )
350- cmds .delete (newShape )
351375 nextIndex += 1
352- return None
376+
377+ cmds .delete (baseShape )
378+ except Exception :
379+ cmds .undoInfo (state = True )
380+ raise
381+
353382
354383 def postLoad (self , simp , preRet ):
355384 """
@@ -366,6 +395,23 @@ def postLoad(self, simp, preRet):
366395 """
367396 cmds .undoInfo (state = True )
368397
398+ def checkForErrors (self , window ):
399+ """ Check for any DCC specific errors
400+
401+ Parameters
402+ ----------
403+ window : QMainWindow
404+ The simplex window
405+ """
406+ shapeNodes = cmds .listRelatives (self .mesh , shapes = True , noIntermediate = True )
407+ if len (shapeNodes ) > 1 :
408+ msg = (
409+ "The current mesh has multiple shape nodes." ,
410+ "The UI will still mostly work, but extracting/connecting shapes"
411+ "may fail in unexpected ways."
412+ )
413+ QMessageBox .warning (window , "Multiple Shape Nodes" , '\n ' .join (msg ))
414+
369415 # System IO
370416 @undoable
371417 def loadNodes (self , simp , thing , create = True , pBar = None ):
@@ -655,18 +701,18 @@ def loadAbc(self, abcMesh, js, pBar=None):
655701 cmds .polyEvaluate (importHead , vertex = True ) # Force a refresh
656702 cmds .disconnectAttr (abcNode + ".outPolyMesh[0]" , importHeadShape + ".inMesh" )
657703
658- importBS = cmds .blendShape (self .mesh , importHead )[0 ]
704+ importRest = cmds .duplicate (self .mesh , name = "importRest" )[0 ]
705+ cmds .delete (importRest , constructionHistory = True )
706+ self ._removeExtraShapeNodes (importRest )
707+
708+ importBS = cmds .blendShape (importRest , importHead )[0 ]
659709 cmds .blendShape (importBS , edit = True , weight = [(0 , 1.0 )])
660710 # Maybe get shapeNode from self.mesh??
661- inTarget = (
662- importBS
663- + ".inputTarget[0].inputTargetGroup[0].inputTargetItem[6000].inputGeomTarget"
664- )
665- cmds .disconnectAttr (self .mesh + ".worldMesh[0]" , inTarget )
666711 importOrig = [
667712 i for i in cmds .listRelatives (importHead , shapes = True ) if i .endswith ("Orig" )
668713 ][0 ]
669714 cmds .connectAttr (abcNode + ".outPolyMesh[0]" , importOrig + ".inMesh" )
715+ cmds .delete (importRest )
670716
671717 if pBar is not None :
672718 pBar .show ()
@@ -1239,6 +1285,15 @@ def renameSystem(self, name):
12391285 -------
12401286
12411287 """
1288+ if (
1289+ self .mesh is None
1290+ or self .ctrl is None
1291+ or self .shapeNode is None
1292+ or self .op is None
1293+ or self .simplex is None
1294+ ):
1295+ raise ValueError ("System is not set up. Cannot rename" )
1296+
12421297 nn = self .mesh .replace (self .name , name )
12431298 self .mesh = cmds .rename (self .mesh , nn )
12441299
0 commit comments