Auto Dimension for FilledRegion

Good afternoon! I ask for help. I’m trying to correct the script from the Russian-speaking forum to install auto-size on FilledRegion. Еhe original code was
import clr
clr.AddReference(‘RevitAPI’)
import Autodesk
from Autodesk.Revit.DB import *
from System.Collections.Generic import *
import System
import math

clr.AddReference(‘ProtoGeometry’)
_import Autodesk.DesignScript.Geometry import * _
from operator import itemgetter, attrgetter

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.GeometryReferences)

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
uiapp=DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
gopt = Options()
gopt.ComputeReferences = True
view = doc.ActiveView
gopt.View = view
elem=IN[0]
ref= ReferenceArray()
d=IN[1]
p1=Point.ByCoordinates(0,0)
p2=Point.ByCoordinates(0,d)
vec1=Vector.ByTwoPoints(p1,p2).ToXyz()
p3=Point.ByCoordinates(d,0)
vec2=Vector.ByTwoPoints(p1,p3).ToXyz()
TransactionManager.Instance.EnsureInTransaction(doc)
for t in IN[0]:
_ k = UnwrapElement(t).GetBoundaries()_
_ for r in k:_
_ for i in r:_
_ line = i.ToProtoType()_
_ length=line.Length_
_ dirX=line.Direction.X/length_
_ dirY=line.Direction.Y/length_
_ a = i.GetEndPointReference(0)_
_ ref.Append(a)_
_ b = i.GetEndPointReference(1)_
_ ref.Append(b)_
_ newdim = doc.Create.NewDimension(doc.ActiveView, i, ref)_
_ newdim.ToDSType(False)_
_ if abs(dirX) < 0.1:_
_ ElementTransformUtils.MoveElement(doc,newdim.Id,vec2)_
_ else:_
_ ElementTransformUtils.MoveElement(doc,newdim.Id,vec1)_
_ ref.Clear()_
TransactionManager.Instance.TransactionTaskDone()
But the script produces an error File “”, line 60, in Exception: Invalid number of references where the 60th line newdim = doc.Create.NewDimension(doc.ActiveView, i, ref).
Then I found advice on changing the name of the library
clr.AddReference (‘ProtoGeometry’)
import Autodesk.DesignScript.Geometry as ge # to distinguish libraries
and changed part of the code
p1=ge.Point.ByCoordinates(0,0)
p2=ge.Point.ByCoordinates(0,d)
vec1=ge.Vector.ByTwoPoints(p1,p2).ToXyz()
p3=ge.Point.ByCoordinates(d,0)
vec2=ge.Vector.ByTwoPoints(p1,p3).ToXyz()
but unfortunately I get the same error Invalid number of references on line newdim = doc.Create.NewDimension(doc.ActiveView, i, ref).
Maybe someone knows what the error is?
Thank you!

Hi Myhail,

Did you find a solution for this issue? I am having same issue.

Can you post the code formatted properly, using the code format tool (looks like </> in the toolbar). That way people don’t have to guess what parts of the code belongs to what for loops, etc.

The error is saying invalid number of references, have you checked the output of ref to see if it is the right amount? Check with the API to read more on it: NewDimension method

Yes you are right. The problem is that the Reference Line of the FilledRegion is not defined and gives the value “nule”. Once again the code (blanks replaced _)

import clr
clr.AddReference(‘RevitAPI’)
import Autodesk
from Autodesk.Revit.DB import *
from System.Collections.Generic import *
import System*
import math*

clr.AddReference(‘ProtoGeometry’)
import Autodesk.DesignScript.Geometry import *
from operator import itemgetter, attrgetter*

clr.AddReference(“RevitNodes”)*
import Revit*
clr.ImportExtensions(Revit.Elements)*
clr.ImportExtensions(Revit.GeometryConversion)*
clr.ImportExtensions(Revit.GeometryReferences)*

clr.AddReference(“RevitServices”)*
import RevitServices*
from RevitServices.Persistence import DocumentManager*
from RevitServices.Transactions import TransactionManager*

doc = DocumentManager.Instance.CurrentDBDocument*
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument*
uiapp=DocumentManager.Instance.CurrentUIApplication*
app = uiapp.Application*
gopt = Options()*
gopt.ComputeReferences = True*
view = doc.ActiveView*
gopt.View = view*
elem=IN[0]*
ref= ReferenceArray()*
d=IN[1]*
p1=Point.ByCoordinates(0,0)*
p2=Point.ByCoordinates(0,d)*
vec1=Vector.ByTwoPoints(p1,p2).ToXyz()*
p3=Point.ByCoordinates(d,0)*
vec2=Vector.ByTwoPoints(p1,p3).ToXyz()*
TransactionManager.Instance.EnsureInTransaction(doc)*
for t in IN[0]:
____k = UnwrapElement(t).GetBoundaries()
____for r in k:
________ for i in r:
________ line = i.ToProtoType()
________ length=line.Length
________ dirX=line.Direction.X/length
________ dirY=line.Direction.Y/length
________ a = i.GetEndPointReference(0)
________ ref.Append(a)
________ b = i.GetEndPointReference(1)
________ ref.Append(b)
________ newdim = doc.Create.NewDimension(doc.ActiveView, i, ref)
________ newdim.ToDSType(False)
________ if abs(dirX) < 0.1:
____________ ElementTransformUtils.MoveElement(doc,newdim.Id,vec2)
________ else:
____________ ElementTransformUtils.MoveElement(doc,newdim.Id,vec1)
________ ref.Clear()
TransactionManager.Instance.TransactionTaskDone()