March 25, 2021
Integrate any Engineering Software Easily with a New Configurable and Flexible User Block
pSeven allows engineers to integrate any CAD/CAE software packages their company use into a single workflow and to eliminate exhaustive repetitive tasks by automating file and data exchange between them.
There are three different ways of software integration in pSeven:
- Direct integration ― allows integration using program-specific blocks, which are intended to provide an easy configurable connector between pSeven and a specific software tool (SolidWorks, Creo, NX, ANSYS, etc.)
- Generic integration ― allows integration using command line interface. It provides greater flexibility than direct integration blocks, but often requires more configuration.
- Integration using User Blocks ― a new integration method released in the 6.17 version. It allows users to integrate any software in their workflow. User block allows user to combine the advantages of two previous integration ways: convenient configuration of direct integration with an interface between a pSeven workflow and a software and a great flexibility of generic integration.
User block integration implementation is presented in this Tech Tip article.
Fig. 1. User Block in pSeven
An example of using User block in a rotation disk problem
User block is a full-featured block template, which user can use to extend the pSeven’s block library with new integrations. User block interface is similar to an integration type blocks and provides some of their components. Most notably, the parameters tree, which allows the user who configures the block to review the list of inputs and outputs list and set the block ports with couple of clicks. Block also provides error handling support, sandbox directories, and other common block features.
The amount of required custom code is minimal: the block just needs two Python functions, which return the tree of parameters in edit time and process the input data in runtime.
Below, we will use a Rotating Disk project from a standard pSeven example (3.1) to demonstrate the implementation of the User block.
It is worth noting that this article contains only a brief guide about User block. To see more information, please visit User block section of the pSeven user manual.
Fig. 2. Drawing of the rotating disk
Workflow with rotating disk calculation has 10 input variables: 8 geometry parameters (r1, r2, r3, r4, r5, r6, t1, t3, t5) and 2 physical parameters (Mass of blades “Mb” and rotation rate “N”). A solver calculates 3 output variables: max stress (“Seqv_max”), mass and displacements (“u2”) of the rotating disk.
As we use the self-made solver, the standard scheme (Text block - Program block - Text block) of generic integration is implemented in the example.
The first Text block of this workflow loads a template file and substitutes values of input variables in specified fields, then outputs modified file to a port. Program block receives this input file and starts the program. After simulation is done, result file is transferred to another text block, which parses and outputs all the results.
Fig. 3. Rotating disk calculation workflow
Our task is to replace described generic integration scheme with single easy-to-use one User block.
Adding a block to the library
First, we need to add our new block to pSeven library using create_block.py script located in pSeven dir\scripts\, where pSeven dir is the pSeven installation directory.
Our command will be as follows:
where— default pSeven installation directory.
After using this command create_block.py script will create RotatingDisk directory in pSeven dir\blocks\. The user_block.py module in this directory will contain two functions which you have to implement, as this module define all the functionality of this block. Subsequently we will show how to implement these functions. Once you restart pSeven, you will see the new block in the block library pane:
Fig. 4. RotatingDisk user block in the block library pane
The first function we need is a tree build function, which provides input and output parameters to the user interface of the block. The user can then select tree nodes to map them to block’s input and output ports, which you can read and write at the run-time.
The tree can be static (entirely defined by block implementation), or the block can generate it by parsing some file selected by the user. In our case, we will use a static tree, as all input and output parameters of model are known in advance. In that way, we only need to create a tree with a specific structure. After that, all the necessary parameters will be shown in the configuration tab.
The tree is a list of dictionaries that has the following structure:
See User block manual to get more information about structure of the parameter tree. The final tree build function will only consist of a static tree. Expandexpand_more
Again, in general case such description can be a result of model preprocessing, when the available parameters are extracted from text files or using simulation tool API.
Fig. 5. Parameters tree of the User block
After tree build function is implemented, you can open your block and tap Build Tree button, then all parameters of the model will be shown on the pane like in a direct integration block (Fig. 5.).
Next to implement is a step function which contains block runtime logic. The block calls this function every time it is executed in the workflow.
First of all, we should obtain all received input values in dictionary format, where the key is a parameter name and the value is a value of parameter. We use input_read() method to get port values.
Then we use this dictionary to generate input file for solver:
After that we set the path to our solver and start the calculation using generated input data. The path to the solver is set in an option pane of the block dialog, field Executable file path. You can get this path in the script using kwargs.get (“exec_file_path”, “”) command.
Fig. 6. Path to the solver
After calculation is done, we need to parse solver output. All result data is saved in dictionary parsed_results
Using output_write() method we set output port values:
As a result, we have ready-to-run user block with a direct interface between a workflow and the solver, which allows to run a simulation of the rotating disk and use its results of stress and displacement later in the workflow.
Fig. 7. Implemented rotating disk User block
An entire code of the implemented User block is as follows: expandexpand_more
Block update and sharing
When updating pSeven, it is necessary to upgrade user blocks from the previous installation to make them available in the updated version. To upgrade a user block from a previous version of pSeven:
- Back up the block directory and .p7block file from the previous installation of pSeven. In our case, the block directory is RotatingDisk, and name of the .p7block file is RotatingDisk.6.18.400.p7block. Default location of these files is
- Back up the projects that include workflows with user blocks.
- Install a new version of pSeven, but do not run it yet.
- Copy the block directory and .p7block file to pSeven dir\blocks\in the new installation
( as for version 6.20 of pSeven).
- Run create_block.py --upgrade-blocks in the new installation using the pSeven’s in-built Python. Therefore, the full command will be as follows:
After the script finishes, you can continue working with projects from the previous version in the updated pSeven.
Do not open existing projects with user blocks in the updated version of pSeven before adding and upgrading user blocks in the new pSeven installation. Otherwise, user blocks may be automatically removed from a workflow when you open it in the new pSeven installation.
Note that it is also possible to re-implement a block in the new version of pSeven — you can add a new block and copy code from the old block. A strong disadvantage of this method is that the block will get a new identifier, so pSeven will not be able to recognize the new block as an upgraded version of some previously available block. Consequently, the new version of pSeven will remove your block from workflows on open, since block’s version in a workflow will have an identifier that is not found in the block library of the new pSeven.
To share your blocks with other users who have the same version of pSeven as yours, you just need to copy the block directory (in our case RotatingDisk) and .p7block file (RotatingDisk.6.18.400.p7block) to the pSeven dir\blocks\ of another computer.
User block is a convenient integration tool that allows users to create interface between a pSeven workflow and any software they use.
This tech tip demonstrates an example of implementation of such block. Compared to the generic integration approach, which used to be the only method available to integrate some specific, rare or in-house software, you can now reuse and share the custom integration block with your team. As we see, block requires a minimum amount of code in Python, only two functions that define all the functionality of the block. In that way, knowing the exchange formats or API of the simulation tool you want to integrate it is possible to create your own User block and include it into pSeven block library for everyday convenient use.
We encourage you to share your User blocks with our development team if you feel that your custom integration block fits right in the upcoming pSeven releases.
By Alexander Dosyuk, Application Engineer, DATADVANCE