Changing the material colour using Python scripting

09 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


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

Related posts

Privacy Preference Center


The Cookies are necessary for the site to function

CONSENT, NID, _cfduid, wp-settings-time-16, wp-setting-16, wordpress_test_cookie, gdpr[allowed_cookies], gdpr[consent_types], wp_woocommerce_session, wordpress_logged_in, wordpress_sec, PHPSESSID


These Cookies are used to provide you with useful information based on recent browser data

UserMatchHistory, lang, BizoID
lidc, bcookie


These are used to track user interaction and detect potential problems. These help us improve our services by providing analytical data on how users use this site

_ga, _gid