Cinema 4D: Bereichsrendern für die Animationsbildfolgen. Automatisches Beschneiden der Bilder Script!

  • #1, by JackMcRipFriday, 09. August 2013, 13:09 11 years ago
    Ich hatte folgendes Problem mit Cinema 4D und den von Visionaire geforderten Animationsgrafiken:

    Visionaire erwartet Animierte Bereiche einer Hintergrundgrafik als Bildfolge.
    Mit der Funktion Bereichsrendern von Cinema 4D wird zwar nur ein Ausschnitt gerendert, jedoch bleibt das Bild in der vollen (HD-) Auflösung mit schwarzen, bzw. durchsichtigen Rändern.
    Die Bildfolge wollte ich nun automatisch beschneiden und behalf mir mit Phyton.

    Das Script liest aus den Rendersettings die Bereichseinstellungen und den Namen der Files.
    Es liest die Bilddatei ein und kopiert den angegebenen Ausschnitt in eine neue Bilddatei die dem bereich entsprechend groß ist und speichert diese unter dem zusatz "_crop_" ab.

    Das Script funktioniert in meinem Einsatz einwandfrei, ich weise jedoch darauf hin dass Programmfehler die Bilder gefährden könnten. Daher lieber erstmal mit Sicherheitskopien arbeiten.

    Falls es hier weitere C4D User gibt könnte Ihnen das viel Arbeit erleichtern ;-)

    Viel Spaß damit:
    files.total3d.de/croprenderedimages.zip




    [CODE] 
    import c4d, os 
    from c4d import gui 
    from c4d import bitmaps, storage 
    #Welcome to the world of Python 
    
    def main(): 
    rd = doc.GetActiveRenderData() # Get Renderdata 
    dateiname = rd[c4d.RDATA_PATH] # The Renderfilename 
    dateiendung = os.path.splitext(dateiname) # Split The Name Into Path and Extension 
    
    if dateiendung[0] == "" : # Abbort at No Filepath in the Rendersettings 
    gui.MessageDialog("filename not found in rendersettings - Abbort!") 
    end() 
    
    # Get and Calculate Renderdata Values 
    renderfps = rd[c4d.RDATA_FRAMERATE] 
    vonBild = rd[c4d.RDATA_FRAMEFROM] 
    zuBild = rd[c4d.RDATA_FRAMETO] 
    
    RenderBreite = rd[c4d.RDATA_XRES_VIRTUAL] 
    RenderHoehe = rd[c4d.RDATA_YRES_VIRTUAL] 
    RangeLinks = rd[c4d.RDATA_RENDERREGION_LEFT] 
    RangeRechts = rd[c4d.RDATA_RENDERREGION_RIGHT] 
    RangeTop = rd[c4d.RDATA_RENDERREGION_TOP] 
    RangeUnten = rd[c4d.RDATA_RENDERREGION_BOTTOM] 
    bildbreite = RenderBreite - RangeLinks - RangeRechts 
    bildhoehe = RenderHoehe - RangeTop - RangeUnten 
    bildalpha = rd[c4d.RDATA_ALPHACHANNEL] 
    
    # Check File Extensiom 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1100 : bildext = c4d.FILTER_TIF; dend = ".tif" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1110 : bildext = c4d.FILTER_TIF; dend = ".tif" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1111 : bildext = c4d.FILTER_PSB; dend = ".psb" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1101 : bildext = c4d.FILTER_TGA; dend = ".tga" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1102 : bildext = c4d.FILTER_BMP; dend = ".bmp" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1103 : bildext = c4d.FILTER_IFF; dend = ".iff" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1104 : bildext = c4d.FILTER_JPG; dend = ".jpg" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1105 : bildext = c4d.FILTER_PICT; dend = ".pct" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1106 : bildext = c4d.FILTER_PSD; dend = ".psd" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1107 : bildext = c4d.FILTER_RLA; dend = ".rla" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1108 : bildext = c4d.FILTER_RPF; dend = ".rpf" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1109 : bildext = c4d.FILTER_B3D; dend = ".b3d" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1023671 : bildext = c4d.FILTER_PNG; dend = ".png" 
    if dateiendung[1] == "" and rd[c4d.RDATA_FORMAT] == 1001379 : bildext = c4d.FILTER_HDR; dend = ".hdr" 
    
    # Check Name Constellation 
    if rd[c4d.RDATA_NAMEFORMAT] == 0 : zeros = 4; ForValue = ""; 
    if rd[c4d.RDATA_NAMEFORMAT] == 1 : zeros = 4; ForValue = ""; bildext = ""; dend == "" 
    if rd[c4d.RDATA_NAMEFORMAT] == 2 : zeros = 4; ForValue = "."; bildext = ""; dend == "" 
    if rd[c4d.RDATA_NAMEFORMAT] == 3 : zeros = 3; ForValue = ""; 
    if rd[c4d.RDATA_NAMEFORMAT] == 4 : zeros = 3; ForValue = ""; bildext = ""; dend == "" 
    if rd[c4d.RDATA_NAMEFORMAT] == 5 : zeros = 3; ForValue = "."; bildext = ""; dend == "" 
    if rd[c4d.RDATA_NAMEFORMAT] == 6 : zeros = 4; ForValue = "."; 
    
    # Count The Framerange 
    bildmenge = zuBild.GetFrame(renderfps) - vonBild.GetFrame(renderfps) 
    stepframe = vonBild.GetFrame(renderfps) # stepframe is first Frame from Range 
    count = 0 
    while (stepframe <= zuBild.GetFrame(renderfps)): # loop so long as stepframe is not cout to End Frame 
    
    #--------------------------- # Add Zero In Front Of Frame Number 
    if stepframe >= 99 and zeros ==3 : addzero = "" 
    if stepframe <= 99 and zeros ==3 : addzero = "0" 
    if stepframe <= 9 and zeros ==3 : addzero = "00" 
    
    if stepframe >= 1000 and zeros ==4 : addzero = "" 
    if stepframe <= 999 and zeros ==4 : addzero = "0" 
    if stepframe <= 99 and zeros ==4 : addzero = "00" 
    if stepframe <= 9 and zeros ==4 : addzero = "000" 
    
    aktBild = addzero+str(stepframe) # Add Zero In Front Of Frame Number 
    #--------------------------- 
    
    neuerdateiname = dateiendung[0]+ForValue+aktBild+dend # filename of the to loading image 
    savedateiname = dateiendung[0]+"_crop_"+ForValue+aktBild+dend # filename of the save image 
    
    bildneu = bitmaps.BaseBitmap() # Init Bitmap Var (for original image) 
    orig = bitmaps.BaseBitmap() # Init Bitmap Var (for 'copy to' image 
    if orig.InitWith(neuerdateiname)[0] != c4d.IMAGERESULT_OK: # Load Bitmap and check correct loading 
    gui.MessageDialog("Cannot load image \"" + neuerdateiname+"\"\n abort") 
    return 
    
    bildneu = orig.GetClonePart(RangeLinks, RangeTop, bildbreite, bildhoehe) # Clone Image Range from Original Image 
    # Save The Image With OR Without Alpha Chanal 
    if bildalpha == True : bildneu.Save(savedateiname, rd[c4d.RDATA_FORMAT], c4d.BaseContainer(), c4d.SAVEBIT_ALPHA) 
    if bildalpha == False : bildneu.Save(savedateiname, rd[c4d.RDATA_FORMAT], c4d.BaseContainer()) 
    
    print ("Picture "+aktBild+" cropped (Frame "+str(count)+" from "+str(bildmenge)+")") # Print Infos Into Console 
    
    stepframe = stepframe + 1 # Count While Loop stepframe 
    count = count + 1 # Count For Message How Much File Croped 
    
    gui.MessageDialog(" croped "+str(count)+" frames! \n FINISHED\n\n Alpha = "+str(bildalpha)) 
    c4d.EventAdd() # Send global event 
    
    if __name__=='__main__': 
    main() 
    [/CODE]

    Forum Fan

    115 Posts