c4d.Gradient

class c4d.Gradient

Gradient data type (CUSTOMDATATYPE_GRADIENT) for the GradientCustomGui GUI.

This type is called by value.

Methods Signatures

Gradient.__init__(self, v)

type v

c4d.Gradient

Gradient.__hash__(self)

Returns a hash of the whole gradient state, including the needles, colors and interpolation type.

Gradient.InvertKnots(self)

Inverts the knots.

Gradient.DoubleKnots(self)

Doubles the knots.

Gradient.DistributeKnots(self)

Distributes the knots evenly.

Gradient.FlushKnots(self)

Flushes all knots.

Gradient.PrepareRenderData(self, irs)

Initializes the gradient data for render.

Gradient.PrepareRenderDataWithAlpha(self, irs)

Initializes the gradient data for render.

Gradient.InsertKnot(self, col, brightness, ...)

Insert a knot. Not passed arguments will be set with default values.

Gradient.RemoveKnot(self, index)

Delete a knot.

Gradient.GetKnot(self, index)

Returns the information about a knot.

Gradient.SetKnot(self, index, col, ...)

Set the values of a knot.

Gradient.GetData(self, id)

Gets a data item from the gradient container.

Gradient.SetData(self, id, data)

Sets a data item from the gradient container.

Gradient.GetKnotCount(self)

Gets the knot count.

Gradient.CopyFrom(self, src)

Copies all gradient data from the source gradient.

Gradient.GetChecksum(self)

Gets a checksum of the whole gradient state, including the knots, colors and interpolation type.

Gradient.GetGradient(self)

Gets the internal gradient.

Gradient.SetGradient(self, gradient)

Sets the internal gradient.

Gradient.GetAlphaGradient(self)

Gets a copy of the alpha gradient.

Gradient.SetAlphaGradient(self, alphaGradient)

Sets the alpha gradient.

Gradient.AllocAlphaGradient(self)

Create a alpha of the gradient. Similar to Gradient.GetAlphaGradient().

Gradient.ConvertToAlphaGradient(self[, bc, id])

Converts this gradient to an alpha gradient.

Inheritance

Parent Class:

Methods Documentation

Gradient.__init__(self, v)
Parameters

v (c4d.Gradient) – Copy constructor.

Gradient.__hash__(self)

Returns a hash of the whole gradient state, including the needles, colors and interpolation type.

print(hash(obj) #hash calls obj.__hash__())
Return type

int

Returns

Hash value

Gradient.InvertKnots(self)

Inverts the knots.

Return type

bool

Returns

True if successful, otherwise False.

Gradient.DoubleKnots(self)

Doubles the knots.

Return type

bool

Returns

True if successful, otherwise False.

Gradient.DistributeKnots(self)

Distributes the knots evenly.

New in version R20.

Return type

bool

Returns

True if successful, otherwise False.

Gradient.FlushKnots(self)

Flushes all knots.

Gradient.PrepareRenderData(self, irs)

Initializes the gradient data for render.

New in version 2024.0.0.

Note

Call before CalcGradientPixel().

Parameters

irs (c4d.modules.render.InitRenderStruct) – Information about the upcoming rendering.

Return type

maxon.GradientRenderData

Returns

RenderData on success.

Gradient.PrepareRenderDataWithAlpha(self, irs)

Initializes the gradient data for render.

New in version 2024.0.0.

Note

Call before CalcGradientPixel().

Parameters

irs (c4d.modules.render.InitRenderStruct) – Information about the upcoming rendering.

Return type

tuple[maxon.GradientRenderData, maxon.GradientRenderData]

Returns

RenderData for the colors and the Alpha on success.

Gradient.InsertKnot(self, col, brightness, pos, bias, index)

Insert a knot. Not passed arguments will be set with default values.

Parameters
  • col (c4d.Vector) – The color.

  • brightness (float) – The brightness.

  • pos (float) – The position.

  • bias (float) – The bias.

  • index (int) – The index.

Return type

int

Returns

The new knot

Note

The new knot index is GetKnotCount() - 1

Gradient.RemoveKnot(self, index)

Delete a knot.

Parameters

index (int) –

index knot.

Note

0 <= index < GetKnotCount()

Gradient.GetKnot(self, index)

Returns the information about a knot.

Parameters

index (int) –

The index.

Note

The new knot index has to be 0 <= index < Gradient.GetKnotCount()

Check out this small example.

col, brightness, pos, bias, index = gradient.GetKnot(index)

Return type

Dict[int, c4d.Vector, float, float, float]

Returns

A dictionary with the knot information.

Gradient.SetKnot(self, index, col, brightness, pos, bias)

Set the values of a knot.

Note

Just the passed arguments will be set, the other will be discarded.

Parameters
  • index (int) –

    The knot index.

    Note

    The new knot index has to be 0 <= index < Gradient.GetKnotCount()

  • col (c4d.Vector) – The color.

  • brightness (float) – The brightness.

  • pos (float) – The position.

  • bias (float) – The bias.

Gradient.GetData(self, id)

Gets a data item from the gradient container.

Parameters

id (int) –

Data ID:

GRADIENT_KNOT

BaseContainer

Holds the knots as sub-containers:

GRADIENTKNOT_COLOR

Vector

Color.

GRADIENTKNOT_BRIGHTNESS

float

Brightness.

GRADIENTKNOT_POSITION

float

Position.

GRADIENTKNOT_BIAS

float

Bias.

GRADIENTKNOT_ID

int

Index.

GRADIENTKNOT_INTERPOLATION

int

GRADIENT_INTERPOLATION_CUBICKNOT

Cubic knot.

GRADIENT_INTERPOLATION_SMOOTHKNOT

Smooth knot.

GRADIENT_INTERPOLATION_LINEARKNOT

Linear knot.

GRADIENT_INTERPOLATION_NONE

None.

GRADIENT_INTERPOLATION_EXP_UP

Exponential up.

GRADIENT_INTERPOLATION_EXP_DOWN

Exponential down.

GRADIENT_INTERPOLATION_BLEND

New in version R20: Blend.

GRADIENT_MODE

int

Mode:

GRADIENTMODE_COLOR

Color only.

GRADIENTMODE_ALPHA

Alpha only.

GRADIENTMODE_COLORALPHA

Color and alpha.

GRADIENT_UNCLAMPED

bool

Unclamped

Return type

object

Returns

The data.

Gradient.SetData(self, id, data)

Sets a data item from the gradient container.

Parameters
  • id (int) –

    Data ID:

    GRADIENT_KNOT

    BaseContainer

    Holds the knots as sub-containers:

    GRADIENTKNOT_COLOR

    Vector

    Color.

    GRADIENTKNOT_BRIGHTNESS

    float

    Brightness.

    GRADIENTKNOT_POSITION

    float

    Position.

    GRADIENTKNOT_BIAS

    float

    Bias.

    GRADIENTKNOT_ID

    int

    Index.

    GRADIENTKNOT_INTERPOLATION

    int

    GRADIENT_INTERPOLATION_CUBICKNOT

    Cubic knot.

    GRADIENT_INTERPOLATION_SMOOTHKNOT

    Smooth knot.

    GRADIENT_INTERPOLATION_LINEARKNOT

    Linear knot.

    GRADIENT_INTERPOLATION_NONE

    None.

    GRADIENT_INTERPOLATION_EXP_UP

    Exponential up.

    GRADIENT_INTERPOLATION_EXP_DOWN

    Exponential down.

    GRADIENT_INTERPOLATION_BLEND

    New in version R20: Blend.

    GRADIENT_MODE

    int

    Mode:

    GRADIENTMODE_COLOR

    Color only.

    GRADIENTMODE_ALPHA

    Alpha only.

    GRADIENTMODE_COLORALPHA

    Color and alpha.

    GRADIENT_UNCLAMPED

    bool

    Unclamped

  • data (object) – The data.

Gradient.GetKnotCount(self)

Gets the knot count.

Return type

int

Returns

Knot count.

Gradient.CopyFrom(self, src)

Copies all gradient data from the source gradient.

New in version 2024.0.0.

Parameters

src (c4d.Gradient) – The source gradient.

Returns

True if the copy succeeded otherwise False.

Return type

bool

Gradient.GetChecksum(self)

Gets a checksum of the whole gradient state, including the knots, colors and interpolation type.

New in version 2024.0.0.

Returns

The checksum.

Return type

int

Gradient.GetGradient(self)

Gets the internal gradient.

New in version 2024.0.0.

Returns

The internal gradient.

Return type

maxon.Gradient

Gradient.SetGradient(self, gradient)

Sets the internal gradient.

New in version 2024.0.0.

Parameters

gradient (maxon.Gradient) – The internal gradient to set.

Gradient.GetAlphaGradient(self)

Gets a copy of the alpha gradient.

Note

It is just a copy of the original gradient.
Can be changed, but has no effect to the original alpha-gradient.
Use Gradient.SetAlphaGradient() to set the alpha-gradient.
Return type

c4d.Gradient

Returns

Alpha gradient.

Gradient.SetAlphaGradient(self, alphaGradient)

Sets the alpha gradient.

Parameters

alphaGradient (c4d.Gradient) – Alpha gradient.

Gradient.AllocAlphaGradient(self)

Create a alpha of the gradient. Similar to Gradient.GetAlphaGradient().

Note

It is a copy of the original gradient.
Can be changed, but has no effect to the original alpha-gradient.
Return type

c4d.Gradient

Returns

Alpha gradient.

Gradient.ConvertToAlphaGradient(self, bc=None, id=0)

Converts this gradient to an alpha gradient.

Parameters
  • bc (Optional[c4d.BaseContainer]) – The container holding the gradient.

  • id (Optional[int]) – The ID of the gradient within the container.

Return type

int

Returns

Knot count.