def main():
    # Gets selected objects
    objList = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0)
    if not objList:
        raise RuntimeError("Failed to retrieve selected objects")

    # Opens a LoadDialog to define the path of the VDB file to save
    filePath = c4d.storage.SaveDialog()

    # Leaves if nothing was selected
    if not filePath:
        return

    # Add the vdb extension if needed
    if not filePath.endswith(".vdb"):
        filePath += ".vdb"

    # Creates a maxon.BaseArray with all our obj, we want to convert
    volumesArray = maxon.BaseArray(maxon.frameworks.volume.VolumeRef)
    volumesArray.Resize(len(objList))
    for i, obj in enumerate(objList):
        volumesArray[i] = polygonToVolume(obj)

    # Generates the final file path to save the vdb
    path = maxon.Url(filePath)
    scale = 1.0
    metaData = maxon.DataDictionary()
    try:
        maxon.frameworks.volume.VolumeToolsInterface.SaveVDBFile(
            path, scale, volumesArray, metaData)
    except IOError:
        raise IOError("Failed to Save the VDB file.")

    print("File saved to ", path)
예제 #2
0
def main():
    # Retrieves render data and its container
    renderData = doc.GetActiveRenderData()
    bc = renderData.GetDataInstance()

    # Gets image filters options
    saveOptions = bc.GetContainerInstance(c4d.RDATA_SAVEOPTIONS)

    # Sets OpenEXR output format
    bc[c4d.RDATA_FORMAT] = c4d.FILTER_EXR

    # Defines OpenEXR settings
    compressionmethodID = maxon.Id('net.maxon.mediasession.openexr.export.compressionmethod')
    halffloatID = maxon.Id('net.maxon.mediasession.openexr.export.halffloat')
    layernumberingID = maxon.Id('net.maxon.mediasession.openexr.export.layernumbering')

    # Configures OpenEXR format options with a maxon.DataDictionary
    exportSettings = maxon.DataDictionary()
    exportSettings.Set(compressionmethodID, maxon.Id("rle"))
    exportSettings.Set(halffloatID, True)
    exportSettings.Set(layernumberingID, True)

    # Stores settings in render data container
    c4d.bitmaps.SetImageSettingsDictionary(exportSettings, saveOptions, c4d.FILTER_EXR)

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()

    # Retrieves OpenEXR images settings
    settings = c4d.bitmaps.GetImageSettingsDictionary(saveOptions, c4d.FILTER_EXR)

    # Reads and prints OpenEXR format options
    print("openexr.export.compressionmethod: " + str(settings.Get(compressionmethodID)))
    print("openexr.export.halffloat: " + str(settings.Get(halffloatID)))
    print("openexr.export.layernumbering: " + str(settings.Get(layernumberingID)))
def main():
    # Creates a python dictionary object
    pyDict = {'foo': 1, 'something': 20.05, 'test': 'A string'}

    # Creates a maxon data dictionary object
    mDict = maxon.DataDictionary()

    # Sets the value of the tuple
    for key, value in pyDict.iteritems():
        mDict.Set(key, value)

    print mDict
def main():
    # Retrieves a path to load the imported file
    selectedFile = c4d.storage.LoadDialog(title="Load File for Volume Import",
                                          type=c4d.FILESELECTTYPE_ANYTHING,
                                          force_suffix="vdb")
    if not selectedFile:
        return

    # Define the path of the file.vdb located in the same folder of this script
    path = maxon.Url(selectedFile)

    # Try to load the VDB File, and apply a Scale of 1 to this VDB
    scale = 1.0
    gridNames = maxon.BaseArray(maxon.String)
    gridIndices = None
    metaData = maxon.DataDictionary()
    volumeArr = None
    try:
        volumeArr = maxon.frameworks.volume.VolumeToolsInterface.LoadVDBFile(
            path, scale, gridNames, gridIndices, metaData)
    except Exception as e:
        print("LoadVDBFile error {}, {}".format(e, e.args))

    if volumeArr is None:
        raise RuntimeError("Unknown error.")

    if len(volumeArr) == 0:
        raise RuntimeError("Selected Vdb store 0 volume.")

    # Retrieves the first volume
    volRef = volumeArr[0]

    # Creates a Volume Object to store the previous volume calculated
    volumeObj = c4d.BaseObject(c4d.Ovolume)
    if volumeObj is None:
        raise MemoryError("Failed to create a volume object.")

    doc.InsertObject(volumeObj)
    volumeObj.SetVolume(volRef)

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
예제 #5
0
def main():
    # Gets selected objects
    objList = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0)
    if not objList:
        raise RuntimeError("Failed to retrieve selected objects")

    # Creates a maxon.BaseArray with all our obj, we want to convert
    volumesArray = maxon.BaseArray(maxon.frameworks.volume.VolumeRef)
    volumesArray.Resize(len(objList))
    for i, obj in enumerate(objList):
        volumesArray[i] = polygonToVolume(obj)

    try:
        # Generates the final file path to save the vdb
        path = maxon.Url(os.path.join(os.path.dirname(__file__), "file.vdb"))
        scale = 1.0
        metaData = maxon.DataDictionary()
        maxon.frameworks.volume.VolumeToolsInterface.SaveVDBFile(
            path, scale, volumesArray, metaData)
        print "File saved to ", path
    except Exception as e:
        print "SaveVDBFile error {}, {}".format(e.message, e.args)