Beispiel #1
0
def main():
    # 获取文件路径与文件名
    doc = documents.GetActiveDocument()
    name = doc.GetDocumentName()
    originPath = doc.GetDocumentPath()
    originFilePath = os.path.join(originPath, name)
    originFilePath = os.path.normpath(originFilePath)

    if doc.SearchObject("FileSaver"):
        fileSaver = doc.SearchObject("FileSaver")
    else:
        print "You need to run 'createSaveOutUserData.py' first"
        return

    isOutputFbx = fileSaver[c4d.ID_USERDATA, 1]
    isSavingOriginFile = fileSaver[c4d.ID_USERDATA, 2]
    filepath = fileSaver[c4d.ID_USERDATA, 3]

    if isOutputFbx:
        if len(filepath) == 0:
            print "You need to specify the file path"
            return

    filepath = os.path.normpath(filepath)
    filepath = "/".join(filepath.split("\\")[:-1])
    # 将文件后缀改为.fbx
    if name[-3:] != "fbx":
        if len(name.split(".")) == 1:
            name = name + ".fbx"
        else:
            index = -1
            while name[index] != '.':
                index -= 1
            name = name[:(index + 1)] + "fbx"
            print "convert filetype to .fbx"

    filepath = os.path.join(filepath, name)
    filepath = os.path.normpath(filepath)

    # 导出模型到原文件路径
    if documents.SaveDocument(doc, filepath,
                              c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST,
                              1026370):
        print "export document to: " + filepath
    else:
        print "export failed"

    if isSavingOriginFile:
        if documents.SaveDocument(doc, originFilePath,
                                  c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST,
                                  c4d.FORMAT_C4DEXPORT):
            print "save origin file to: " + originFilePath
        else:
            print "save origin file failed"

    c4d.EventAdd()
Beispiel #2
0
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!"
Beispiel #3
0
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)
Beispiel #4
0
 def Main(self):
     # Export document to FBX
     container = c4d.plugins.GetWorldPluginData(FBX_EXPORTER_ID)
     for id, value in container:
         if id == c4d.FBXEXPORT_ASCII:  container[id] = 0
         elif id == c4d.FBXEXPORT_BAKE_ALL_FRAMES: container[id] = 0
         elif id == c4d.FBXEXPORT_SAVE_NORMALS: container[id] = 1
         elif id == c4d.FBXEXPORT_GRP_ANIMATION : container[id] = 1
         elif id == c4d.FBXEXPORT_TEXTURES: container[id] = 1
         elif id == c4d.FBXEXPORT_GRP_TEXTURES: container[id] = 1
         elif id == c4d.FBXEXPORT_EMBED_TEXTURES: container[id] = 1
         elif id == c4d.FBXEXPORT_GRP_ADDITIONAL: container[id] = 1
     c4d.plugins.SetWorldPluginData(FBX_EXPORTER_ID, container)        
     self.status = documents.SaveDocument(self.doc, self.exportPath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, FBX_EXPORTER_ID)
Beispiel #5
0
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!"
Beispiel #6
0
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)
Beispiel #7
0
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():
    # Creates a document
    doc = documents.BaseDocument()

    # Creates and inserts a cube object
    cube = c4d.BaseObject(c4d.Ocube)
    doc.InsertObject(cube)

    # Generates the document file name
    name = os.path.join(os.path.dirname(__file__), 'cube.c4d')

    # Saves the document
    saved = documents.SaveDocument(doc, name, c4d.SAVEDOCUMENTFLAGS_0,
                                   c4d.FORMAT_C4DEXPORT)
    if saved:
        print('Succesfully saved document to \'{}\''.format(name))
Beispiel #9
0
def main():
    document = c4d.documents.GetActiveDocument()
    objs = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
    if objs == None:
        return
    if len(objs) > 1:
        return

    # Get a fresh, temporary document with only the selected objects
    docTemp = c4d.documents.IsolateObjects(doc, objs)
    if docTemp == None:
        return

    obj = os.path.dirname(os.path.realpath(__file__)) + os.sep + "1.obj"

    if documents.SaveDocument(docTemp, obj, c4d.SAVEDOCUMENTFLAGS_0,
                              c4d.FORMAT_OBJEXPORT):
        objToVertData(obj)
Beispiel #10
0
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)
Beispiel #11
0
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!"
Beispiel #12
0
def main():   
    doc = documents.GetActiveDocument( );
    aobj = doc.GetActiveObject( );
    axis = aobj.GetAbsPos( );
    center = aobj.GetMp( );    

    c4d.CallCommand( 12112 );
    c4d.CallCommand( 14048 );
    c4d.CallCommand( 12479 );

    print ( "OBJECT: " + aobj.GetName( ) );
    print ( "CENTER: " + str( center ) );
    print ( "AXIS: " + str( axis ) );

    fn = storage.SaveDialog( c4d.FILESELECTTYPE_ANYTHING, "OBJ Exporter", "", "./"  );
    fn = ( fn + ".obj" );
    
    documents.SaveDocument( doc, fn, c4d.SAVEDOCUMENTFLAGS_0, c4d.FORMAT_OBJEXPORT );
    
    c4d.EventAdd( );
    c4d.CallCommand( 12147 );
    
    return True
Beispiel #13
0
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)
Beispiel #14
0
def main():

    # Get file data
    document = documents.GetActiveDocument()
    path = document.GetDocumentPath()
    name = document.GetDocumentName()
    settings = c4d.BaseContainer()

    obj = document.SearchObject("Connect")
    userDataObject = document.SearchObject("Mordifier")
    objList = document.GetObjects()

    outPutFilename = userDataObject[c4d.ID_USERDATA, 15]
    outPutPath = userDataObject[c4d.ID_USERDATA, 16]

    # C-Model
    return_value = utils.SendModelingCommand(
        command=c4d.MCOMMAND_CURRENTSTATETOOBJECT,
        list=[obj],
        mode=c4d.MODELINGCOMMANDMODE_ALL,
        bc=settings,
        doc=document)

    if return_value:
        document.InsertObject(
            return_value[0])  #return_value is a list in this case
        c4d.EventAdd()

    # del others
    for i in objList:
        i.Remove()

    # change name of the model
    newModel = document.GetFirstObject()
    newModel.SetName(outPutFilename)

    # delete all material
    mat = document.GetMaterials()
    for i in mat:
        i.Remove()

    # save file
    # path = "C:\\newStart\\Assets\\Models\\CutOutModels\\"
    name = outPutFilename + "_forUnity.c4d"
    path = os.path.join(outPutPath, name)
    # 导出模型到原文件路径
    if documents.SaveDocument(doc, path,
                              c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST,
                              c4d.FORMAT_C4DEXPORT):
        print "export document to: " + path
    else:
        print "export failed"

    # open new model


#     try:
#          newDoc = documents.LoadDocument(path, c4d.
# SCENEFILTER_0)
#     except IOError:
#         print "Can't open the new model"

    c4d.EventAdd()
 def Main(self):
     destfile = self.dest_file + '.fbx'
     self.status = documents.SaveDocument(
         self.doc, destfile, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST,
         self.EXPORTER_ID)