You can run native Fusion Electronics commands—such as RIPUP, DELETE, or GROUP—against a schematic, board, or library from a script. Commands use the same syntax as Electronics script files (.scr); see the Fusion Electronics command reference for the supported commands.
Commands are submitted as an ordered batch. The batch runs as a single operation, and the result reports the outcome of every command and the messages they produced.
Each command must contain all the arguments it needs to run without user interaction. For example, a command that would normally ask for a confirmation needs SET CONFIRM YES; ahead of it.
| Type | Role |
|---|---|
EcadCommandInput |
The batch of command strings and the stop and rollback policy. Created with EcadDrawing.createCommandInput(). |
EcadCommandBatchResult |
The overall result returned by EcadDrawing.executeCommands(). |
EcadCommandResult |
The outcome of one command in the batch. |
EcadCommandMessage |
One informational, warning, or error message produced during execution. |
Call createCommandInput on a Schematic, Board, or Library (any EcadDrawing), add commands with add or addRange, then pass the input to executeCommands.
import adsk.core
import adsk.electron
app = adsk.core.Application.get()
brd = adsk.electron.Board.cast(app.activeProduct)
cmd_input = brd.createCommandInput()
cmd_input.addRange([
"SET CONFIRM YES;",
"DISPLAY ALL;",
"RIPUP;",
"GROUP (-32 -32) (-32 32) (32 32) (32 -32);",
"DELETE (> 0 0);",
])
result = brd.executeCommands(cmd_input)
app.log("Batch succeeded: {0}".format(result.success))
add and addRange only store the strings. Commands are parsed and validated when executeCommands is called. Use count and item(index) to read back the commands in the batch, and clear() to empty it.
Two properties on EcadCommandInput control what happens when a command fails. Both default to True.
| Property | When True |
When False |
|---|---|---|
stopOnError |
Commands after the first failed command are not run; their status is NotExecutedEcadCommandStatus. |
Execution continues with the following commands when it is safe to do so. |
rollbackOnError |
If the batch fails, all changes made by the batch are discarded and EcadCommandBatchResult.rolledBack is True. |
Changes made before the failure are kept. |
EcadCommandBatchResult provides:
success — True when every command completed. A command that completes with warnings still counts as successful. It is False if any command failed or was not run.rolledBack — True when the batch failed and its changes were discarded. The drawing is then in the state it had before the batch.startedCommandCount — the number of commands that were started (commands that were not run are not counted).commandResults — one EcadCommandResult per command in the input, in the original order.messages — all messages from the batch, including batch-level messages that don't belong to a single command.Each EcadCommandResult has commandIndex, command, status, and its own messages.
Command statuses (EcadCommandStatuses)
| Value | Meaning |
|---|---|
SucceededEcadCommandStatus |
Completed with no warnings. |
SucceededWithWarningEcadCommandStatus |
Completed, with one or more warnings. |
FailedEcadCommandStatus |
Started but did not complete successfully. |
NotExecutedEcadCommandStatus |
Not started, normally because an earlier command failed. |
Message severities (EcadCommandMessageSeverities): InfoEcadCommandMessageSeverity, WarningEcadCommandMessageSeverity, ErrorEcadCommandMessageSeverity.
Each EcadCommandMessage has severity, text, command, and commandIndex. A commandIndex of -1 (and an empty command) marks a batch-level message.
# Per-command outcome.
for i in range(result.commandResults.count):
cr = result.commandResults.item(i)
app.log("[{0}] {1}: {2}".format(i, cr.status, cr.command))
# All messages, with the command each one belongs to.
for i in range(result.messages.count):
msg = result.messages.item(i)
app.log("[{0}] [{1}] {2}".format(msg.commandIndex, msg.severity, msg.text))
if result.rolledBack:
app.log("Batch failed; the drawing was restored.")