The documentation from version 39.5.17 of PLANTA project can be found in the new PLANTA Online Help.

Autonomous Module Call

General

Objective

  • When opening modules, the submodule must not receive any instructions from the source module that influence the module behavior.

Agreements

  • Modules must be customized with Python in a way that they can administrate the action to be carried out themselves.
  • The module call must not be followed by a menu item command.
  • Only @L variables are used as filter criteria, @D variables are no longer used.
  • Module numbers are not programmed fixed in Python, but the module numbers are to be saved in global variables and read from them.

Creation of an Autonomous Module Call

Use of the ppms_cu.py Python Module

Details

  • Together with with the Python API, the ppms_cu.py Python module is to form a basis for customizing macros.
    • Documentation of ppms_cu.py
    • The Python module has classes and methods at its disposal which are essential to the creation of an autonomous module call.

Class Access - Enables Access to PLANTA Python Objects

  • Method - get_datafields_by_sc
    • Searches for data fields with the specified filter criterion
      • As a return, you receive a Python dictionary
        • DAC-Id: String as key
        • DFC-Id: String returned as a value.

Class Action - Enables the Manipulation of Objects/Launches Actions

  • Method - call_SUB
    • Opens a submodule starting from the main_mod object

Use of the module_macro_helper.py Python module

Details

Creation of a Macro Module for Opening a Submodule

Details

  • Creation of a Python macro module as described here.
  • The Python macro contains the initialization of the action object as well as the call of Call_Sub().
#Create object of ppms_cu.Action class 
   ppms_cu_action = ppms_cu.Action(invoker_module) 
   #Create sub_mod_dictionary 
   sub_mod_dict={} 
   sub_mod_dict['009101'] = ["right",0.3,{'@L4':[values]}] 
   ppms_cu_action.call_SUB(sub_mod_dict=sub_mod_dict) 
  • You can use, e.g., module 0099Y3/ „Python macro: open data areas" as a development template.

Creation of the Submodule Macro

Details

  • According to the on_load() and on_focus() methods, you can specify more accurately which actions are started when activating the submodule.
  • You can use the modul_macro_helper.py Python module for a facilitated creation of module macros.

Notes

  • Opening Call_Sub() for the first time causes the on_load() methods to be carried out.
    • In order to already activate the module at on_load(), on_load() must open the focus() method of the Objects module.
      • As a result, the focus() method causes the module to be activated at the client and on_focus() to be run.
  • From now on, the on_focus() method is opened each time.
  • Module 000857 Data Areas can be used as a development template.

Add Individual Methods to a Module Instance

Objective

  • The module instance is to offer an individual interface outwardly, via which it can be controlled.
  • Data is handed over in a method call.

Details

  • In order to link the methods to the module instance, the MethodType class of the types Python module is used.

Notes

  • The first parameter of the function converted to a method is reserved for the instance.
    • Therefore, “self” should be included in the method name for reasons of comprehensibility (same convention as for regular methods).
  • The converted function can be defined in the macro itself or in an external module.
    • Individual methods that are used by many methods should be kept centrally (in an external module).

Example

  • A project module is to display data of a particular project.
  • The program code of the added method is far from being a good code! Here, the focus is on the use of MethodType only.
from types import MethodType

mod = ppms.get_target_module()

def show_project(self, project_id):
    self.menu(19)
    project_da = self.get_das()[0]
    first_rec = project_da.get_records()[0]
    project_df = first_rec.get_df('pr_id')
    project_df.set_text_value(project_id)
       
def on_load():
    mod.menu(11)	
    mod.show_project = MethodType(show_project, mod)
    
def on_initial_focus():
    mod.show_project('4711')
    
def on_focus():
    pass

def on_reset():
    on_load()

         PLANTA project









 
  • Suche in Topic-Namen

  • Suche in Topic-Inhalten
This site is powered by the TWiki collaboration platform Powered by Perl