def fixUnhookedSpaces(ctrl): ''' Preliminary tool to deal with messed up spaces. Right now ONLY deals if there is a space name and destination unhookedup. FILL IN OTHERS WITH ERROR IN NAME??? ''' names = common.getNames(ctrl) space = pdil.dagObj.zero(ctrl, apply=False) constraint = PyNode(parentConstraint(space, q=True)) targetPlugs = constraint.getWeightAliasList() if len(names) != len(targetPlugs): print('There are', len(names), 'but', len(targetPlugs), ', you will need to figure out what is right!') noDriver = {} for i, plug in enumerate(targetPlugs): cons = plug.listConnections(s=True, d=False) if not cons: noDriver[i] = plug # connected = {} unconnected = [] conditions = ctrl.attr(common.ENUM_ATTR).listConnections(type='condition') for c in conditions: con = c.outColorR.listConnections() if con: order = c.secondTerm.get() connected[order] = con[0] else: unconnected.append(c) missingIndex = range(len(targetPlugs)) for i in connected: missingIndex.remove(i) if len(noDriver) == 1 and len(unconnected) == 1: print(noDriver, unconnected) print(connected.keys()) print(missingIndex) print('Autofixing!', noDriver.values()[0], 'is "%s"' % names[missingIndex[0]]) unconnected[0].secondTerm.set(missingIndex[0]) #print( noDriver.values()[0] ) unconnected[0].outColorR >> noDriver.values()[0] if not noDriver and not unconnected: print('All good!') else: print('This had some errors') 'FILL IN OTHERS WITH ERROR IN NAME???'
def remove(control, spaceNameOrIndex, shuffleRemove=False): ''' Remove the space from the control. If `shuffleRemove` is `True`, keep the same number of enum but make the last one marked for delete. This means you can remove referenced things but it's a 3 step process: * shuffleRemove * move the anim curves to the appropriate connection in ref'ed files * Fully remove the end spaces marked for delete. Args: controls - The control with a space to be removed spaceNameOrIndex - String name or the index (in case a name was duplicated on accident) shuffleRemove - Retains the same number of spaces, but puts a 'DELETE' space at the end. The intention is to preserve the count if referenced, but probably not actually useful. .. todo:: Option to allow specifying the actual space target instead of just the name? ''' # Adjust the condition for each one secondTerm to be one earlier # Mark or delete the final item names = common.getNames(control) if isinstance(spaceNameOrIndex, numbers.Number): index = spaceNameOrIndex else: index = names.index(spaceNameOrIndex) conditionToDelete = None plugToDelete = None # Find target and shift all the values above down to closes the gap. for condition in control.attr( common.ENUM_ATTR).listConnections(type='condition'): plugs = condition.outColorR.listConnections(p=True) if condition.secondTerm.get( ) == index and plugs: # Verify plugs exist, otherwise it's an orphaned condition conditionToDelete = condition plugToDelete = plugs[0] if condition.outColorR.listConnections( ) else None break for condition in control.attr( common.ENUM_ATTR).listConnections(type='condition'): if condition.secondTerm.get() > index: # Shuffle all terms down condition.secondTerm.set(condition.secondTerm.get() - 1) del names[index] if shuffleRemove: names.append('DELETE') # If the last space was removed, remove the switch attr entirely if not names: control.deleteAttr(common.ENUM_ATTR) else: common.setNames(control, names) spaceGrp = pdil.dagObj.zero(control, apply=False) const = PyNode(parentConstraint(spaceGrp, q=True)) # Since the targetList order might not match the enum order, find the # correct target by matching up the destination weight plug. if plugToDelete: for target, plug in zip(const.getTargetList(), const.getWeightAliasList()): if plug == plugToDelete: parentConstraint(target, const, e=True, rm=True) if conditionToDelete: delete(conditionToDelete)