3.4 Common Errors

We all get errors - no big deal! Here are some errors you're likely to encounter.

Introduction

The Python Script node often gives useful feedback when things go wrong, enabling us to figure out where the problems in our code lie.

Since most errors begin with: 'IronPythonEvaluator.EvaluateIronPythonScript operation Failed', this will be omitted from any errors below.

Reading Traceback Errors

Traceback errors try and tell the full story of errors as they happened. As with Dynamo, an error somewhere is likely to cause a cascade of errors to occur. The Traceback message will tell you where things went wrong in reverse order, telling you the source of the error first with its line number.

It will also often give information as to the kind of error, such as 'TypeError'. From the kinds of errors, it is possible to further infer what went wrong in your code.

The referenced object is not valid, possibly because it has been deleted from the database, or its creation was undone

This is a common error, which translates to 'your script tried to refer to an object that is no longer there'. This is most often caused by deleting an element from the active document and then trying to access that element again after its deletion.

Unexpected Token

This is simply down to a syntax error (your fault, I'm afraid). Perhaps you forgot the ':' after a conditional branch or there is an unclosed parenthesis left somewhere in your code?

Python scripts are broken down into 'tokens' which helps the program navigate the logic of your code. If the parser comes across a token which makes no sense in the Python language, your node will throw this error.

'Unexpected Indent' or 'Inconsistent Use of Tabs and Spaces'

The in-built Python Script editor often has troubles with tabs and spaces in larger scripts. These can be especially tricky to remedy as they're invisible! Fortunately, this can be easily resolved by using Microsoft's Visual Studio Code application.

First, you'll need to get it set up:

  1. If you don't have it already, download Visual Studio Code.

  2. Once installed, you'll need to install the Python extension and pylint.

  3. Start a new file, make sure it's read as a Python file.

  4. In the View menu, select 'Command Palette' and type 'Convert Indentation to Tabs'.

That's it - you should now be able to copy/paste your code back into the Dynamo Python Editor window.

Modifying is forbidden because the document has no open transaction.

Revit won't let you edit its database until you've wrapped all of the modifications inside a transaction. Learn more about transactions here.

Last updated