@@ -37,11 +37,11 @@ Create a custom operator
3737To create a custom DPF operator using PyDPF-Core, define a custom operator class inheriting from
3838the :class: `CustomOperatorBase <ansys.dpf.core.custom_operator.CustomOperatorBase> ` class in a dedicated Python file.
3939
40- The following are sections of a file named `custom_operator_example.py `.
40+ The following are sections of a file named `custom_operator_example.py ` available under `` ansys.dpf.core.examples.python_plugins ``:
4141
42- First, create the custom operator class, with necessary imports and a first property to define the operator scripting name:
42+ First declare the custom operator class, with necessary imports and a first property to define the operator scripting name:
4343
44- .. literalinclude :: custom_operator_example.py
44+ .. literalinclude :: /../../src/ansys/dpf/core/examples/python_plugins/ custom_operator_example.py
4545 :end-at: return "my_custom_operator"
4646
4747Next, set the `specification ` property of your operator with:
@@ -55,13 +55,13 @@ Next, set the `specification` property of your operator with:
5555 when running the operator. Set it equal to ``any_dpf_supported_increments `` to allow any license
5656 currently accepted by DPF (see :ref: `here<target_to_ansys_license_increments_list> `)
5757
58- .. literalinclude :: custom_operator_example.py
58+ .. literalinclude :: /../../src/ansys/dpf/core/examples/python_plugins/ custom_operator_example.py
5959 :start-after: return "my_custom_operator"
6060 :end-at: return spec
6161
6262Next, implement the operator behavior in its `run ` method:
6363
64- .. literalinclude :: custom_operator_example.py
64+ .. literalinclude :: /../../src/ansys/dpf/core/examples/python_plugins/ custom_operator_example.py
6565 :start-after: return spec
6666 :end-at: self.set_succeeded()
6767
@@ -89,7 +89,7 @@ You can transform this single Python file into a DPF Python plugin very easily b
8989``load_operators(*args) `` function with a call to the
9090:func: `record_operator() <ansys.dpf.core.custom_operator.record_operator> ` method at the end of the file.
9191
92- .. literalinclude :: custom_operator_example.py
92+ .. literalinclude :: /../../src/ansys/dpf/core/examples/python_plugins/ custom_operator_example.py
9393 :start-at: def load_operators(*args):
9494
9595PS: You can declare several custom operator classes in the same file, with as many calls to
@@ -104,12 +104,10 @@ First, start a server in gRPC mode, which is the only server type supported for
104104
105105.. jupyter-execute ::
106106
107- import os
108107 import ansys.dpf.core as dpf
109108
110109 # Python plugins are not supported in process.
111- server = dpf.start_local_server(config=dpf.AvailableServerConfigs.GrpcServer)
112-
110+ server = dpf.start_local_server(config=dpf.AvailableServerConfigs.GrpcServer, as_global=False)
113111
114112With the server and custom plugin ready, use the :func: `load_library() <ansys.dpf.core.core.load_library> ` method in a PyDPF-Core script to load it.
115113
@@ -119,14 +117,23 @@ With the server and custom plugin ready, use the :func:`load_library() <ansys.dp
119117
120118.. jupyter-execute ::
121119
120+ # Get the path to the example plugin
121+ from pathlib import Path
122+ from ansys.dpf.core.examples.python_plugins import custom_operator_example
123+ custom_operator_folder = Path(custom_operator_example.__file__).parent
124+
125+ # Load it on the server
122126 dpf.load_library(
123- filename=os.getcwd() , # Look into the current directory
127+ filename=custom_operator_folder , # Path to the plugin directory
124128 name="py_custom_operator_example", # Look for a Python file named 'custom_operator_example.py'
125129 symbol="load_operators", # Look for the entry-point where operators are recorded
126130 server=server, # Load the plugin on the server previously started
127131 generate_operators=False, # Do not generate the Python module for this operator
128132 )
129133
134+ # You can verify the operator is now in the list of available operators on the server
135+ assert "my_custom_operator" in dpf.dpf_operator.available_operator_names(server=server)
136+
130137.. _tutorials_custom_operators_and_plugins_custom_operator_use_the_custom_operator :
131138
132139Use the custom operator
0 commit comments