Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
PLAXIS | SOILVISION
  • Product Communities
  • More
PLAXIS | SOILVISION
PLAXIS | SOILVISION Wiki Changing the material colour using Python scripting
    • Sign in
    • +Working from home with PLAXIS
    • Working from home with SOILVISION
    • -PLAXIS | SOILVISION Wiki
      • Geotechnical SELECT Entitlements [GSE]
      • -PLAXIS
        • PLAXIS CONNECT Edition and legacy versions
        • +License - PLAXIS
        • +PLAXIS Software downloads
        • +Release Notes PLAXIS 2D and PLAXIS 3D
        • +Manuals - PLAXIS
        • -API / Python scripting - PLAXIS
          • How to install additional Python modules in PLAXIS
          • Access to Staged Construction settings using Python
          • Automatic line cross-section chart generation using Python
          • Changing the material colour using Python scripting
          • Combined plate results in one chart using Python
          • Create custom connection with selection API
          • How to create a tunnel using Python
          • How to get a load - displacement curve using Scripting interface
          • Identify Python commands from Plaxis command line
          • Material lists in PLAXIS – Python
          • Output scripting example: create curve data
          • Output scripting example: get anchor force
          • Output scripting example: get heave of excavation bottom
          • Output scripting example: get maximum bending moment
          • Polycurves to Polygons in PLAXIS 2D using Python
          • Receive instant notifications for finished calculations on your phone
          • Retrieve coordinates of a Polygon in PLAXIS 2D using Python
          • Retrieving soil layer info from boreholes using Python
          • Scripting reference and how to use it
          • Selection API for PLAXIS Input
          • Soil layer material assignment using Python
          • Tunnel advancement script for PLAXIS 3D
          • User defined Python script (3D): Extract displacements by coordinates
          • Adding functionality to PLAXIS Calculation Manager: pre- and post-processing
          • Remove invalid custom connections for PLAXIS 3D
        • +Downloads - PLAXIS
        • +Known issues - PLAXIS
        • +Models - PLAXIS
        • +Publications
        • +Tips and Tricks
        • +Tutorials - PLAXIS
        • +Verifications - PLAXIS
        • +Videos - PLAXIS
      • +PLAXIS MoDeTo
      • +SOILVISION
      • +Subscription Entitlement Service

     
     Questions about this article, topic, or product? Click here. 

    Changing the material colour using Python scripting

    Application PLAXIS 2D
    PLAXIS 3D
    Version PLAXIS 2D
    PLAXIS 3D
    Date created 09 February 2018
    Date modified 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

    Version

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

    See also

    Using PLAXIS Remote scripting with the Python wrapper

    [Tips and Tricks]


    Identify Python commands from Plaxis command line

    [Python Scripts]

    • Plaxis 3D
    • python
    • RGB
    • API
    • py cookbook
    • colour
    • Automation
    • Scripting
    • PLAXIS
    • Remote scripting
    • cookbook
    • material
    • python cookbook
    • PLAXIS 2D
    • color
    • Share
    • History
    • More
    • Cancel
    • Micha van der Sloot Created by Bentley Colleague Micha van der Sloot
    • When: Wed, Dec 18 2019 9:33 AM
    • Stefanos Papavasileiou Last revision by Bentley Colleague Stefanos Papavasileiou
    • When: Tue, Oct 13 2020 6:20 AM
    • Revisions: 3
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2021 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies