-
Notifications
You must be signed in to change notification settings - Fork 13
How To
Table of contents:
- HOW-TO Export Diagram to .bpmn (XML) format
- HOW-TO Save Diagram in SVG
- HOW-TO Display code with line numbers
- HOW-TO Manually select connection sides for elements
- HOW-TO change font size for title, element and footer
To export diagram to .bpmn format, call export_to_bpmn()
method after draw()
method.
my_process_map.draw()
my_process_map.export_to_bpmn("my_process.bpmn")
If you are using PiperFlow syntax, set the optional export_to_bpmn
parameter to True. the .bpmn file name will be the same as the PNG or SVG output file name, but with .bpmn extension.
text2diagram.render(input_syntax, output_file, export_to_bpmn=True)
Known Limitation: The BPMN 2.0 specification does not support font colour or lane fill colour. The attributes listed below cannot be exported to.bpmn:
- Pool text font
- Lane fill colour
- Lane text colour
- Shape text colour
To save diagram in SVG instead of the default PNG format, specify painter_type
when creating ProcessMap.
with ProcessMap(
"My Process", painter_type="SVG"
) as my_process_map:
...
my_process_map.save("my_process.svg")
To display generated code, print the return code using text2diagram.show_code_with_line_number() function.
input_syntax = """<your piperflow text>"""
gen_code, img = text2diagram.render(input_syntax)
text2diagram.show_code_with_line_number(gen_code)
1 from processpiper import ProcessMap, EventType, ActivityType, GatewayType
2 with ProcessMap("debug", colour_theme="BLUEMOUNTAIN", width=10000) as my_process_map:
3 with my_process_map.add_pool("Pool") as pool1:
4 with pool1.add_lane("") as lane1:
5 start = lane1.add_element("start", EventType.START)
6 activity_14 = lane1.add_element("the customer receives feedback from the assessor or approver", ActivityType.TASK)
7 end = lane1.add_element("end", EventType.END)
8 activity_13 = lane1.add_element("assess the request", ActivityType.TASK)
9 gateway_1 = lane1.add_element("", GatewayType.EXCLUSIVE)
10 gateway_2 = lane1.add_element("", GatewayType.EXCLUSIVE)
11 deny_the_loan = lane1.add_element("deny the loan", ActivityType.TASK)
12 approve_the_loan = lane1.add_element("approve the loan", ActivityType.TASK)
13 send_the_request = lane1.add_element("send the request", ActivityType.TASK)
14 gateway_2_end = lane1.add_element("", GatewayType.EXCLUSIVE)
15 gateway_1_end = lane1.add_element("", GatewayType.EXCLUSIVE)
16 start.connect(activity_13)
17 activity_13.connect(gateway_1)
18 gateway_1.connect(gateway_2)
19 gateway_1.connect(approve_the_loan, "the loan is \nsmall, the \ncustomer is")
20 approve_the_loan.connect(gateway_1_end)
21 gateway_2.connect(deny_the_loan)
22 gateway_2.connect(send_the_request, "the customer is")
23 send_the_request.connect(gateway_2_end)
24 deny_the_loan.connect(gateway_2_end)
25 gateway_2_end.connect(gateway_1_end)
26 gateway_1_end.connect(activity_14)
27 activity_14.connect(end)
28 my_process_map.draw()
29 my_process_map.save("piper_20230813_144818.png")
An element has four connection points. Namely: Top, Bottom, Left and Right.

Processpiper library connects these shapes automatically according to their connection points' distance. If the output is not how you like it, you can manually specify the connection side. Here is how:

To draw a connection from source element's bottom point to target element's left point as shown above, specify the source_connection_side
and target_connection_side
when calling connect()
method.
source_element.connect(target_element, source_connection_point=Side.BOTTOM, target_connection_point=Side.LEFT)

To draw a connection from source element's right point to target element's right point as shown above, specify the source_connection_side
and target_connection_side
when calling connect()
method.
source_element.connect(target_element, source_connection_point=Side.RIGHT, target_connection_point=Side.RIGHT)
Note:
- If you only specify either of the sides (
source_connection_side
ortarget_connection_side
), processpiper library will automatically determine the nearest point for the corresponding element.
You can change font size for title, element and footer using the following methods. Call the methods before draw()
method:
process_map.set_title_font_size(30)
process_map.set_element_font_size(10)
process_map.set_footer("My footer", font_size=20)
process_map.draw()
process_map.save("my-diagram.png")