Upgrading to Python 3


I made some scripts in iron python for revit.
I am trying to upgrade to Python 3 but am stuck on some basic errors.
Shown below is a defenition that always worked on the old python.
Now i get the error invalid syntax on the “None” part of the script.
I dont even know where to start with an error like this

def PickPoint(a = "Select a point on the screen"):
    var = Autodesk.Revit.UI.Selection.ObjectSnapTypes.None, a
    out = uidoc.Selection.PickPoint(var)    
    return out

Check this Ironpython 3.4:  issue with enum when using its `None` member ? · Issue #1873 · eirannejad/pyRevit · GitHub

That should solve your issue


Hi @MelleH,
are you sure this is the exact code you used before?

On line 2 you declare a tuple, and then on line 3 you pass it as a single parameter to pickpoint, that needs 2 separate arguments.

You should unpack the tuple using **var inside the PickPoint method, but creating a tuple to unpack it on the next instruction is useless, so I suggest to use

def pick_point(prompt = "Select a point on the screen"):
    obj_type = Autodesk.Revit.UI.Selection.ObjectSnapTypes.None
    return uidoc.Selection.PickPoint(obj_type, prompt)   

here I also gave the variables an appropriate name, in order to clarify what they are/do.

A final note: please post the exact error with the traceback (if any), so that we can better understand the problem.

EDIT: I was too late and didn’t have the right answer, but my points are still valid :wink:


Thanks for the replys!
Sorry i hadn’t responded. Didn’t have the time.

The main reason i want to use CPyton is becouse of the modules i can use.
Now i tried to import some simple modules but i dont seem to get it working.
I’ve followed some of the other posts about this topic here but i can’t get it to work.
My code:

#! python3
import sys
import numpy

The error message i get is :

3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)]

CPython Traceback:
ModuleNotFoundError : No module named ‘numpy’
File “L:\REVIT\Dynamo\Toolbar\Tab P-BEH Melle\Melle.extension\P-BEH.tab\Persoonlijk MHo.panel\TestKnop.pushbutton\script.py”, line 4, in
import numpy

at Python.Runtime.Runtime.CheckExceptionOccurred()
at Python.Runtime.PyScope.Exec(String code, IntPtr _globals, IntPtr _locals)
at Python.Runtime.PyScope.Exec(String code, PyDict locals)
at PyRevitLabs.PyRevit.Runtime.CPythonEngine.Execute(ScriptRuntime& runtime)

Hi @MelleH,
the numpy library is not included in pyrevit, so, in order to make it import able, you install and make it available to the python interpeter.

You can do it following these steps:

  1. install a python 3.10 distribution in you system (it could be vanilla python or anaconda/condaforge)
  2. install numpy in that python envrionment
  3. in your pyrevit script, do a sys.path.append(xxx) where xxx is the path of the site-packagedirectory of the python environment

after that, you can try to import the numpy library, but I suspect it will not work. As I tried to state quite a few times here and on github, and also tried to advertise in the quickstart post, cpython support is not yet ready for production.
Good luck with that!