def run(self): doc = documents.GetActiveDocument() doc.StartUndo() sel = doc.GetSelection() if sel is None: return False c4d.StatusSetSpin() timestart = c4d.GeGetMilliSeconds() c4d.StopAllThreads() # loop through all objects for op in sel: print op.GetName() # and do something with op # op.Message(c4d.MSG_UPDATE) c4d.StatusClear() # tell C4D to update internal state c4d.EventAdd() doc.EndUndo() timeend = int(c4d.GeGetMilliSeconds() - timestart) timemsg = u"MakeAwesomeButton: finished in " + str( timeend) + " milliseconds" print(timemsg) return True
def Copy(tmppath, converted): sel = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN) if not sel: gui.MessageDialog('Select some Objects first.') return c4d.StopAllThreads() c4d.StatusSetSpin() export = [] for obj in sel: #Convert Current State to Object for all selected Objects if converted: obj = Command_CSTO(obj) export.append(obj) if export == []: message = 'Sorry, nothing to Export.' gui.MessageDialog(message) return iso_objs=c4d.documents.IsolateObjects(doc, export) c4d.documents.SaveDocument(iso_objs, tmppath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, c4d.FORMAT_C4DEXPORT) c4d.StatusClear() message = 'Copied Object(s).' if converted: message = 'Copied converted Object(s).' gui.MessageDialog(message)
def main(undo = True): now = c4d.GeGetTimer() # start stopwatch c4d.CallCommand(13957) # Konsole löschen # c4d.CallCommand(12305) # Konsole... if GetActiveDocument(): doc = GetActiveDocument() if doc.GetFirstObject(): c4d.StatusSetSpin() op = doc.GetFirstObject() myobject = op counter = numberofobjects(op) secondcounter = 0 c4d.StatusSetText ('%s Objects are processed.' %(counter)) opactive = None else: print "Error: No Objects" return False else: print "Error: No Document" return False #doc.StartUndo() # Start undo support # iterate over all objects in the document c4d.CallCommand(12113) # Alles deselektieren while op: optemp = op op = GetNextObject(op) # get next object secondcounter += 1 statusbar(counter, secondcounter) if optemp.CheckType(c4d.Opolygon): optemp.SetBit(c4d.BIT_ACTIVE) if selchildren(optemp,optemp.GetNext()): c4d.CallCommand(16768) #Connect And Delete c4d.CallCommand(16768) #Connect And Delete opactive = doc.GetActiveObject() opactive.DelBit(c4d.BIT_ACTIVE) optemp.DelBit(c4d.BIT_ACTIVE) c4d.StatusClear() #doc.EndUndo() # Do not forget to close the undo support c4d.EventAdd() # update cinema 4d print 'END OF SCRIPT %s ms ' %(c4d.GeGetTimer() - now) return
def Paste(tmppath): c4d.StopAllThreads() c4d.StatusSetSpin() merge = c4d.documents.MergeDocument(doc, tmppath, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS | c4d.SCENEFILTER_MERGESCENE, None) c4d.StatusClear() if not merge: message = "Couldn't find Objects to paste...\nMake sure to export first." gui.MessageDialog(message) return c4d.EventAdd()
def ReplaceRendersettingsFromScene(scene, append=True): c4d.StatusSetSpin() message = """Replacing current Render-Settings from: %s""" % (scene) c4d.StatusSetText(message) tdoc = c4d.documents.LoadDocument( scene, c4d.SCENEFILTER_ONLY_RENDERDATA | c4d.SCENEFILTER_IGNOREMISSINGPLUGINSINNONACTIVERENDERDATA, None) if tdoc is None: return trd = tdoc.GetFirstRenderData() active = tdoc.GetActiveRenderData() clones = list() while trd: clones.append(trd.GetClone()) trd = trd.GetNext() rd = doc.GetFirstRenderData() current_rd = list() while rd: current_rd.append(rd) rd = rd.GetNext() doc.StartUndo() if not append: for rd in current_rd: doc.AddUndo(c4d.UNDOTYPE_DELETE, rd) rd.Remove() for trd in reversed(clones): doc.AddUndo(c4d.UNDOTYPE_NEW, trd) doc.InsertRenderDataLast(trd) if trd.GetData() == active.GetData(): doc.SetActiveRenderData(trd) doc.EndUndo() c4d.EventAdd() c4d.StatusSetBar(0) c4d.StatusClear()
def main(): colors_objects_mgs = {} doc.StartUndo() c4d.StatusSetText("[1/2]: Collating by color.") c4d.StatusSetSpin() # Store objects by color obj = doc.GetFirstObject() while obj: color = obj[c4d.ID_BASEOBJECT_COLOR] color_string = repr(color) mg = obj.GetMg() obj_mg = (obj, mg) if color_string in colors_objects_mgs.keys(): colors_objects_mgs[color_string].append(obj_mg) else: colors_objects_mgs[color_string] = [obj_mg] obj = GetNextObject(obj) c4d.StatusSetText("[2/2]: Grouping Objects.") # Build groups of objects by color pred_null = None for color_string, obj_mg_list in colors_objects_mgs.iteritems(): # Find the center position of the objects average_pos = c4d.Vector(0.0) for obj, mg in obj_mg_list: average_pos += mg.off average_pos /= float(len(obj_mg_list)) # Create a null centered between the objects null_obj = c4d.BaseObject(c4d.Onull) # Make it the same color as the objects null_obj[c4d.ID_BASEOBJECT_USECOLOR] = 1 # Automatic Mode null_obj[c4d.ID_BASEOBJECT_COLOR] = eval("c4d." + color_string) null_obj[c4d.NULLOBJECT_ICONCOL] = True # Center the null center_mg = c4d.Matrix() mg.off = average_pos # Ensure nulls are inserted roughly in the same order colors first occurred in the scene. doc.InsertObject(null_obj, pred=pred_null) pred_null = null_obj # Center the null null_obj.SetMg(center_mg) doc.AddUndo(c4d.UNDOTYPE_NEW, null_obj) # Move objects of the came color under the new null pred = None for obj, mg in obj_mg_list: doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj) obj.Remove() doc.InsertObject(obj, parent=null_obj, pred=pred) obj.SetMg(mg) pred = obj doc.EndUndo() c4d.EventAdd() c4d.StatusClear()