pyrevitlabs / pyRevit

Rapid Application Development (RAD) Environment for Autodesk Revit®
http://wiki.pyrevitlabs.io
GNU General Public License v3.0
1.33k stars 337 forks source link

import rpw in RevitPythonShell crashes Revit2023 (pyRevit v4.8.14) #2081

Open jj-github-jj opened 9 months ago

jj-github-jj commented 9 months ago

🙏 Please use the search in the issue section before filing a new issue


🐞 Describe the bug

import rpw in RevitPythonShell crashes Revit2023 (pyRevit v4.8.14) from pyrevit import revit works without crashing revit. also pyRevit is working otherwise as I am running custom buttons etc just fine but was now trying to use rpw for the first time but cant get past line 1 i.e import rpw tried from rpw import db and it also crashed revit

♻️ To Reproduce

open revitpythonshell (it says 3.4.1 ironpython on my computer but pyRevit says running on ironpython 3.4.0) write import rpw hit run watch crash of Revit2023

⏲️ Expected behavior

A clear and concise description of what you expected to happen.

🖼 Screenshots of the issue

If applicable, add screenshots to help explain your problem.

🖥️ Hardware and Software Setup (please complete the following information):

👉 pyrevit env Latest Installed .Net Framework: 4.8 No .Net Target Packs are installed. No .Ne-Core Target Packs are installed. pyRevit CLI v4.8.14.24016+1909.ee814ee2f686d23db8bb6ff80d8bb918ff9adc99 ==> Registered Clones (full git repos) ==> Registered Clones (deployed from archive/image) master | Deploy: "basepublic" | Branch: "master" | Version: "4.8.14.24016+1909" | Path: "C:\Users\user\AppData\Roaming\pyRevit-Master Admin Access: No

Additional context

Add any other context about the problem here.

onomou commented 3 months ago

I am seeing a number of places where Python 2 syntax is used, which may be causing your issue. One option (that I don't like) may be to change your IronPython engine to 2.x. I looked at the source and found some things that seemed to crash Revit for me.

One change in Python 3 is iteritems() for dicts has been replaced in Python 3 by items(). For example: https://github.com/pyrevitlabs/pyRevit/blob/f9fa0d296386d548e198324dd752fb7fb5cd7b58/pyrevitlib/rpw/base.py#L54

Raising exceptions is another change. raise ErrorType, message is now raise ErrorType(message).

https://github.com/pyrevitlabs/pyRevit/blob/f9fa0d296386d548e198324dd752fb7fb5cd7b58/pyrevitlib/rpw/utils/rlcompleter.py#L36

I don't know enough about the development to know how to fix all of this. I think progress has been made on pyRevit itself:

https://github.com/pyrevitlabs/pyRevit/blob/f9fa0d296386d548e198324dd752fb7fb5cd7b58/site-packages/pyparsing.py#L716-L719

I got rpw to work for me by mass editing my pyRevit source files, and it seems to work fine. If the changes in pyparsing.py are all it takes to fix this for more people, I would be happy to help with fixing this.

sanzoghenzo commented 3 months ago

Thanks @onomou to report your findings!

rpw was neglected for quite some time now, an I personally think we should merge the missing functionalities into pyrevit itself instead of maintaining two separate libraries (rpw was abandoned by the original author, IIRC).

In the meantime, the updates to make it compatible with both python 2 and 3 are more than welcome!

Bear in mind that PY_3 is a pyrevit variable that rpw shouldn't use to avoid coupling of the teo libraries and possibly circular dependencies problems.

@jj-github-jj FYI pyrevit ships its own versions of ironpython and doesn't use the one installed in your system.