architecture-building-systems / revitpythonshell

An IronPython scripting environment for Autodesk Revit and Vasari
MIT License
490 stars 112 forks source link

RPS 2021 - AttributeError: 'module' object has no attribute 'LoadComponent' #120

Open maltezc opened 2 years ago

maltezc commented 2 years ago

Hi all, I'm trying to get the rps debugger set up working for dynamo and am running into an error in my dynamo. If anyone has any other methods of debugging length dynamo code, please let me know.

I saw this post and have high hopes for this eventually happening

And also the same with this post

I'm trying to follow along with this post and this one but it seems to not be working. A youtube video going through the settings and setup for the necessary programs would be incredibly helpful.

So far, I've tried changing iron python engines in pyrevit as this was suggested but I haven't had any luck. Here is a snippet of all of my ironpython engine options if this helps. image

Here are the versions of relevant programs I have installed:

Here is the error I'm getting:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. Traceback (most recent call last): File "<string>", line 9, in <module> File "C:\Users\cmaltez\AppData\Roaming\Dynamo\Dynamo Revit\2.6\packages\RevitPythonWrapper\extra\rpw.zip\rpw\ui\forms\console.py", line 128, in __init__ AttributeError: 'module' object has no attribute 'LoadComponent'

image

Any and all help is appreciated!

daren-thomas commented 2 years ago

I suggest looking at line 9 of that "Python Script" block. It should have an expression / statement including LoadComponent in it. And dynamo is complaining that it doesn't know what that's about. Are you missing an import statement?

Also, as far as I'm aware, pyRevit, RPS and dynamo are separate tools and your issue description seems to assume they're all somehow linked.

maltezc commented 2 years ago

@daren-thomas , I agree that they are separate tools. I figured I'd try their suggestion anyways. Thanks for clarifying.

In the post i shared, it shows that Gui was able to get RPS to work as a dynamo debugger somehow by using pycharm. To be clear, this is what I'm trying to accomplish.

Apologies, I forgot to post the code inside the dynamo script. It is the same code used in the linked post. Here it is:

import sys
sys.path.append(IN[0]) # Assumes RPW_GetFilePath output is IN[0]

from rpw.ui.forms import Console

for i in range(10):
    if i ==5:
        Console(context=locals())

The error then refers to the console.py file. Here is the line its referring to:

self.ui = wpf.LoadComponent(self, StringReader(Console.LAYOUT))

image

daren-thomas commented 2 years ago

@maltezc, ok, so I don't have a copy of Revit anymore and therefore won't be of much help with this issue for you. One thing that comes to mind is that you might be missing some .net assemblies. Application.LoadComponent is found in the PresentationFramework.dll - so maybe you need to load that. also, check what wpf is... is it really the System.Windows.Application?

A lot of debugging can be done with print statements. A poor man's debugger so to speak.

I'm sorry I can't help you any more than this, but I hope there are some other people here that can!