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!