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
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
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:
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
pyRevitLabs.PythonNet
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:
install a python 3.10 distribution in you system (it could be vanilla python or anaconda/condaforge)
install numpy in that python envrionment
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!