def main(): # Get Alembic export plugin, 1028082 is its ID plug = plugins.FindPlugin(1028082, c4d.PLUGINTYPE_SCENESAVER) if plug is None: return # Get a path to save the exported file filePath = storage.LoadDialog(title="Save File for Alembic Export", flags=c4d.FILESELECT_SAVE, force_suffix="abc") if filePath is None: return op = {} # Send MSG_RETRIEVEPRIVATEDATA to Alembic export plugin if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op): print op if "imexporter" not in op: return # BaseList2D object stored in "imexporter" key hold the settings abcExport = op["imexporter"] if abcExport is None: return # Change Alembic export settings abcExport[c4d.ABCEXPORT_SELECTION_ONLY] = True abcExport[c4d.ABCEXPORT_PARTICLES] = True abcExport[c4d.ABCEXPORT_PARTICLE_GEOMETRY] = True # Finally export the document if documents.SaveDocument(doc, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1028082): print "Document successfully exported to:" print filePath else: print "Export failed!"
def fireAction(pObj): tool = plugins.FindPlugin(doc.GetAction(), c4d.PLUGINTYPE_TOOL) if tool is not None: #gui.MessageDialog(tool) tool[c4d.MDATA_TRANSFER_OBJECT_LINK] = pObj c4d.CallButton(tool, c4d.MDATA_APPLY) c4d.EventAdd()
def importStorageSystem(selectedFile): doc = c4d.documents.GetActiveDocument() if selectedFile is None: return # Find the FBX importer plugin plug = plugins.FindPlugin(1026369, c4d.PLUGINTYPE_SCENELOADER) if plug is None: return # Access the settings op = {} if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op): print op fbximport = op["imexporter"] if fbximport is None: return # Define the settings fbximport[c4d.FBXIMPORT_CAMERAS] = False # Import without dialogs c4d.documents.MergeDocument( doc, selectedFile, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS, None) c4d.EventAdd()
def exportDAE15(filePath,doc): pluginID = 1025755 plug = plugins.FindPlugin(pluginID, c4d.PLUGINTYPE_SCENESAVER) if plug is None: return op = {} # Send MSG_RETRIEVEPRIVATEDATA to export plugin if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op): if "imexporter" not in op: return # BaseList2D object stored in "imexporter" key hold the settings xExport = op["imexporter"] if xExport is None: return # Change export settings xExport[c4d.COLLADA_EXPORT_TRIANGLES] = False xExport[c4d.COLLADA_EXPORT_ANIMATION] = False xExport[c4d.COLLADA_EXPORT_GROUP] = True xExport[c4d.COLLADA_EXPORT_2D_GEOMETRY] = False xExport[c4d.COLLADA_EXPORT_SCALE] = 1 # Export the document if documents.SaveDocument(doc, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, pluginID): #print "Successfully exported: " + str(filePath) return else: print "Export failed for: " + str(filePath)
def SetExporter(doc): plug = plugins.FindPlugin(1012074, c4d.PLUGINTYPE_SCENESAVER) if plug is None: return data = {} if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, data): if "imexporter" not in data: return aiExport = data["imexporter"] if aiExport is None: return # Change Illustrator export settings aiExport[c4d.TUAIEXPORT_OUTPUTSIZE] = 0 # Output: Render aiExport[c4d.TUAIEXPORT_ZSORT] = 0 aiExport[c4d.TUAIEXPORT_SCALE] = 1 # Scale: 100% aiExport[c4d.TUAIEXPORT_EXPORTLINES] = 1 # Export lines aiExport[c4d.TUAIEXPORT_LINEOPACITY] = 0 # Disable line opacity aiExport[c4d.TUAIEXPORT_LINETHICKNESS] = 0 # Disable line thickness aiExport[c4d.TUAIEXPORT_LINEPATTERNS] = 0 # Disable line patterns aiExport[c4d.TUAIEXPORT_LINECONNECTIONS] = 1 # Enable line connections aiExport[c4d.TUAIEXPORT_EXPORTSURFACE] = 0 # Disable surface export aiExport[c4d.TUAIEXPORT_ANIMATION] = 1 # Export animation aiExport[c4d.TUAIEXPORT_ANIMTYPE] = 0 # Output As: Files aiExport[c4d.TUAIEXPORT_FRAMES] = 2 # Frames: Manual aiExport[c4d.TUAIEXPORT_FRAME_START] = doc.GetLoopMinTime() # Animation first frame aiExport[c4d.TUAIEXPORT_FRAME_END] = doc.GetLoopMaxTime() # Animation last frame aiExport[c4d.TUAIEXPORT_FRAME_RATE] = doc.GetFps() # Frame rate
def find_engine(): engine = doc.GetActiveRenderData() engine_id = engine[c4d.RDATA_RENDERENGINE] base_plug = plugins.FindPlugin(engine_id, c4d.PLUGINTYPE_VIDEOPOST) if base_plug is None: return "Native" if "Redshift" in base_plug.GetName(): return "Redshift" if "Octane" in base_plug.GetName(): return "Octane"
def main(): # Get OBJ import plugin, 1030177 is its ID plug = plugins.FindPlugin(1030177, c4d.PLUGINTYPE_SCENELOADER) if plug is None: print("fatal error can't find obj import plugin") return ischecked = c4d.IsCommandChecked(170009) print("showuvmesh checked:", ischecked) if ischecked == False: c4d.CallCommand(170009, 170009) # Show UV Mesh for structure in inputfilenames: do_one_file(structure) print("structure = ", structure)
def exportFBX(filePath,doc): pluginID = 1026370 plug = plugins.FindPlugin(pluginID, c4d.PLUGINTYPE_SCENESAVER) if plug is None: return op = {} # Send MSG_RETRIEVEPRIVATEDATA to export plugin if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op): if "imexporter" not in op: return # BaseList2D object stored in "imexporter" key hold the settings xExport = op["imexporter"] if xExport is None: return # Change export settings #unit_scale = c4d.UnitScaleData() #unit_scale.SetUnitScale(1.0, c4d.DOCUMENT_UNIT_CM) #xExport[c4d.FBXEXPORT_SCALE] = unit_scale xExport[c4d.FBXEXPORT_FBX_VERSION] = c4d.FBX_EXPORTVERSION_7_4_0 xExport[c4d.FBXEXPORT_ASCII] = False xExport[c4d.FBXEXPORT_TEXTURES] = True xExport[c4d.FBXEXPORT_EMBED_TEXTURES] = False xExport[c4d.FBXEXPORT_SAVE_NORMALS] = True xExport[c4d.FBXEXPORT_TRIANGULATE] = False xExport[c4d.FBXEXPORT_LIGHTS] = False xExport[c4d.FBXEXPORT_CAMERAS] = False xExport[c4d.FBXEXPORT_SPLINES] = False xExport[c4d.FBXEXPORT_SDS] = False # Export the document if documents.SaveDocument(doc, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, pluginID): #print "Successfully exported: " + str(filePath) return else: print "Export failed for: " + str(filePath)
def exportOBJ(filePath,doc): pluginID = 1030178 plug = plugins.FindPlugin(pluginID, c4d.PLUGINTYPE_SCENESAVER) if plug is None: return op = {} # Send MSG_RETRIEVEPRIVATEDATA to export plugin if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op): if "imexporter" not in op: return # BaseList2D object stored in "imexporter" key hold the settings xExport = op["imexporter"] if xExport is None: return #unit_scale = c4d.UnitScaleData() #unit_scale.SetUnitScale(1.0, c4d.DOCUMENT_UNIT_CM) #xExport[c4d.OBJEXPORTOPTIONS_SCALE] = unit_scale xExport[c4d.OBJEXPORTOPTIONS_NORMALS] = True xExport[c4d.OBJEXPORTOPTIONS_MATERIAL] = True xExport[c4d.OBJEXPORTOPTIONS_MATERIAL] = c4d.OBJEXPORTOPTIONS_MATERIAL_MATERIAL xExport[c4d.OBJEXPORTOPTIONS_TEXTURECOORDINATES] = True xExport[c4d.OBJEXPORTOPTIONS_OBJECTS_AS_GROUPS] = True xExport[c4d.OBJEXPORTOPTIONS_POINTTRANSFORM_FLIPX] = False xExport[c4d.OBJEXPORTOPTIONS_POINTTRANSFORM_FLIPY] = False xExport[c4d.OBJEXPORTOPTIONS_POINTTRANSFORM_FLIPZ] = False xExport[c4d.OBJEXPORTOPTIONS_POINTTRANSFORM_SWAPYZ] = False xExport[c4d.OBJEXPORTOPTIONS_POINTTRANSFORM_SWAPXZ] = False xExport[c4d.OBJEXPORTOPTIONS_POINTTRANSFORM_SWAPXY] = False xExport[c4d.OBJEXPORTOPTIONS_INVERT_TRANSPARENCY] = False xExport[c4d.OBJEXPORTOPTIONS_FLIPFACES] = False xExport[c4d.OBJEXPORTOPTIONS_FLIPUVW] = False # Export the document if documents.SaveDocument(doc, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, pluginID): #print "Successfully exported: " + str(filePath) return else: print "Export failed for: " + str(filePath)
def main(): objs = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN) size = len(objs) i=0 e=0 for obj in objs: name = obj[c4d.ID_BASELIST_NAME] name = name.split(".")[0] i+=1 e+=1 print str(i) + "/" + str(size) + " " + name # Get Alembic export plugin, 1028082 is its ID plug = plugins.FindPlugin(1028082, c4d.PLUGINTYPE_SCENESAVER) if plug is None: return filePath = "//192.168.10.45/server_01/2018/claro_and_cia/shot_010/3d/houdini/footage/alembic/" + name + ".abc" doc.SetSelection( obj , c4d.SELECTION_NEW) #new active selection for each object c4d.EventAdd() #update selectoin op = {} if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op): # BaseList2D object stored in "imexporter" key hold the settings abcExport = op["imexporter"] # Change Alembic export settings abcExport[c4d.ABCEXPORT_SELECTION_ONLY] = True # Finally export the document if documents.SaveDocument(doc, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1028082): None else: print "Export failed!"
def main(): # Define the main function of the script tool = plugins.FindPlugin( doc.GetAction(), c4d.PLUGINTYPE_TOOL ) # Define tool to find what the currently selected tool if tool is not None: # If there is a tool: doc.StartUndo( ) # Marks the beginning of a range of code that should be reversible doc.AddUndo(c4d.UNDOTYPE_CHANGE, tool) # Make the following button click reversible c4d.CallButton(tool, c4d.MDATA_APPLY) # Make the "Apply" button click c4d.EventAdd() # Refresh the scene to update the change doc.EndUndo( ) # Marks the end of a range of code that should be reversible c4d.EventAdd() # Refresh the scene to update the change
def main(): # Get OBJ import plugin, 1030177 is its ID plug = plugins.FindPlugin(1030177, c4d.PLUGINTYPE_SCENELOADER) if plug is None: return # Get a path to load the imported file selectedFile = c4d.storage.LoadDialog(title="Load File for OBJ Import", type=c4d.FILESELECTTYPE_ANYTHING, force_suffix="obj") if selectedFile is None: return op = {} # Send MSG_RETRIEVEPRIVATEDATA to OBJ import plugin if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op): print op if "imexporter" not in op: return # BaseList2D object stored in "imexporter" key hold the settings objImport = op["imexporter"] if objImport is None: return # Define the settings # Examples of OBJ import settings from the UI: objImport[c4d.OBJIMPORTOPTIONS_PHONG_ANGLE_DEFAULT] = 22.5 objImport[c4d.OBJIMPORTOPTIONS_TEXTURECOORDINATES] = True objImport[ c4d.OBJIMPORTOPTIONS_SPLITBY] = c4d.OBJIMPORTOPTIONS_SPLITBY_OBJECT objImport[ c4d. OBJIMPORTOPTIONS_MATERIAL] = c4d.OBJIMPORTOPTIONS_MATERIAL_MTLFILE objImport[c4d.OBJIMPORTOPTIONS_POINTTRANSFORM_FLIPZ] = True # objImport[c4d.] = # Import without dialogs c4d.documents.MergeDocument( doc, selectedFile, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS, None) c4d.EventAdd()
def main(): # Get SketchUp import plugin, 1033845 is its ID plug = plugins.FindPlugin(1033845, c4d.PLUGINTYPE_SCENELOADER) if plug is None: return # Get a path to load the imported file selectedFile = c4d.storage.LoadDialog( title="Load File for SketchUp Import", type=c4d.FILESELECTTYPE_ANYTHING, force_suffix="skp") if selectedFile is None: return op = {} # Send MSG_RETRIEVEPRIVATEDATA to SketchUp import plugin if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op): print op if "imexporter" not in op: return # BaseList2D object stored in "imexporter" key hold the settings skpImport = op["imexporter"] if skpImport is None: return # Define the settings # Examples of SketchUp settings from the UI (either True or False): skpImport[c4d.SKPIMPORT_DAYLIGHT_SYSTEM_PHYSICAL_SKY] = True skpImport[c4d.SKPIMPORT_CAMERA] = True skpImport[c4d.SKPIMPORT_SKIP_HIDDEN_OBJECTS] = True skpImport[c4d.SKPIMPORT_SPLIT_OBJECTS_BY_LAYER] = True skpImport[c4d.SKPIMPORT_SHOW_STATISTICS_IN_CONSOLE] = True # Import without dialogs c4d.documents.MergeDocument( doc, selectedFile, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS, None) c4d.EventAdd()
def main(): # Get OBJ export plugin, 1030178 is its ID plug = plugins.FindPlugin(1030178, c4d.PLUGINTYPE_SCENESAVER) if plug is None: return # Get a path to save the exported file filePath = c4d.storage.LoadDialog(title="Save File for OBJ Export", flags=c4d.FILESELECT_SAVE, force_suffix="obj") if filePath is None: return op = {} # Send MSG_RETRIEVEPRIVATEDATA to OBJ export plugin if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op): print op if "imexporter" not in op: return # BaseList2D object stored in "imexporter" key hold the settings objExport = op["imexporter"] if objExport is None: return # Define the settings # Example of OBJ export settings from the UI: objExport[c4d.OBJEXPORTOPTIONS_TEXTURECOORDINATES] = True objExport[c4d.OBJEXPORTOPTIONS_MATERIAL] = c4d.OBJEXPORTOPTIONS_MATERIAL_MATERIAL # objExport[c4d.] = # export without dialogs if c4d.documents.SaveDocument(doc, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1030178): print "Document successfully exported to:" print filePath else: print "Export failed!" c4d.EventAdd()
def exportVRML2(filePath,doc): pluginID = 1001034 plug = plugins.FindPlugin(pluginID, c4d.PLUGINTYPE_SCENESAVER) if plug is None: return op = {} # Send MSG_RETRIEVEPRIVATEDATA to export plugin if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op): if "imexporter" not in op: return # BaseList2D object stored in "imexporter" key hold the settings xExport = op["imexporter"] if xExport is None: return #unit_scale = c4d.UnitScaleData() #unit_scale.SetUnitScale(1.0, c4d.DOCUMENT_UNIT_CM) #xExport[c4d.VRML2EXPORTFILTER_SCALE] = unit_scale xExport[c4d.OBJEXPORTOPTIONS_NORMALS] = True xExport[c4d.VRML2EXPORTFILTER_TEXTURES] = c4d.VRML2EXPORTFILTER_TEXTURES_REFERENCED # VRML2EXPORTFILTER_TEXTURES_NONE, VRML2EXPORTFILTER_TEXTURES_INFILE xExport[c4d.VRML2EXPORTFILTER_BACKFACECULLING] = True xExport[c4d.VRML2EXPORTFILTER_FORMAT] = True #xExport[c4d.VRML2EXPORTFILTER_TEXTURESIZE] = #xExport[c4d.VRML2EXPORTFILTER_SAVEANIMATION] = False #Export[c4d.VRML2EXPORTFILTER_KEYSPERSECOND] = 25 # Export the document if documents.SaveDocument(doc, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, pluginID): #print "Successfully exported: " + str(filePath) return else: print "Export failed for: " + str(filePath)
def exportABC(filePath,doc): # Get Alembic export plugin, 1028082 is its ID plug = plugins.FindPlugin(1028082, c4d.PLUGINTYPE_SCENESAVER) if plug is None: return # Get a path to save the exported file #filePath ="/Users/digitalmedia/Documents/TEMP/TEST-EXPORT/boxX.fbx" op = {} # Send MSG_RETRIEVEPRIVATEDATA to Alembic export plugin if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op): if "imexporter" not in op: return # BaseList2D object stored in "imexporter" key hold the settings abcExport = op["imexporter"] if abcExport is None: return #print 'SELECTION BEFORE: ', abcExport[c4d.ABCEXPORT_SELECTION_ONLY] # Change Alembic export settings abcExport[c4d.ABCEXPORT_SELECTION_ONLY] = False abcExport[c4d.ABCEXPORT_PARTICLES] = False abcExport[c4d.ABCEXPORT_PARTICLE_GEOMETRY] = False #print 'SELECTION AFTER: ', abcExport[c4d.ABCEXPORT_SELECTION_ONLY] # Finally export the document if documents.SaveDocument(doc, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1028082): #print "Successfully exported: " + str(filePath) return else: print "Export failed!"
def export3DS(filePath,doc): pluginID = 1001038 plug = plugins.FindPlugin(pluginID, c4d.PLUGINTYPE_SCENESAVER) if plug is None: return op = {} # Send MSG_RETRIEVEPRIVATEDATA to export plugin if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op): if "imexporter" not in op: return # BaseList2D object stored in "imexporter" key hold the settings xExport = op["imexporter"] if xExport is None: return # Change export settings #unit_scale = c4d.UnitScaleData() #unit_scale.SetUnitScale(1.0, c4d.DOCUMENT_UNIT_CM) #xExport[c4d.F3DEXPORTOPTIONS_SCALE] = unit_scale xExport[c4d.F3DSEXPORTFILTER_GROUP] = False xExport[c4d.F3DSEXPORTFILTER_SPLITTEXCOORDS] = True # Export the document if documents.SaveDocument(doc, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, pluginID): #print "Successfully exported: " + str(filePath) return else: print "Export failed for: " + str(filePath)
def main(): fn = c4d.storage.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, "Folder to export", c4d.FILESELECT_DIRECTORY) if not fn: return # If cancelled stop the script doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document objects = doc.GetObjects() # Get objects plug = plugins.FindPlugin(1030178, c4d.PLUGINTYPE_SCENESAVER) if plug is None: return data = {} if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, data): if "imexporter" not in data: return objExport = data["imexporter"] if objExport is None: return for i, obj in enumerate(objects): # Iterate through objects tempDoc = c4d.documents.BaseDocument() # Initiralize a temp document clone = obj.GetClone() # Get clone of the original object tags = obj.GetTags() # Get object's tags for t in tags: # Loop through tags if isinstance(t, c4d.TextureTag): # If texture tag mat = t[c4d.TEXTURETAG_MATERIAL] # Get material tempDoc.InsertMaterial( mat) # Insert material to the temp document tempDoc.InsertObject(clone) # Insert clone to the temp document name = obj.GetName() path = os.path.splitext(fn)[0] + "\\" + name + ".obj" # File name c4d.documents.SaveDocument(tempDoc, path, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1030178) # Export OBJ-file tempDoc.Flush() # Flush temp doc c4d.StatusSetText("Export complete!") # Set status text c4d.EventAdd() # Refresh Cinema 4D
def prefs(id): return plugins.FindPlugin(id, c4d.PLUGINTYPE_PREFS)
def Execute(self, filepath, exportanim, exportnulls, removexrefs, removetextags): self.doc = documents.GetActiveDocument() assert self.doc is not None c4d.StopAllThreads() # Get the COLLADA export plugin colladaPlugin = plugins.FindPlugin(colladaPluginId, c4d.PLUGINTYPE_SCENESAVER) assert colladaPlugin is not None # Perform requested geometry merges, can only be done on current document, # so this will be undone at the end. mergeObjects = self.GetMergeGeometryObjs(self.doc.GetFirstObject(), []) self.MergeGeometry(mergeObjects) # Clone the current document so the modifications aren't applied to the original scene self.docCopy = self.doc.GetClone(c4d.COPYFLAGS_DOCUMENT) assert self.docCopy is not None # Remove xrefs if removexrefs is True: self.RemoveXRefs(self.docCopy.GetFirstObject()) # Remove objects that are on non-exporting layers removeObjects = self.RemoveNonExporting(self.docCopy.GetFirstObject(), []) for op in removeObjects: op.Remove() # Add object export settings as metadata appended to object names self.ExportDataToNameMeta(self.docCopy.GetFirstObject()) # Add object GUIDs to object names, to force a unique name self.ExportGUIDToName(self.docCopy.GetFirstObject()) # Collect warnings for names that are too long self.WarnIfLongName(self.docCopy.GetFirstObject()) # Add empty polygon objects to childless null objects so that they are exported by the # COLLADA exporter if exportnulls is True: self.FixUpEmptyNulls(self.docCopy.GetFirstObject()) # Remove teture tags if removetextags is True: self.RemoveTextureTags(self.docCopy.GetFirstObject()) # Container for plugin object data op = {} # Configure COLLADA export plugin and export the modified scene assert colladaPlugin.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op) assert 'imexporter' in op # Get the exporter settings from the plugin object colladaExport = op['imexporter'] assert colladaExport is not None # Define the settings colladaExport[c4d.COLLADA_EXPORT_ANIMATION] = exportanim colladaExport[c4d.COLLADA_EXPORT_TRIANGLES] = True # Export without the dialog if c4d.documents.SaveDocument( self.docCopy, filepath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, colladaPluginId): # Parse the saved COLLADA data as XML colladaData = ET.parse(filepath) parentMap = dict( (c, p) for p in colladaData.getiterator() for c in p) # Construct geometry id map geomIdMap = dict() for node in colladaData.getiterator(): if node.tag == ns + 'geometry': geomIdMap[node.get('id')] = node # Get first effect and material nodes to prevent them from being deleted firstEffectNode = colladaData.find('.//' + ns + 'effect') firstMaterialNode = colladaData.find('.//' + ns + 'material') firstMaterialId = firstMaterialNode.get('id') # Iterate thru the hierarchy and deal with things for node in colladaData.getiterator(): # Remove Polygon objects and associated geometry data if node.tag == ns + 'node': if node.get('name') == polygonName: geomId = node.find(ns + 'instance_geometry').get('url')[1:] geomNode = geomIdMap[geomId] parentMap[geomNode].remove(geomNode) parentMap[node].remove(node) # Remove library_images tags if node.tag == ns + 'library_images': parentMap[node].remove(node) # Remove effect tags except for the first one if node.tag == ns + 'effect': if node != firstEffectNode: parentMap[node].remove(node) # Remove material tags except for the first one if node.tag == ns + 'material': if node != firstMaterialNode: parentMap[node].remove(node) # Set material target to the first material id if node.tag == ns + 'instance_material': node.set('target', '#' + firstMaterialId) # Remove the namespace from all tags xmlString = ET.tostring(colladaData.getroot()) xmlString = xmlString.replace(nsPrefix + ':', '') xmlString = xmlString.replace(':' + nsPrefix, '') # Write the modified COLLADA file colladaFile = open(filepath, 'w') colladaFile.write(xmlString) colladaFile.close() # Cleanup if len(mergeObjects) is not 0: for op in mergeObjects: for x in range(0, 3): self.doc.DoUndo(False) self.doc.DoUndo(False) self.doc.DoUndo(False) return 'Export complete\n\nRemoved %d xrefs\nFixed %d empty null objects' % ( self.xrefCounter, self.polyCounter) else: return 'The document failed to save.'
def main(): # --------------------------------------------------------------------------------------------------- # Setup and export AI-sequence with Sketch and Toon fn = c4d.storage.LoadDialog( c4d.FILESELECTTYPE_ANYTHING, "Select Save Path", flags=c4d.FILESELECT_DIRECTORY) # Select path to save if not fn: return # If cancelled stop the script doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document renderData = doc.GetActiveRenderData() # Get document render data currVideoPost = renderData.GetFirstVideoPost() # Get first render effect sntFound = False # Initialize variable for storing info is 'Sketch and Toon' effect enabled already while currVideoPost is not None: # Loop through render effects if currVideoPost.GetType( ) == 1011015: # If 'Sketch and Toon' effect found sntFound = True # Set variable to true currVideoPost = currVideoPost.GetNext( ) # Get next render effect on list if sntFound == False: # If 'Sketch and Toon' effect is not enabled already sketchEffect = c4d.documents.BaseVideoPost( 1011015) # Initialize 'Sketch and Toon' effect renderData.InsertVideoPostLast( sketchEffect) # Add 'Sketch and Toon' effect to render settings sketchMat = c4d.BaseMaterial(1011014) # Initialize 'Sketch Material' doc.InsertMaterial(sketchMat) # Insert material to document sketchTags = [] # Initialize list for 'Sketch Style' tags # --------------------------------------------------------------------------------------------------- # Export plug-in settings plug = plugins.FindPlugin(1012074, c4d.PLUGINTYPE_SCENESAVER) if plug is None: return data = {} if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, data): if "imexporter" not in data: return aiExport = data["imexporter"] if aiExport is None: return # Change Illustrator export settings aiExport[c4d.TUAIEXPORT_OUTPUTSIZE] = 0 # Output: Render aiExport[c4d.TUAIEXPORT_ZSORT] = 0 aiExport[c4d.TUAIEXPORT_SCALE] = 1 # Scale: 100% aiExport[c4d.TUAIEXPORT_EXPORTLINES] = 1 # Export lines aiExport[c4d.TUAIEXPORT_LINEOPACITY] = 0 # Disable line opacity aiExport[c4d.TUAIEXPORT_LINETHICKNESS] = 0 # Disable line thickness aiExport[c4d.TUAIEXPORT_LINEPATTERNS] = 0 # Disable line patterns aiExport[c4d.TUAIEXPORT_LINECONNECTIONS] = 1 # Enable line connections aiExport[c4d.TUAIEXPORT_EXPORTSURFACE] = 0 # Disable surface export aiExport[c4d.TUAIEXPORT_ANIMATION] = 1 # Export animation aiExport[c4d.TUAIEXPORT_ANIMTYPE] = 0 # Output As: Files aiExport[c4d.TUAIEXPORT_FRAMES] = 2 # Frames: Manual aiExport[c4d.TUAIEXPORT_FRAME_START] = doc.GetLoopMinTime( ) # Animation first frame aiExport[c4d.TUAIEXPORT_FRAME_END] = doc.GetLoopMaxTime( ) # Animation last frame aiExport[c4d.TUAIEXPORT_FRAME_RATE] = doc.GetFps() # Frame rate # --------------------------------------------------------------------------------------------------- # Handle selected objects selection = doc.GetActiveObjects( c4d.GETACTIVEOBJECTFLAGS_0) # Get selected objects for i in xrange(0, len(selection)): # Loop through selected objects #sketchTags.append(c4d.BaseTag(1011012)) # Insert 'Sketch Style' tag to sketchTags list sketchTag = c4d.BaseTag(1011012) # Initialize a sketch tag sketchTag[ c4d. OUTLINEMAT_LINE_DEFAULT_MAT_V] = sketchMat # Put sketch material to sketch tag sketchTag[c4d.OUTLINEMAT_LINE_SPLINES] = 1 # Enable splines sketchTag[c4d.OUTLINEMAT_LINE_FOLD] = 0 # Disable fold sketchTag[c4d.OUTLINEMAT_LINE_CREASE] = 0 # Disable crease sketchTag[c4d.OUTLINEMAT_LINE_BORDER] = 0 # Disable border selection[i].InsertTag( sketchTag) # Insert sketch tag to selected object # --------------------------------------------------------------------------------------------------- folderPath = os.path.splitext(fn)[0] # Folder path objectName = selection[i].GetName() # Get object name os.mkdir(folderPath + "\\" + objectName) # Create new folders fullFilePath = folderPath + "\\" + objectName + "\\" + objectName + ".ai" # Full file path c4d.documents.SaveDocument(doc, fullFilePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1012074) # Export AI-file sketchTag.Remove() # Delete sketch tag # --------------------------------------------------------------------------------------------------- # Remove unnecessary stuff #for st in sketchTags: # Loop through sketchTags #st.Remove() # Remove 'Sketch Style' tag sketchMat.Remove() # Remove 'Sketch Material' if sntFound == False: # If there was not 'Sketch and Toon' render effect already sketchEffect.Remove() # Remove 'Sketch and Toon' render effect # --------------------------------------------------------------------------------------------------- c4d.StatusClear() # Clear status bar c4d.StatusSetText("Export complete!") # Set status text c4d.EventAdd() # Refresh Cinema 4D
def tool(): return plugins.FindPlugin(doc.GetAction(), c4d.PLUGINTYPE_TOOL)