I tried to extract the parameters of a window (height and width for area calculation).
For a window I do it with the code block, everything works:
I try with all kinds of project windows with Python:
I get the error in the line 31
I can’t understand why
Some help will be appreciated
Thank you
Try adding these lines as part of the imports (if you haven’t already)
They will add the dynamo design script classes
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
1 Like
Thanks for the reply
I checked and those Dynamo design script classes are there
What does the warning say?
Thanks for the reply
I don’t understand the warning… the kink
Parameter.Parameter By Name
works
You have imported both the Autodesk.Revit.DB.Parameter
and Revit.Elements.Parameter
classes so there may be some clashing or overwriting.
Comment out the following lines and see if that helps
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
1 Like
hi, here is removing the number of variables and following Mr. Mike’s remarks
Don’t forget to put between < / >
your code
import sys
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
FIN=IN[0]
Stock=[]
for t in range(len(FIN)):
t3=FIN[t]
la=Revit.Elements.Parameter.ParameterByName(t3,"Largeur").Value
ha=Revit.Elements.Parameter.ParameterByName(t3,"Hauteur").Value
S=la*ha
Stock.append([la,ha,str(round(S,2))+" m²"])
OUT = Stock
Sincerely
christian.stan
jmark
October 17, 2024, 3:23am
9
my solution:
import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import System
from System import Array
from System.Collections.Generic import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
#------------------------------------------------------
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument
#------------------------------------------------------
elements = UnwrapElement(IN[0])
area_lst = []
for element in elements:
width = element.get_Parameter(BuiltInParameter.FAMILY_WIDTH_PARAM).AsDouble()
height = element.get_Parameter(BuiltInParameter.GENERIC_HEIGHT).AsDouble()
area = width * height
new_val = UnitUtils.ConvertFromInternalUnits(area, UnitTypeId.SquareMeters)
area_lst.append(new_val)
#------------------------------------------------------
OUT = area_lst
1 Like
Thanks for the reply… works fine
1 Like
Thanks for the reply…very interesting
hi, glad to hear it, all we have to do is close the topic as resolved
(choice of Design Script classes or Revit API classes that of Mr. jmark)
Sincerely
christian.stan
1 Like