do#
- Mapdl.do(par, ival='', fval='', inc='', **kwargs)#
Context manager for an APDL
*DOloop.Mechanical APDL Command: *DO
The block of commands issued inside the
withblock is sent to MAPDL once and executed repeatedly by MAPDL itself, similarly to how the*DO/*ENDDOcommands work when typed directly into MAPDL. This is fundamentally different from a Pythonforloop: the body of thewithblock is only evaluated once by Python to build up the block of APDL commands, and MAPDL performs the actual looping.This method automatically uses the
Mapdl.non_interactivecontext manager (unless it is already active) so the whole loop is sent to MAPDL as a single block.MAPDL allows a maximum of 20 levels of nested do-loops (shared between
*DOand*DOWHILE). Attempting to nest more loops than that raises aMapdlDoLoopLimitError.If an exception is raised inside the
withblock, the*ENDDOis never sent and the (incomplete) commands buffered by this loop are discarded, without affecting commands legitimately buffered before entering the loop, for example by an outernon_interactiveblock or an outerdo/dowhileloop.- Parameters:
- par
str The name of the scalar parameter used as the loop index. Any existing parameter of the same name is redefined.
- ival
str,optional Initial value assigned to
par.- fval
str,optional Final value. If
ivalexceedsfvalandincis positive, the loop is not executed.- inc
str,optional Increment applied to
parfor each successive loop. Defaults to 1 in MAPDL. Negative increments and non-integer numbers are allowed.
- par
- Returns:
contextlib.AbstractContextManagerContext manager that opens the
*DOloop on entry and closes it with*ENDDOon exit.
- Return type:
_DoLoop
Examples
Create 10 nodes along the X axis.
>>> with mapdl.do("i", 1, 10): ... mapdl.n("i", "i", 0, 0)