NewLinearDimension Inputs not met

I’m getting an error when running this code. Can’t figure out what is going wrong. I get the same error when I provide a dimension type. The error is referring to the NewLinearDimension method.

IronPython Traceback:
Traceback (most recent call last):
File “L:\Revit\Development\PyRevit\DevTool\DevTool.extension\DevTools.tab\Development.Panel\JustTesting.pushbutton\JustTesting_script.py”, line 90, in
Exception: One of the conditions for the inputs was not satisfied. Consult the documentation for requirements for each argument.

# Testing Script experiments
import datetime

# Import libraries
from pyrevit import DB, revit, script, forms
from Autodesk.Revit.DB import *
from rpw.ui.selection import Pick
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
import Autodesk
from Autodesk.Revit.UI import RevitCommandId
from Autodesk.Revit.UI import UIApplication
from Autodesk.Revit.UI import ExternalCommandData
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from System.Collections.Generic import List

import System
doc = __revit__.ActiveUIDocument.Document
# doc = DocumentManager.Instance.CurrentDBDocument
# uiapp = DocumentManager.Instance.CurrentUIApplication
cView = doc.ActiveView

################################################################################
# Debug toggles
globalDebug = True
disabledScript = False

def dprint(*printItems):
    if globalDebug:
        for pI in printItems:
            print(pI)

####################################################################################################
####################################################################################################
#Create Reference plane
####################################################################################################
####################################################################################################
t = Transaction(doc, "pyRevit - Create Reference Plane")
famMan = doc.FamilyManager

dimTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.LinearDimensionType)
dprint(dimTypeId)
dimType = doc.GetElement(dimTypeId)



t.Start()
# Parameters
# Label __ Left Right
famMan.AddParameter("Label __ Left Right", GroupTypeId.Constraints, SpecTypeId.Length, True)
# Label __ Off Wall
famMan.AddParameter("Label __ Off Wall", GroupTypeId.Constraints, SpecTypeId.Length, True)
# Label_Dim_LeftCorrection
famMan.AddParameter("Label_Dim_LeftCorrection", ForgeTypeId(), SpecTypeId.Length, True)
# Label_Dim_OffsetFromWallCorrection
famMan.AddParameter("Label_Dim_OffsetFromWallCorrection", ForgeTypeId(), SpecTypeId.Length, True)


p = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ(0, 0, 0))
sp = SketchPlane.Create(doc, p)

# Ref Plane Label Anchor
refSymbolAnchorLeft = doc.FamilyCreate.NewReferencePlane(XYZ(-3,-1,0),XYZ(-3,1,0), XYZ(0,0,1), cView)
refSymbolAnchorLeft.Name = "Symbol Anchor"
refSymbolAnchorLeft.Pinned = True
refSymbolAnchorLeft.LookupParameter("Is Reference").Set(12)

# Ref Line Label Vertical Center
lsvc = Line.CreateBound(XYZ(2, -2, 0), XYZ(2, -4, 0))
lineSymbolVerticalCenter = doc.FamilyCreate.NewModelCurve(lsvc, sp)
lineSymbolVerticalCenter.ChangeToReferenceLine()

# Create Dimension
ra = ReferenceArray()
ra.Append(refSymbolAnchorLeft.GetReference())
ra.Append(lineSymbolVerticalCenter.GeometryCurve.Reference)
dimline = Line.CreateBound(XYZ(2, -5, 0), XYZ(-3, -5, 0))

dprint(cView)
dprint(dimline)
dprint(ra)
dprint(ra.IsEmpty)
dprint(ra.Size)
dprint(ra.Item[0])
dprint(ra.Item[1])
dprint(dimType)
dim = doc.FamilyCreate.NewLinearDimension(cView, dimline, ra)

t.Commit()

Ahhhh, I think this is a transaction issue. I committed the transaction after creating the references and added a new transaction for the dimension and it worked.

1 Like

You can also use subtransactions and or doc.Regernerate() to work around issues like this. As you have found out - the element needs to exist before you can work with it.

A subtransaction can keep your undo list shorter and neater.

1 Like

When I ran them in separate transactions it worked but not with this subtransaction setup:

# Testing Script experiments
import datetime

# Import libraries
from pyrevit import DB, revit, script, forms
from Autodesk.Revit.DB import *
from rpw.ui.selection import Pick
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
import Autodesk
from Autodesk.Revit.UI import RevitCommandId
from Autodesk.Revit.UI import UIApplication
from Autodesk.Revit.UI import ExternalCommandData
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from System.Collections.Generic import List

import System
doc = __revit__.ActiveUIDocument.Document
# doc = DocumentManager.Instance.CurrentDBDocument
# uiapp = DocumentManager.Instance.CurrentUIApplication
cView = doc.ActiveView

################################################################################
# Debug toggles
globalDebug = True
disabledScript = False

def dprint(*printItems):
    if globalDebug:
        for pI in printItems:
            print(pI)

####################################################################################################
####################################################################################################
#Create Reference plane
####################################################################################################
####################################################################################################
t = Transaction(doc, "pyRevit - Create Label Controls")
t.Start()

famMan = doc.FamilyManager

dimTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.LinearDimensionType)
dprint(dimTypeId)
dimType = doc.GetElement(dimTypeId)

sT = SubTransaction(doc)
sT.Start()
# Parameters
# Label __ Left Right
famMan.AddParameter("Label __ Left Right", GroupTypeId.Constraints, SpecTypeId.Length, True)
# Label __ Off Wall
famMan.AddParameter("Label __ Off Wall", GroupTypeId.Constraints, SpecTypeId.Length, True)
# Label_Dim_LeftCorrection
famMan.AddParameter("Label_Dim_LeftCorrection", ForgeTypeId(), SpecTypeId.Length, True)
# Label_Dim_OffsetFromWallCorrection
famMan.AddParameter("Label_Dim_OffsetFromWallCorrection", ForgeTypeId(), SpecTypeId.Length, True)


p = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ(0, 0, 0))
sp = SketchPlane.Create(doc, p)

# Ref Plane Label Anchor
refSymbolAnchorLeft = doc.FamilyCreate.NewReferencePlane(XYZ(-3,-1,0),XYZ(-3,1,0), XYZ(0,0,1), cView)
refSymbolAnchorLeft.Name = "Symbol Anchor"
refSymbolAnchorLeft.Pinned = True
refSymbolAnchorLeft.LookupParameter("Is Reference").Set(12)

# Ref Line Label Vertical Center
lsvc = Line.CreateBound(XYZ(2, -2, 0), XYZ(2, -4, 0))
lineSymbolVerticalCenter = doc.FamilyCreate.NewModelCurve(lsvc, sp)
lineSymbolVerticalCenter.ChangeToReferenceLine()
sT.Commit()

sT = SubTransaction(doc)
sT.Start()
# Create Dimension
ra = ReferenceArray()
ra.Append(refSymbolAnchorLeft.GetReference())
ra.Append(lineSymbolVerticalCenter.GeometryCurve.Reference)
dimline = Line.CreateBound(XYZ(2, -5, 0), XYZ(-3, -5, 0))

dprint(cView)
dprint(dimline)
dprint(ra)
dprint(ra.IsEmpty)
dprint(ra.Size)
dprint(ra.Item[0])
dprint(ra.Item[1])
dprint(dimType)
dim = doc.FamilyCreate.NewLinearDimension(cView, dimline, ra)
sT.Commit()

t.Commit()

You might try a doc.Regenerate() after the subtransaction. That updates the database. Might work - but haven’t look at the code in detail.

“The only cases that require explicit regen are when you make several different modifications within one single transaction, and/or query the model after some of them have been make.”
https://forums.autodesk.com/t5/revit-api-forum/when-to-use-doc-regenerate/td-p/8408490

2 Likes

That did it. Thanks.

1 Like