Module object has no attribute

Hi,

Im getting an module object has no attribute error using the a pyrevit function. Im not sure it isnt working. I had it working on my home pc but for some reason wont work on work pc.

import clr
import pyrevit
from pyrevit import *

clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI') 
from Autodesk.Revit.DB import * 
from Autodesk.Revit.UI import *

doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument

def get_parameter_value_by_name(element, parameterName):
	return element.LookupParameter(parameterName).AsValueString()

#Select elements from revit.
selection = [doc.GetElement(x) for x in uidoc.Selection.GetElementIds()]

for s in selection:
    locationcurve = s.Location.Curve
    beam_start_point = locationcurve.GetEndPoint(0)
    beam_end_point = locationcurve.GetEndPoint(1)
    converted_start_point = pyrevit.revit.geom.convert_point_to_metric(beam_start_point)
    converted_end_point = pyrevit.revit.geom.convert_point_to_metric(beam_end_point)



Hi @shane_au
I cannot reproduce, it seems to work fine on my end.

on another note:
import * is a bad practice, and performance wise, not so good as well

try from pyrevit import revit, DB
It will be much better and you won’t have to prefix all pyrevit functions with pyrevit.

1 Like

Thanks for the tips @Jean-Marc

I did some troubleshooting and have narrowed down the issue a little further. Hopefully this extra information helps track down the issue.

  • If i replace a script in the pyrevit toolbar with my script it will run. However it will only run after i run another command from the pyrevit menu. Then it will continiue to run fine.

  • If i run it from my extension tab. it wont ever work. regardless if i run other commands before it.

  • If i copy a pyrevit command to my extension that uses the pyrevit module, it will run fine.

  • a script on my extension that doesnt use the pyrevit module will also run fine.

I hope this makes sense. The version of pyrevit i installed was the public release version exe. not the commandline in case this makes a difference.

ok, after changing my code to what you suggested @Jean-Marc it works
import * is definately bad hah

import pyrevit
from pyrevit import revit, DB

Glad it worked out.
In your case, import pyrevit might be redundant

from pyrevit import revit, DB is enough