Changing the material colour using Python scripting


ApplicationPLAXIS 2D
PLAXIS 3D
VersionPLAXIS 2D
PLAXIS 3D
Date created09 February 2018
Date modified09 February 2018

The generation of the colour numbers for Plaxis material datasets is based on a function that combines Red, Green and Blue (RGB) colour codes into one number, using a function that involves bit-shifting of the colour numbers.

The function is:

(B shift bits left: 16) + (G shift bits left: 8) + R

In Python, the example below will set the material colour of a material called Sand to an orange colour with R, G, B = 255, 174, 61

def get_RGB_number(R, G, B):
    # get colour number from RGB using BIT LEFT SHIFT
    iB = B<<16 # left shift 16 bits for Blue
    iG = G<<8  # left shift  8 bits for Green
    iR = R     # left shift  0 bits for Red
    return iB + iG + iR


def setMaterialColourRGB(material, R, G, B):
    material.Colour = get_RGB_number(R, G, B)
    

soilmat = g_i.Sand
RGB = (255, 174, 61)
# change the colour of the Sand material:
setMaterialColourRGB(soilmat, *RGB)

This code was made for PLAXIS 2D 2017 and PLAXIS 3D 2017 assuming we have a soil material named Sand.
g_i refers to the  Plaxis Input global object.

Changing soil material color using Python

Figure 1. Changing soil material colour to orange using Python

Version

The above example is made for PLAXIS 2D 2017.00 and PLAXIS 3D 2017.00 using Python 3.4.x

See also