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 Receive instant notifications for finished calculations on your phone
    • Sign in
    • -Geotechnical Analysis Wiki
      • +Geotechnical SELECT Entitlements [GSE]
      • -PLAXIS
        • +Software and License - PLAXIS
        • +Documentation - PLAXIS
        • -API / Python scripting - PLAXIS
          • Access to Staged Construction settings using Python
          • Adding functionality to PLAXIS Calculation Manager: pre- and post-processing
          • Automatic line cross-section chart generation using Python
          • Automatically generated cross-sections of embankments
          • Changing the material colour using Python scripting
          • Combined plate results in one chart using Python
          • Create custom connection with selection API
          • Export and format plots from PLAXIS Output using Python
          • How to create a tunnel using Python
          • How to get a load - displacement curve using Scripting interface
          • How to install additional Python modules in PLAXIS
          • How to open and close a PLAXIS project with Python
          • How to retrieve results from PLAXIS Output by the node number
          • Identify Python commands from Plaxis command line
          • Material lists in PLAXIS – Python
          • Material Property changes for Python scripting
          • 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
          • Remove invalid custom connections for PLAXIS 3D
          • 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
        • +Known issues - PLAXIS
        • +Models - PLAXIS
        • +Tips and Tricks
        • +Publications
        • +Videos - PLAXIS
      • +PLAXIS LE
      • +PLAXIS Monopile Designer
      • +SOILVISION
      • +Subscription Entitlement Service
    • +Working from home with PLAXIS
    • +Working from home with PLAXIS LE

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

    Receive instant notifications for finished calculations on your phone

    Application PLAXIS 2D
    PLAXIS 3D
    Version PLAXIS 2D
    PLAXIS 3D
    Date created 29 April 2015
    Date modified 29 April 2015

    When running long calculations using PLAXIS, it would be great if you can receive instant notifications when this calculation is finished: either via e-mail or a (push) notification on your smartphone (e.g. iPhone or Android device). This could be very useful for calculations that run unattended for example during a meeting, during lunch break or after office hours.
    With the implementation of the PLAXIS Remote Scripting / HTTP REST API, this is now possible: once a calculation is finished you can be notified instantly!

    First step: Message composition

    Any method that we will use below will first need to calculate the PLAXIS project and gather the results for a short overview of the calculation result.

    First, we need to have the model loaded into PLAXIS and PLAXIS needs to be run as a Remote Scripting server. The PLAXIS Remote Scripting server within PLAXIS 2D or PLAXIS 3D can be activated via the menu item Expert > Configure remote Scripting server.
    See also the related page on Using PLAXIS Remote scripting with the Python wrapper at the bottom of the page.

    Next step is to use Python scripting to start the calculation, after which we can collect the results:

    • check for each phase if the calculation was successful or not
    • Optional, when desired we can get main characteristics for a calculation type, like the reached value of SumMsf for a Safety calculation (i.e. the Factor of Safety)
    • And determine a summary for the notification

    Here we can write a function that gathers the basic phase information: was it calculated, and was it calculated successful or did it fail:

    def gather_phase_overview(): 
        results = [] 
        allpassed = True 
        for phase in g_i.Phases[:]: 
            msg = "not calculated" 
            if not phase.ShouldCalculate: 
                if phase.CalculationResult == phase.CalculationResult.ok: 
                    msg = "OK" # may be extended for more details 
                else: 
                    msg = "Failed: error {0}".format(phase.LogInfo) 
                    allpassed = False 
            results.append("{0}: {1}".format( phase.Name, msg)) 
         return allpassed, results
    

    This can be used to create message data with a subject/summary and a detailed message (the body):

    def get_message_info(): 
        message = {"Subject": "", "Body": ""} 
        allpassed, results = gather_phase_overview() 
        if allpassed == True: 
            message["Subject"] = "Calculation OK" 
        else: 
            message["Subject"] = "Calculation failed" 
        body = ["Summary for PLAXIS calculation"] 
        body.append("Title: {0}".format(g_i.Project.Title)) 
        body.append("File: {0}".format(g_i.Project.Filename)) 
        body.append('') 
        body.append('Phase results:') 
        for result in results: 
            body.append('- {0}'.format(result)) 
        message["Body"] = "n".join(body) 
        return message
    

    E-mail notification

    With Python, it is possible to send e-mail messages, e.g. by using the SMTP protocol via the smtplib module, but of course, more methods are available. For a detailed example, please refer to:

    • the Python sample on Sending an email using Gmail in the PLAXIS Reference manual Appendix on Python HTTP REST API wrapper.
    • this example is based on this Python code example: http://segfault.in/2010/12/sending-gmail-from-python/

    Push notifications on smart devices

    Using third party services/apps it is possible to get push messages/notifications on smart devices like iPhones or Android devices. Two of such services are for example:

    • BoxCar: https://boxcar.io/
    • PushOver: https://pushover.net/

    Such services have apps available for e.g. iOS and Android. Using the service's API it is possible to send a self-made notification to these apps on your smartphone.

    Example: Notifications for iPhone using BoxCar

    Below we have a sample code to send a message using BoxCar. Documentation on how to send a notification to BoxCar:

    • http://help.boxcar.io/support/solutions/articles/6000004813-how-to-send-...

    Note: to be able to use the Boxcar end-user API, you need your "Access Token". The access token is available from the general "Settings" screen of Boxcar or from the Boxcar Web Inbox setting page.
    Also, we will use the requests module, which is not a standard Python module: it is available via https://pypi.python.org/pypi/requests (requires to install) and it is also available as part of the Plaxis scripting environment.

    import requests # available at https://pypi.python.org/pypi/requests 
    import json 
    import time
    
    class BoxCar: 
        BASE_URL = "https://new.boxcar.io/api/" 
        RETRY_ATTEMPTS = 3 
        RETRY_SLEEP = 2 
        SOUND = 'done' 
        ICON = 'https://www.plaxis.com/content/uploads/2016/11/plaxis_64.png' 
        
        def __init__(self, access_token): 
            self.access_token = access_token 
            self.success = False 
            self.encoded_data = None 
            self.sound=self.SOUND
     
        def notify(self, title, message): 
            attempts = 0 
            while attempts < self.RETRY_ATTEMPTS: 
                attempts += 1 
                result = self._send_notification(title, message) 
                if result.status_code == 201: 
                    print("* Message: %s" % title ) 
                    print("* Message delivered @ %s" % result.headers['date']) 
                    self.success = True 
                    break 
                else: 
                    if attempts == self.RETRY_ATTEMPTS: 
                        print("! Message delivery FAILED: %s" % ( result )) 
                        print("!   %s" % result.status_code) 
                    self.success = False 
            return self.success
     
        def _send_notification(self, title, long_message ): 
            ''' Documentation on how to send a notification to BoxCar: 
                http://help.boxcar.io/support/solutions/articles/6000004813-how-to-send-a-notification-to-boxcar-for-ios-users
            ''' 
            print('Sending a notification via BoxCar...') 
            long_message = long_message.replace( "n", '<br />') 
            data = { 'user_credentials': self.access_token, 
                     'notification': { 
                         'title': "PLAXIS: {0}".format(title), 
                         'long_message': long_message, 
                         'sound': self.sound, 
                         'icon_url': self.ICON, 
                         'source_name' : 'PLAXIS' 
                         } 
                    }  
            notifications_url = self.BASE_URL + "notifications" 
            headers = {'Content-type': 'application/json', 
                                       'Accept': 'application/json'} 
            self.encoded_data = json.dumps(data, ensure_ascii=False).encode('utf8') 
            _request = requests.post(notifications_url, 
                                     data=self.encoded_data, 
                                     headers=headers ) 
            return _request
    

    Now we can combine it to send a message. For this, you will need your BoxCar token. The access token is available from the general "Settings" screen of Boxcar or from  Boxcar Web Inbox setting page.

    g_i.calculate() 
    def sendmessage(): 
        message = get_message_info() 
        boxcartoken = '' # YOUR BOXCAR TOKEN HERE! 
        push = BoxCar(boxcartoken) 
        push.notify(message[ "Subject" ], message[ "Body" ]) 
    sendmessage()
    

    Now the push message on e.g. an iPhone will look like this:

    Figure 1. Notifications using BoxCar 2: left lock screen push message and on the right the detailed message

    Conclusion

    Using the power of Plaxis Remote Scripting it is possible to get instant notifications about your PLAXIS calculations on your mobile devices!

    See also

    Identify Python commands from Plaxis command line

    [Python Scripts]


    Using PLAXIS Remote scripting with the Python wrapper

    [Tips and Tricks]


    Remote Scripting API: Drivemining

    [Videos]

    • Rest Http
    • PLAXIS 3D
    • python
    • API
    • py cookbook
    • push
    • Android
    • iPhone
    • mobile
    • PLAXIS
    • Remote scripting
    • cookbook
    • python cookbook
    • ios
    • Notifications
    • PLAXIS 2D
    • Share
    • History
    • More
    • Cancel
    • Micha van der Sloot Created by Bentley Colleague Micha van der Sloot
    • When: Wed, Dec 18 2019 9:34 AM
    • Stefanos Papavasileiou Last revision by Bentley Colleague Stefanos Papavasileiou
    • When: Tue, Feb 15 2022 6:11 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

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