def MgSelTagsFromSelectedClones(obj): tag = obj.GetLastTag() # Get object's last tag tags = obj.GetTags() # Get object's tags md = mo.GeGetMoData(obj) # Get object's MoGraph data cnt = md.GetCount() # Get clone count selection = mo.GeGetMoDataSelection( tag) # Get selection from MoGraph selection tag prefix = "ms" # Prefix sep = "_" # Separator x = 0 # Initialize iteration variable for k in tags: # Loop through reversed list of tags if k.GetName().split("_")[0] == prefix: x = x + 1 # Increase iteration variable for i in range(0, cnt): # Loop through reversed list of clones if selection.IsSelected(i) == True: t = c4d.BaseTag(1021338) # Initialize MoGraph selection tag t[c4d.ID_BASELIST_NAME] = prefix + sep + str(x) # Set tag name s = c4d.BaseSelect() # Initialize BaseSelect s.Select(i) # Select clone obj.InsertTag(t, obj.GetLastTag()) # Insert new tag to object doc.AddUndo(c4d.UNDOTYPE_NEW, t) # Add undo command for inserting new tag mo.GeSetMoDataSelection(t, s) # Set MoGraph selection x = x + 1 # Increase iteration variable tag.Remove() # Remove old tag doc.AddUndo(c4d.UNDOTYPE_DELETE, tag) # Add undo command for removing tag
def main(): doc.StartUndo() tag = op.GetLastTag() tags = op.GetTags() md = mo.GeGetMoData(op) cnt = md.GetCount() selection = mo.GeGetMoDataSelection(tag) prefix = "ms" sep = "_" x = 0 for k in reversed(tags): if k.GetName().split("_")[0] == prefix: x = x + 1 for i in reversed(xrange(0, cnt)): if selection.IsSelected(i) == True: t = c4d.BaseTag(1021338) t[c4d.ID_BASELIST_NAME] = prefix + sep + str(x) s = c4d.BaseSelect() s.Select(i) op.InsertTag(t) doc.AddUndo(c4d.UNDOTYPE_NEW, t) mo.GeSetMoDataSelection(t, s) x = x + 1 tag.Remove() doc.AddUndo(c4d.UNDOTYPE_DELETE, tag) doc.EndUndo() c4d.EventAdd()
def MgSelTagForEveryClone(obj): doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document try: # Try to execute following md = mo.GeGetMoData(obj) # Get MoGraph data cnt = md.GetCount() # Get clone count for i in xrange(0, cnt): # Loop through clones tag = c4d.BaseTag(1021338) # Initialize MoGraph selection tag tag[c4d.ID_BASELIST_NAME] = "ms_" + str(i) s = c4d.BaseSelect() # Initialize BaseSelect obj.InsertTag(tag, obj.GetLastTag()) # Insert tag to object doc.AddUndo(c4d.UNDOTYPE_NEW, tag) # Add undo command for inserting tag s.Select(i) # Select clone mo.GeSetMoDataSelection(tag, s) # Set selection to tag except: # If something went wrong pass # Do nothing
def MoGraphSelectionFromRange(obj): #try: tag = obj.GetLastTag() # Get last tag of object tags = obj.GetTags() # Get object's tags md = mo.GeGetMoData(obj) # Get MoGraph data cnt = md.GetCount() # Get clone count prefix = "ms" # Prefix for selection tag sep = "_" # Separator for selection tag p = 0 # Initialize iteration variable userInput = g.InputDialog("Selected IDs for " + obj.GetName(), "") # User input dialog baseList = userInput.split(",") # Split user input to list add = [] # Initialize empty list finalList = [] # Initialize empty list for x in baseList: # Loop through list items rng = x.split("-") # Split range value (e.g. 5-15) if len(rng) > 1: for i in xrange(int(rng[0]), int(rng[1]) + 1): add.append(i) fullList = baseList + add for f in fullList: if type(f) is int: finalList.append(f) if type(f) is not int: if f.find("-") is -1: finalList.append(f) for k in reversed(tags): # Loop through tags if k.GetName().split("_")[0] == prefix: p = p + 1 # Increase iteration t = c4d.BaseTag(1021338) # Initialize MoGraph Selection tag t[c4d.ID_BASELIST_NAME] = prefix + sep + str(p) # Set tag name s = c4d.BaseSelect() # Initialize BaseSelect for f in finalList: # Loop through list s.Select(int(f)) # Select items obj.InsertTag(t) # Insert tag to object doc.AddUndo(c4d.UNDOTYPE_NEW, t) # Add undo command for inserting new tag mo.GeSetMoDataSelection(t, s) # Set MoGraph selection
def MoGraphSelectionFromRange(obj, keyMod): #try: userInput = g.InputDialog("Selected IDs for " + obj.GetName(), "") # User input dialog if userInput == "": return baseList = userInput.split(",") # Split user input to list add = [] # Initialize empty list finalList = [] # Initialize empty list for x in baseList: # Loop through list items rng = x.split("-") # Split range value (e.g. 5-15) if len(rng) > 1: for i in xrange(int(rng[0]), int(rng[1]) + 1): add.append(i) fullList = baseList + add for f in fullList: if type(f) is int: finalList.append(f) if type(f) is not int: if f.find("-") is -1: finalList.append(f) if keyMod == "None": tags = obj.GetTags() # Get object's tags prefix = "ms" # Prefix for selection tag sep = "_" # Separator for selection tag msNums = [] for k in tags: # Loop through tags if k.GetName().split("_")[0] == prefix: msNums.append(int(k.GetName().split("_")[1])) t = c4d.BaseTag(1021338) # Initialize MoGraph Selection tag if len(msNums) != 0: num = max(msNums) + 1 else: num = 0 t[c4d.ID_BASELIST_NAME] = prefix + sep + str(num) # Set tag name s = c4d.BaseSelect() # Initialize BaseSelect for f in finalList: # Loop through list s.Select(int(f)) # Select items obj.InsertTag(t, obj.GetLastTag()) # Insert tag to object doc.AddUndo(c4d.UNDOTYPE_NEW, t) # Add undo command for inserting new tag mo.GeSetMoDataSelection(t, s) # Set MoGraph selection elif keyMod == "Shift": prefix = "ms" # Prefix for selection tag sep = "_" # Separator for selection tag msNums = [] for i, f in enumerate(finalList): # Loop through list tags = obj.GetTags() # Get object's tags #for k in reversed(tags): # Loop through tags for k in tags: # Loop through tags if k.GetName().split("_")[0] == prefix: msNums.append(int(k.GetName().split("_")[1])) t = c4d.BaseTag(1021338) # Initialize MoGraph Selection tag if len(msNums) != 0: num = max(msNums) + 1 else: num = 0 t[c4d.ID_BASELIST_NAME] = prefix + sep + str(num) # Set tag name s = c4d.BaseSelect() # Initialize BaseSelect s.Select(int(f)) # Select items obj.InsertTag(t, obj.GetLastTag()) # Insert tag to object doc.AddUndo(c4d.UNDOTYPE_NEW, t) # Add undo command for inserting new tag mo.GeSetMoDataSelection(t, s) # Set MoGraph selection