Miscellaneous
Run a PythonPart from command line
You can start ALLPLAN and execute a PythonPart from windows command line like:
"x:\Path\to\Prg\Allplan_2099.exe" -o "@Y:\Path\to\PythonPart.pyp" "first_argument" "second_argument" "third_argument"
The path to the PYP file provided in the -o
argument must be absolute and preceded by @
.
It can be followed custom arguments, that you want to pass to your script.
To handle both normal start and start from the command line, the constructor of your script object or interactor should look like:
def __init__(self,
build_ele: BuildingElement,
script_object_data: BaseScriptObjectData):
super().__init__(script_object_data)
if "Allplan_Command_Line" in sys.argv:
# The logic, when script is started from the command line
AllplanBaseEle.ProjectService.CloseAllplan() #(1)!
return
# the logic during regular start
self.build_ele = build_ele
-
Call this function when you want to terminate ALLPLAN after the execution. This way, the batch script moves on and you can e.g. shut down the computer after the execution of the PythonPart like:
The additional parameters from the command line are stored in the sys.argv
, but not
the way you would expect. The first element in this list will be a string Allplan_Command_Line
followed by your custom arguments in reversed order:
Start another PythonPart
You can create a PythonPart, that starts another PythonPart. Optionally, when the other PythonPart is done, it can return back to the first PythonPart. This behavior is possible to achieve with the script object or interactor contracts and here's how:
-
Define the
__init__()
function of your script object or interactor class as usual, i.e.: -
Whenever you want to switch to another PythonPart, call the callable
exec_switch_pythonpart()
.When your script object class inherits from
BaseScriptObject
(as we recommend), this callable is an instance attribute. Call it like:In an interactor, the callable is part of the
BaseInteractorData
class, which on the other hand is composed in your interactor. Therefore, call it likeRegardless, where the other PythonPart is located (in the prj, std, etc or usr), the path you provide to the callable must be relative to one of these directories. The framework will search in all of them in the above order. The boolean argument tells, whether to terminate PythonPart execution after the other PythonPart is done (
False
) or return to the original PythonPart (True
)
Visual scripting
VisualScripting is a no-code feature of ALLPLAN to create PythonParts. The user can visually code his PythonPart, without programming knowledge.
An interactor PythonPart can execute a PythonPart created using Visual Scripting. This makes it possible e.g., to use existing VS-PythonPart scripts and combine them with the placement functionality provided by an interactor PythonPart.
The integration of the VS-PythonPart in the interactor script can be done by using VisualScriptService. This service class allows to:
- load and initialize the VS-PythonPart script
- load and save the favorite data
- process the parameter modification and the control events
- get the created elements for the preview drawing
- create a PythonPart from the script