def main(): doc.StartUndo() tags = op.GetTags() mstag = c4d.BaseTag(1021338) i = 0 for x in tags: if x.GetType() == 1021338: plain = c4d.BaseObject(1021337) plain[c4d.ID_MG_BASEEFFECTOR_SELECTION] = x.GetName() #plain[c4d.ID_BASELIST_NAME] = plain[c4d.ID_BASELIST_NAME]+"_"+str(i) doc.InsertObject(plain) effList = c4d.InExcludeData() if op.GetType() == 1019268: effList = op[c4d.MGTEXTOBJECT_EFFECTORLIST_CHAR] effList.InsertObject(plain, 1) op[c4d.MGTEXTOBJECT_EFFECTORLIST_CHAR] = effList elif op.GetType() == 1018544 or op.GetType( ) == 1018791 or op.GetType() == 1018545: effList = op[c4d.ID_MG_MOTIONGENERATOR_EFFECTORLIST] effList.InsertObject(plain, 1) op[c4d.ID_MG_MOTIONGENERATOR_EFFECTORLIST] = effList elif op.GetType() == 1036557: effList = op[c4d.ID_MG_VF_MOTIONGENERATOR_EFFECTORLIST] effList.InsertObject(plain, 1) op[c4d.ID_MG_VF_MOTIONGENERATOR_EFFECTORLIST] = effList i = i + 1 doc.AddUndo(c4d.UNDOTYPE_NEW, plain) doc.EndUndo() c4d.EventAdd()
def tracerFromSelection(selection): doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document tracer = c4d.BaseObject(1018655) # Initialize tracer object tracerList = c4d.InExcludeData() # Initialize in-exclude data list for s in selection: # Loop through selection tracerList.InsertObject(s, 1) # Add object to list tracer[c4d. MGTRACEROBJECT_OBJECTLIST] = tracerList # Update tracer object list tracer[c4d.MGTRACEROBJECT_MODE] = 1 # 'Connect All Objects' tracer[c4d.MGTRACEROBJECT_USEPOINTS] = False # Disable 'Trace Vertices' doc.InsertObject(tracer) # Insert tracer object to document doc.AddUndo(c4d.UNDOTYPE_NEW, tracer) # Add undo command for inserting new object
def main(): # Gets selected objects and check if there is more than 1 object selected activeObjects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0) if not activeObjects: raise RuntimeError("Failed to retrieve selected objects.") # Gets the last object selected lodObject = doc.GetTargetObject() if not lodObject.CheckType(c4d.Olod): raise TypeError("last selected object is not a Lod Object.") # Defines parameters lodObject[c4d.LOD_MODE] = c4d.LOD_MODE_MANUAL_GROUPS lodObject[c4d.LOD_CRITERIA] = c4d.LOD_CRITERIA_MANUAL lodObject[c4d.LOD_LEVEL_COUNT_DYN] = len(activeObjects) - 1 level = 0 # Iterates over all active object for obj in activeObjects: if obj == lodObject: continue # Makes object a child object of the LOD object obj.Remove() doc.InsertObject(obj, lodObject) # Inserts object into "Objects" list of the given level listID = lodObject.GetManualModeObjectListDescID(level) if listID is None: continue # Creates InExcludeData inExData = c4d.InExcludeData() if inExData is None: continue # Inserts object into list inExData.InsertObject(obj, 1) # Sets parameter lodObject[listID] = inExData # Increments the level level = level + 1 # Pushes an update event to Cinema 4D c4d.EventAdd()
def main(): doc.StartUndo() active = doc.GetActiveObject() children = active.GetChildren() tracer = c4d.BaseObject(1018655) tracerlist = c4d.InExcludeData() for x in children: tracerlist.InsertObject(x, 1) tracer[c4d.MGTRACEROBJECT_OBJECTLIST] = tracerlist doc.InsertObject(tracer) doc.AddUndo(c4d.UNDOTYPE_NEW, tracer) c4d.EventAdd() doc.EndUndo()
def TracerFromObjects(selection, keyMod): tracer = c4d.BaseObject(1018655) # Initialize tracer object tracerList = c4d.InExcludeData() # Initialize in-exclude data list if keyMod == "Alt+Shift": # If Alt pressed for s in selection: # Loop through selection tracerList.InsertObject(s, 1) # Add object to list elif keyMod == "Alt+Ctrl": # If Alt and Ctrl pressed objectManagerSelection = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN) # Include children also if selected for s in objectManagerSelection: # Loop through selection tracerList.InsertObject(s, 1) # Add object to list tracer[c4d.MGTRACEROBJECT_OBJECTLIST] = tracerList # Update tracer object list tracer[c4d.MGTRACEROBJECT_MODE] = 1 # 'Connect All Objects' tracer[c4d.MGTRACEROBJECT_USEPOINTS] = False # Disable 'Trace Vertices' doc.InsertObject(tracer) # Insert tracer object to document doc.AddUndo(c4d.UNDOTYPE_NEW, tracer) # Add undo command for inserting new object tracer.SetBit(c4d.BIT_ACTIVE) # Select tracer object
def main(): doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document doc.StartUndo() # Start recording undos selected = doc.GetActiveObject() # Get selected object children = selected.GetChildren() # Get selected object's children tracer = c4d.BaseObject(1018655) # Initialize tracer object tracerList = c4d.InExcludeData() # Initialize in-exclude data list for obj in children: # Loop through children objects tracerList.InsertObject(obj, 1) # Add object to list tracer[c4d. MGTRACEROBJECT_OBJECTLIST] = tracerList # Update tracer object list doc.InsertObject(tracer) # Insert tracer object to document doc.AddUndo(c4d.UNDOTYPE_NEW, tracer) # Add undo command for inserting new object doc.EndUndo() # Stop recording undos c4d.EventAdd() # Refresh Cinema 4D
def PlainEffForEveryMgSelTag(obj): doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document tags = obj.GetTags() # Get object's tags mstag = c4d.BaseTag(1021338) # Initialize MoGraph selection tag i = 0 # Initialize iteration variable generators = { # MoGraph generators dictionary 'Cloner': 1018544, 'Matrix': 1018545, 'Fracture': 1018791, 'MoSpline': 440000054, 'MoInstance': 1018957, 'Voronoi Fracture': 1036557, 'MoText': 1019268, 'MoExtrude': 1019358, 'PolyFX': 1019222, } for x in tags: # Loop through tags if x.GetType() == 1021338: # If tag is MoGraph selection tag plain = c4d.BaseObject(1021337) # Initialize plain effector plain[c4d.ID_MG_BASEEFFECTOR_SELECTION] = x.GetName() # Set MoGraph selection tag to plain effector selection doc.InsertObject(plain) # Insert plain effector doc.AddUndo(c4d.UNDOTYPE_NEW, plain) # Add undo command for inserting plain effector to document effList = c4d.InExcludeData() # Initialize effector list if obj.GetType() == generators['MoText']: # If object is MoText effList = obj[c4d.MGTEXTOBJECT_EFFECTORLIST_CHAR] # Clone generator's effector lsit effList.InsertObject(plain,1) # Add plain effector to effector list obj[c4d.MGTEXTOBJECT_EFFECTORLIST_CHAR] = effList # Set updated effector list elif obj.GetType() == generators['Voronoi Fracture']: # If object is Voronoi Fracture effList = obj[c4d.ID_MG_VF_MOTIONGENERATOR_EFFECTORLIST] effList.InsertObject(plain,1) obj[c4d.ID_MG_VF_MOTIONGENERATOR_EFFECTORLIST] = effList elif obj.GetType() == generators['MoSpline']: # If object is MoSpline effList = obj[c4d.MGMOSPLINEOBJECT_EFFECTORLIST] effList.InsertObject(plain,1) obj[c4d.MGMOSPLINEOBJECT_EFFECTORLIST] = effList else: # If object is any else MoGraph generator effList = obj[c4d.ID_MG_MOTIONGENERATOR_EFFECTORLIST] effList.InsertObject(plain,1) obj[c4d.ID_MG_MOTIONGENERATOR_EFFECTORLIST] = effList i = i + 1 # Increase iteration variable value by one
def main(): activeObjects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0) if len(activeObjects) <= 1: return lodObject = doc.GetTargetObject() if lodObject.GetType() != c4d.Olod: return lodObject[c4d.LOD_MODE] = c4d.LOD_MODE_MANUAL_GROUPS lodObject[c4d.LOD_CRITERIA] = c4d.LOD_CRITERIA_MANUAL lodObject[c4d.LOD_LEVEL_COUNT_DYN] = len(activeObjects) - 1 for level, object in enumerate(activeObjects): if object == lodObject: continue # make object a child object of the LOD object object.Remove() doc.InsertObject(object, lodObject) # insert object into "Objects" list of the given level listID = lodObject.GetManualModeObjectListDescID(level) if listID is not None: # create InEx data inExData = c4d.InExcludeData() if inExData is not None: # insert object into list inExData.InsertObject(object, 1) # set parameter lodObject[listID] = inExData c4d.EventAdd()
def main(): # ------------------------------------------------------ # get original obj list obj_list_origin = get_allObjs(doc.GetFirstObject()) # ------------------------------------------------------ # load external alembic load_dlg = c4d.storage.LoadDialog(type=c4d.FILESELECTTYPE_ANYTHING, title="", flags=c4d.FILESELECT_LOAD, force_suffix="", def_path="", def_file="") if not load_dlg: return c4d.documents.MergeDocument( doc, load_dlg, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS, None) # loop elements to organize new alembic objs obj = doc.GetFirstObject() obj_loop = True obj_list = [obj] # abc objs loop iterations while obj_loop: obj = obj.GetNext() if obj.GetType() == OBJ_ABC_GENERATOR: obj_list.append(obj) else: obj_loop = False # move all abc objs into a main parent null null = c4d.BaseObject(c4d.Onull) null_name = load_dlg.split('\\') null_name = null_name[-1] null_name = null_name.split('.') null[c4d.ID_BASELIST_NAME] = null_name[0] null.InsertBefore(obj_list[0]) null.SetBit(c4d.BIT_ACTIVE) for obj in obj_list: obj.InsertUnderLast(null) main_geo = doc.SearchObject('_geo_') if main_geo: null.InsertUnder(main_geo) # make obj list with children obj_list = get_allObjs(null) for obj in obj_list_origin: if obj in obj_list: obj_list.remove(obj) else: continue # ------------------------------------------------------ # import external documents # import materials and layers c4d.documents.MergeDocument( doc, tree_document_materials, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS, None) obj_mat = doc.SearchObject('Materials_Arbol') # find new object obj_mat.Remove() # delete null obj # import eyes lights rig c4d.documents.MergeDocument( doc, tree_document_eyeslightrig, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS, None) obj_eyes_lighstrig = doc.SearchObject('Eyes Rig') # find new object main_lights = doc.SearchObject('_lights_') # find main lights group if main_lights: obj_eyes_lighstrig.InsertUnder( main_lights) # insert eyes lights rig inside main light group # ------------------------------------------------------ # get layer layer = find_layer(tree_layer_objs) if not layer: return layer_mats = find_layer(tree_layer_mats) if not layer: gui.MessageDialog( 'this scene does not have the needed material layer.') return # get mats mats = doc.GetMaterials() mats_character = [] for mat in mats: if mat[c4d.ID_LAYER_LINK]: if mat[c4d.ID_LAYER_LINK].GetName() == tree_layer_mats: mats_character.append(mat) # ------------------------------------------------------ # add eyes geometries into eyes lights rig tree_eye_r = make_editable(doc.SearchObject('R_XmasTree_eye')) tree_eye_l = make_editable(doc.SearchObject('L_XmasTree_eye')) obj_eyes_lighstrig[c4d.ID_USERDATA, 3] = tree_eye_r # add right eye obj_eyes_lighstrig[c4d.ID_USERDATA, 6] = tree_eye_l # add left eye # add geometries into include light lists lightR_InEx = c4d.InExcludeData() lightR_InEx.InsertObject(tree_eye_r, 1) lightL_InEx = c4d.InExcludeData() lightL_InEx.InsertObject(tree_eye_l, 1) light_eye_R = doc.SearchObject('Eye R - Disc Light') light_eye_L = doc.SearchObject('Eye L - Disc Light') light_eye_R[c4d.REDSHIFT_LIGHT_EXCLUSION_LIST] = lightR_InEx light_eye_L[c4d.REDSHIFT_LIGHT_EXCLUSION_LIST] = lightL_InEx # ------------------------------------------------------ # import tags from external document *delete them in child ops c4d.documents.MergeDocument( doc, tree_document_tags, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS, None) obj_tag_eyes = doc.SearchObject('R_XmasTree_eye_tags') obj_tag_tongue = doc.SearchObject('XmasTree_tongue_tags') obj_tag_body = doc.SearchObject('XmasTree_body_tags') # ------------------------------------------------------ # add all objs in layer for obj in obj_list: obj[c4d.ID_LAYER_LINK] = layer # ------------------------------------------------------ # main parent commands main_parent = null add_redshift_tag(main_parent, layer, True, True, 1, 3, 0, 0, 0, 0, 0, 0, 1, 30) # add main redshift tag obj_list.remove(null) # remove main parent from obj list # ------------------------------------------------------ # add_redshift_tag(obj,layer,geometry,tessellation,tess_min,tess_max,displacement,dis_max,dis_scale,dis_autobump,reference,ref_source,obj_id,obj_id_value) # add redshift tag # ------------------------------------------------------ # children ops for obj in obj_list: if obj.GetName() == tree_nameslist[0]: # R_XmasTree_eyelid_top display_color(obj, tree_color_blue) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[5]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Body add_redshift_tag(obj, layer, True, True, 0, 3, True, 1, 1, False, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, False, False) # add redshift tag elif obj.GetName() == tree_nameslist[1]: # R_XmasTree_eyelid_botton display_color(obj, tree_color_blue) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[5]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Body add_redshift_tag(obj, layer, True, True, 0, 3, True, 1, 1, False, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, False, False) # add redshift tag elif obj.GetName() == tree_nameslist[2]: # R_XmasTree_eye #display_color(obj,tree_color_white) # display color tag = tag_copy(obj_tag_eyes, c4d.Tpolygonselection, obj) # copy polygon selection tags addTexTag(obj, layer, find_mat(mats_character, tree_matslist[3]), TAG_TEXTURE_PROJECTION_UVW, tag.GetName()) # add material - Tree_Eye addTexTag(obj, layer, find_mat(mats_character, tree_matslist[4]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Iris add_redshift_tag(obj, layer, 0, 0, 0, 0, 0, 0, 0, 0, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, 0, 0) # add redshift tag elif obj.GetName() == tree_nameslist[3]: # L_XmasTree_eyelid_top display_color(obj, tree_color_blue) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[5]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Body add_redshift_tag(obj, layer, True, True, 0, 3, True, 1, 1, False, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, False, False) # add redshift tag elif obj.GetName() == tree_nameslist[4]: # L_XmasTree_eyelid_botton display_color(obj, tree_color_blue) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[5]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Body add_redshift_tag(obj, layer, True, True, 0, 3, True, 1, 1, False, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, False, False) # add redshift tag elif obj.GetName() == tree_nameslist[5]: # L_XmasTree_eye #display_color(obj,tree_color_white) # display color tag = tag_copy(obj_tag_eyes, c4d.Tpolygonselection, obj) # copy polygon selection tags obj_tag_eyes.Remove() addTexTag(obj, layer, find_mat(mats_character, tree_matslist[3]), TAG_TEXTURE_PROJECTION_UVW, tag.GetName()) # add material - Tree_Eye addTexTag(obj, layer, find_mat(mats_character, tree_matslist[4]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Iris add_redshift_tag(obj, layer, 0, 0, 0, 0, 0, 0, 0, 0, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, 0, 0) # add redshift tag elif obj.GetName() == tree_nameslist[6]: # XmasTree_tongue obj = make_editable(obj) display_color(obj, tree_color_blue) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[2]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Tongue add_redshift_tag(obj, layer, 0, 0, 0, 0, 0, 0, 0, 0, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, True, 32) # add redshift tag tag_copy(obj_tag_tongue, c4d.Tvertexmap, obj) # copy polygon selection tags elif obj.GetName() == tree_nameslist[7]: # XmasTree_teeths display_color(obj, tree_color_white) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[1]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Teeths add_redshift_tag(obj, layer, 0, 0, 0, 0, 0, 0, 0, 0, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, 0, 0) # add redshift tag elif obj.GetName() == tree_nameslist[8]: # XmasTree_legs display_color(obj, tree_color_blue) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[5]), TAG_TEXTURE_PROJECTION_SPHERICAL, '') # add material - Tree_Body add_redshift_tag(obj, layer, True, True, 0, 3, True, 1, 1, False, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, False, False) # add redshift tag elif obj.GetName() == tree_nameslist[9]: # XmasTree_top_2 display_color(obj, tree_color_lime) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[0]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Ribbon and Gloves Cloth add_redshift_tag(obj, layer, 0, 0, 0, 0, 0, 0, 0, 0, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, True, 31) # add redshift tag elif obj.GetName() == tree_nameslist[10]: # XmasTree_top_1 display_color(obj, tree_color_lime) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[0]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Ribbon and Gloves Cloth add_redshift_tag(obj, layer, 0, 0, 0, 0, 0, 0, 0, 0, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, True, 31) # add redshift tag elif obj.GetName() == tree_nameslist[11]: # XmasTree_band display_color(obj, tree_color_lime) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[0]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Ribbon and Gloves Cloth add_redshift_tag(obj, layer, 0, 0, 0, 0, 0, 0, 0, 0, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, True, 31) # add redshift tag elif obj.GetName() == tree_nameslist[12]: # XmasTree_Knot_3 display_color(obj, tree_color_lime) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[0]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Ribbon and Gloves Cloth add_redshift_tag(obj, layer, 0, 0, 0, 0, 0, 0, 0, 0, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, True, 31) # add redshift tag elif obj.GetName() == tree_nameslist[13]: # XmasTree_Knot_2 display_color(obj, tree_color_lime) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[0]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Ribbon and Gloves Cloth add_redshift_tag(obj, layer, 0, 0, 0, 0, 0, 0, 0, 0, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, True, 31) # add redshift tag elif obj.GetName() == tree_nameslist[14]: # XmasTree_Knot_1 display_color(obj, tree_color_lime) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[0]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Ribbon and Gloves Cloth add_redshift_tag(obj, layer, 0, 0, 0, 0, 0, 0, 0, 0, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, True, 31) # add redshift tag elif obj.GetName() == tree_nameslist[15]: # XmasTree_gloves display_color(obj, tree_color_lime) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[0]), TAG_TEXTURE_PROJECTION_UVW, '') # add material - Tree_Ribbon and Gloves Cloth add_redshift_tag(obj, layer, 0, 0, 0, 0, 0, 0, 0, 0, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, True, 31) # add redshift tag elif obj.GetName() == tree_nameslist[16]: # XmasTree_body obj = make_editable(obj) display_color(obj, tree_color_blue) # display color addTexTag(obj, layer, find_mat(mats_character, tree_matslist[5]), TAG_TEXTURE_PROJECTION_SPHERICAL, '') # add material - Tree_Body add_redshift_tag(obj, layer, True, True, 0, 3, True, 1, 1, False, True, TAG_REDSHIFT_REFERENCE_SNAPSHOT, 0, 0) # add redshift tag tag_copy(obj_tag_body, c4d.Tvertexmap, obj) # copy polygon selection tags else: None # ------------------------------------------------------ # remove imported objects obj_tag_tongue.Remove() obj_tag_body.Remove() # ------------------------------------------------------ c4d.EventAdd() print 'Tree imported successfully.'