Using the QForm API for Python

<< Click to Display Table of Contents >>

Navigation:  Users manual > Work with the Application Wizard >

Using the QForm API for Python

When working with a large project, the code should be written directly in the development environment. Jupyter Notebook (www.jupyter.org) is widely spread for Python programming language. It's possible to write code in cells and execute individual application fragments.

1. Run Jupyter Notebook and create a new file. In the first cell we will write the code to runQForm UK. It is important to correctly specify the path to the file with API commands.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

 

import sys

sys.path.append(r'C:\QForm UK\12.0.1\API\App\Python')

 

from QFormAPI import*

 

qform = QForm()

 

try:

arg1 = r'C:\QForm UK\12.0.1\x64'

    qform.qform_dir_set(arg1)

 

if qform.qform_is_started_by_api():

        qform.qform_attach()

 

else:

        arg2 = False

        ret2 = qform.qform_start(arg2)

 

except Exception:

    print('Error')

The try-except block allows you to join an open project or open a project in new QForm UK window.

Running code carried out at the press a Run button.

2. Let's consider the application of API commands on the example of creating a project through the development environment .

First, let's create a process consisting of one operation:

1

2

3

4

5

6

 

arg3 = OperationParams()

arg3.id = 1

arg3.name = r'Operation 1'

arg3.parent = 0

arg3.creation_mode = OperationCreationMode.CreateAsNewProcess

ret3:ItemId = qform.operation_create(arg3)

Next, let's select the problem type:

1

2

3

4

5

6

7

 

arg4 = Property()

arg4.object_type = ObjectType.Operation

arg4.object_id = - 1

arg4.path = r'dim_type'

arg4.property_type = PropertyType.Value

arg4.value = r'axis'

qform.property_set(arg4)

After running these blocks, the first operation with the 2D axisymmetric problem type will be created.

3. Similarly, using commands from Application Wizard, you can add all the necessary parameters for the operation.

Below is a code example that allows you to select the workpiece material, specify the initial workpiece temperature, and select the drive for tool 1 from the standard database:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

 

# Material

arg5 = Property()

arg5.object_type = ObjectType.Workpiece

arg5.object_id = 1

arg5.path = r'params/material_id'

arg5.property_type = PropertyType.Value

arg5.value = r'std:w-material/Steels/Carbon steels/C22 (1-0402)'

qform.property_set(arg5)

 

# Temperature

arg6 = Property()

arg6.object_type = ObjectType.Workpiece

arg6.object_id = 1

arg6.path = r'params/temper'

arg6.property_type = PropertyType.Value

arg6.value = r'1200'

qform.property_set(arg6)

 

# Drive

arg7 = Property()

arg7.object_type = ObjectType.Tool

arg7.object_id = 1

arg7.path = r'drive_id'

arg7.property_type = PropertyType.Value

arg7.value = r'std:drive/Mechanical press/25MN'

qform.property_set(arg7)

info

Information

Note that to set properties to objects, you must first load the geometry of these objects and assign types to them.