Value cannot be null. Parameter name: view

Hey,
I was wondering how can I fix this problem?

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory,Dimension

from Autodesk.Revit.Creation import Document

walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()

wallLocations = [wall.Location for wall in walls]

wallCurves = [wallLoc.Curve for wallLoc in wallLocations]
    
wall_line=[i for i in wallCurves]

ra=ReferenceArray()
ref=[]

for i in wallCurves:

  ra.Append(i.GetEndPointReference(0))
  ref.append(ra)
  ra.Append(i.GetEndPointReference(1))
  ref.append(ra)

for i in ref:
 for b in wall_line:
    dim = doc.Create.NewDimension(doc.ActiveView,b, i)

hi,
it certainly cannot run as is.
running this in pyRevit or RPS?
top of my head

  • doc is not defined
  • you can also declare the active_view, just cleaner
  • creation implies a revit Transaction needs to be started then commited
# what is missing at the top of your script
from pyrevit import revit
doc = revit.doc
active_view = doc.ActiveView
# end of the boiler plate and imports 

# what is missing at the very end, wrap your element/dimension creation
with revit.Transaction('whatever you are doing described'):
    for i in ref:
        for b in wall_line:
            # changed to the active_view variable
            dim = doc.Create.NewDimension(active_view ,b, i)

I doubt this will be enough to get it working, but that is a step in the right direction

hey, I’m using revit python shell I think pyrevit doesn’t define in it.

your referenceArray needs to be redefined for each dimension creation, therefore inside the loop

as for working in rps, then I can’t help you furthermore.

After some changes I use the script blow and run it with Pyrevit. there is no error but also nothing happend :sweat_smile:

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, Dimension,Transaction, Reference, ReferenceArray
from pyrevit import script, forms
from rpw import revit
from Autodesk.Revit.Creation import Document

doc = revit.doc
uidoc = revit.uidoc
logger = script.get_logger()


walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()

wallLocations = [wall.Location for wall in walls]

wallCurves = [wallLoc.Curve for wallLoc in wallLocations]

wall_line = [i for i in wallCurves]

ra = ReferenceArray()
ref = []

for i in wallCurves:
    ra.Append(i.GetEndPointReference(0))
    ra.Append(i.GetEndPointReference(1))

t= Transaction(doc,"Linear Dimension")
t.Start()


for i in ref:
  for b in wall_line:
     dim = doc.Create.NewDimension(doc.ActiveView, b, i)


t.Commit()

well, it is kind of a big mess now.
that being said. KISS rule:

from pyrevit import revit, DB

doc = revit.doc

walls = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()

with revit.Transaction("Create Dimension"):
      for wall in walls:
        wall_curve = wall.Location.Curve
        ra = DB.ReferenceArray()
        #that part does not work, to dimension walls it is slightly more complicated than that, you don't have the right number of references
        ra.Append(wall_curve.GetEndPointReference(0))
        ra.Append(wall_curve.GetEndPointReference(1))
        dim = doc.Create.NewDimension(doc.ActiveView, wall_curve, ra)

but again, you could literally take Cyril’s example I sent you in previous forum thread