Esempio n. 1
0
def main():

    # Selects the c4d file to load
    filename = c4d.storage.LoadDialog(type=c4d.FILESELECTTYPE_SCENES, title="Choose File.", flags=c4d.FILESELECT_LOAD, force_suffix="c4d")
    if filename is None:
        return

    # Checks selected file is a c4d scene file
    name, suffix = os.path.splitext(filename)
    if suffix != ".c4d":
        return

    # Loads the document
    loadedDoc = c4d.documents.LoadDocument(filename, c4d.SCENEFILTER_0)
    if loadedDoc is None:
        return

    # Creates a new ColorSwatchData
    swatchData = cc.ColorSwatchData()
    if swatchData is None:
        return

    # Loads swatches from document
    swatchData.Load(loadedDoc)

    # Stores swatches into the active document
    swatchData.Save(doc)

    c4d.EventAdd()
def main():
    # Creates a new ColorSwatchData
    swatchData = cc.ColorSwatchData()
    if swatchData is None:
        return

    # Loads color groups from the active document
    if not swatchData.Load(doc):
        return

    # Builds preset URL
    url = cc.GetColorSwatchPresetDirectory()
    url = url + "/newColorPreset"

    # Saves color swatches preset
    if swatchData.SavePresetByURL(url, "User", "This is my preset"):
        print "Color swatch preset saved successfully"
    else:
        print "Color swatch preset could not be saved!"
    
    c4d.EventAdd()
Esempio n. 3
0
def main():
    # Creates a new ColorSwatchData
    swatchData = cc.ColorSwatchData(doc)
    if swatchData is None:
        return

    # Adds a group to the newly created ColorSwatchData
    group = swatchData.AddGroup("New Group", False)
    if group is None:
        return

    # Adds red, green and blue colors to the ColorSwatchGroup
    group.AddColor(c4d.Vector(1.0, 0.0, 0.0), True)
    group.AddColor(c4d.Vector(0.0, 1.0, 0.0), False)
    group.AddColor(c4d.Vector(0.0, 0.0, 1.0), False)

    # Assigns the new group
    swatchData.SetGroupAtIndex(swatchData.GetGroupCount() - 1, group)

    # Saves the color groups into the active document
    swatchData.Save(doc)

    c4d.EventAdd()
def main():

    # Creates a swatch data
    swatchData = colorchooser.ColorSwatchData()
    if swatchData is None:
        return

    # Loads the swatches data from the active document
    swatchData.Load(doc)

    # Makes sure the document contains at least a swatch group
    if swatchData.GetGroupCount(c4d.SWATCH_CATEGORY_DOCUMENT) == 0:
        return

    # Retrieves the first swatch group
    group = swatchData.GetGroupAtIndex(0, c4d.SWATCH_CATEGORY_DOCUMENT)
    if group is not None:
        groupName = group.GetName()
        colorCount = group.GetColorCount()
        for colorIndex in xrange(colorCount):
            # Gets the current color
            color = group.GetColor(colorIndex)[0]

            # Creates a material for the current color
            mat = c4d.BaseMaterial(c4d.Mmaterial)
            # Sets the name with the group name and color index
            mat.SetName(groupName + str(colorIndex))

            # Converts maxon.ColorA to c4d.Vector to set the material color
            mat[c4d.MATERIAL_COLOR_COLOR] = c4d.Vector(color.r, color.g,
                                                       color.b)

            # Inserts the material into the active document
            doc.InsertMaterial(mat)

    # Updates Cinema 4D
    c4d.EventAdd()
def main():

    # Creates a swatch data
    swatchData = colorchooser.ColorSwatchData()
    if swatchData is None:
        return

    # Loads the swatch data from the active document
    swatchData.Load(doc)

    # Creates a swatch group
    group = swatchData.AddGroup(c4d.SWATCH_CATEGORY_DOCUMENT, "Rainbow")
    if group is not None:
        for i in xrange(20):

            # Creates rainbow colors and stores them in the previously created group
            hsv = c4d.Vector(float(i) * 0.05, 1.0, 1.0)
            rgb = c4d.utils.HSVToRGB(hsv)

            # Creates a maxon.ColorA for the current color
            col4 = maxon.ColorA()
            col4.r = rgb.x
            col4.g = rgb.y
            col4.b = rgb.z
            col4.a = 1.0
            group.AddColor(col4)

        # Inserts the swatch group
        index = swatchData.GetGroupCount(c4d.SWATCH_CATEGORY_DOCUMENT) - 1
        swatchData.SetGroupAtIndex(index, group)

        # Saves the group into the active document
        swatchData.Save(doc)

    # Updates Cinema 4D
    c4d.EventAdd()