python C4d - Python导出器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python C4d - Python导出器相关的知识,希望对你有一定的参考价值。

# C4D to OBJ sequence exporter
# http://richh.co/c4d-native-obj-sequence-export-no-plugins/
#https://www.behance.net/gallery/18442389/C4D-Mini-Script-05-Obj-Sequence-Exporter

import c4d
import os
import subprocess
from c4d import gui
#Welcome to the world of Python

def main():
    
    # get active document
    doc = c4d.documents.GetActiveDocument()

    # retrieve an instance of render data
    renderSettings = doc.GetActiveRenderData()

    # retrieve fps
    docFps = 30
    
    # Get Animation Length
    fromTime = 0
    toTime = 150
    animLength = toTime - fromTime + 1
    
    # prompt user for directory
    filePath = c4d.storage.SaveDialog()
    filePath, objName = os.path.split(filePath)
    objName = objName + "_"
    filePath = filePath + "\\"
    # Check for confirmation
    questionDialogText = "Obj Sequence will be saved as:\n\n"\
        "" + filePath + objName + "####.obj\n\n"\
        "From frame " + str(fromTime) + " to " + str(toTime) + " for " + str(animLength) + " frames.\n"
    proceedBool = c4d.gui.QuestionDialog(questionDialogText)
    
    if proceedBool == True:
        
        # Loop through animation and export frames
        for x in range(0,animLength):
            
            # change frame, redraw view
            moveTime = c4d.BaseTime(fromTime,docFps) + c4d.BaseTime(x,docFps)
            doc.SetTime(moveTime)
            c4d.EventAdd(c4d.EVENT_FORCEREDRAW)
            c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW)
            
            # progress bar
            c4d.StatusSetText("Exporting " + str(x) + " of " + str(animLength))
            c4d.StatusSetBar(100.0*x/animLength)
            
            # add buffer 0001
            bufferedNumber = str(doc.GetTime().GetFrame(docFps))
            if len(bufferedNumber)<4:
                for x in range(len(bufferedNumber),4):
                    bufferedNumber = "0" + bufferedNumber
            
            #save file   
            fileName = filePath+objName+bufferedNumber+".obj"
            print fileName
            c4d.documents.SaveDocument(doc,fileName,c4d.SAVEDOCUMENTFLAGS_0,1030178)
        
    else: print "User directed cancel"
        
    c4d.StatusClear()
    
    # ask to open containing folder
    viewFilesBool = c4d.gui.QuestionDialog("Do you want to open containing folder?")
    if viewFilesBool == True:
        ('explorer "C:\path\of\folder"')
        subprocess.Popen('explorer ' + '"' + filePath + '"' )
    else:
        return None
    
    
if __name__=='__main__':
    main()

以上是关于python C4d - Python导出器的主要内容,如果未能解决你的问题,请参考以下文章

python C4D - Pyhton

python C4D - Pyhton

通过Python编程语言实现C4D(R13)中的简单动画

使用 Python 脚本从节点导出器指标获取 CPU、内存、磁盘数据

在C4D中用python实现一个根据索引来控制克隆的简易效果器

用于 json 值的 Prometheus python 导出器