Placing a Column with Python Node

Hey Guys,

I’m trying to place a Column by using the dynamo node. While doing so i keep encountering this error:

Autodesk.Revit.Exceptions.InvalidOperationException: Instance of a level-based family cannot be created without a valid reference level.
at ?A0xa6a4641f.updateInstParamsForLevelRefFamily(ADocument* pADoc, FamilyInstance* pFamilyInstance, Boolean* structuralColumn, ElementId* levelId)
at ?A0xa6a4641f.addFamilyInstanceEx(ADocument* pADoc, Owner<FamilyInstance>* oFamilyInstance, Enum structuralType, ElementId* levelId, Boolean* shouldRegen, Boolean batchprocessing)
at Autodesk.Revit.Creation.addFamilyInstance(ADocument* pADoc, FamilyInstance* pFamilyInstance, Enum structuralType, Boolean* shouldRegen, ElementId* levelId)
at Autodesk.Revit.Creation.ItemFactoryBase.NewFamilyInstance(XYZ location, FamilySymbol symbol, Element host, StructuralType structuralType)

The code snippet i’m trying to use :

def processColumn(self, columnDict,level):
        try:
            xCoordinate = float(columnDict["origoPos"]["x"])*1000
            yCoordinate = float(columnDict["origoPos"]["y"])*1000
            zCoordinate = float(columnDict["origoPos"]["z"])*1000
            basePoint=Point.ByCoordinates(xCoordinate,yCoordinate,zCoordinate)       

            symbol=columnDict["symbol"]

            TransactionManager.Instance.EnsureInTransaction(self.doc)
            symbol.Activate()
            fam=self.doc.Create.NewFamilyInstance(basePoint.ToXyz(), symbol, level , StructuralType.Column)
            TransactionManager.Instance.TransactionTaskDone()   
            return fam 
        except Exception as e:
            return e

The inputparameters (basePoint, symbol, level,StructuralType.Column) seem to be valid. Does anybody know what the cause of this error could? Currently im using Revit 2023.1 with DYNAMO v.2.16.2 . Weird thing is that the columns do get placed:

But they don’t get assigned to the level:


The level im inputting is an actual existing level. I hope somebody could help me out here.

The error says you haven’t provided a valid reference level. Your code looks correct but we can’t see what you’re actually providing as inputs. Share your full code and a screenshot of any inputs from Dynamo.

I’m sorry for the mistake. The way how i get the levels is as follows:

def processColumn(self, columnDict):
        try:
            xCoordinate = float(columnDict["origoPos"]["x"])*1000
            yCoordinate = float(columnDict["origoPos"]["y"])*1000
            zCoordinate = float(columnDict["origoPos"]["z"])*1000
            basePoint=Point.ByCoordinates(xCoordinate,yCoordinate,zCoordinate)       

            symbol=columnDict["symbol"]
            levels= FilteredElementCollector(self.doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
  
            TransactionManager.Instance.EnsureInTransaction(self.doc)
            symbol.Activate()
            fam=self.doc.Create.NewFamilyInstance(basePoint.ToXyz(), symbol, levels[0], StructuralType.Column)

            TransactionManager.Instance.TransactionTaskDone()   
            return fam 
        except Exception as e:
            return e

Does this help @Nick_Boyts ?

Get rid of the try/except loop to see what errors you get. If that doesn’t help, share the DYN and a simplified sample RVT so we can test.

With the try/except-block removed i get the same error. So the script i use now is as below. As Template i use a blank Template from revit 2023.1 (Metric-Architectural Template). I just paste the code below in a python node in a blank .dyn file, this should reproduce the error (see image).


# Load the Python Standard and DesignScript Libraries
import clr
clr.AddReference('RevitAPI')
clr.AddReference("RevitServices")
clr.AddReference('ProtoGeometry')
clr.AddReference("RevitNodes")
clr.AddReference('System')
from Autodesk.Revit.DB import BuiltInCategory
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Plumbing import *
import Autodesk
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
from Autodesk.DesignScript.Geometry import *
from System.Collections.Generic import *
from Autodesk.Revit.DB import FilteredElementCollector, FamilySymbol, Level, Transaction
from Revit.Elements import StructuralType

xCoordinate = 2500
yCoordinate = 0
zCoordinate = 0
doc = DocumentManager.Instance.CurrentDBDocument
basePoint=Point.ByCoordinates(xCoordinate,yCoordinate,zCoordinate) 
symbols = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Columns).WhereElementIsElementType().ToElements()
levels = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()

TransactionManager.Instance.EnsureInTransaction(doc)
symbols[0].Activate()
fam=doc.Create.NewFamilyInstance(basePoint.ToXyz(), symbols[0], levels[0], StructuralType.Column)
TransactionManager.Instance.TransactionTaskDone() 

It looks like CPython3 might still have issues with overload methods unfortunately.

This thread has a little more explanation: Creating column on a point using NewFamilyInstance - Revit - Dynamo

1 Like

Hi @donny.hoogendorp

try to use this method instead

and StructuralType must come from the Autodesk.Revit.DB.Structure NameSpace

# Load the Python Standard and DesignScript Libraries
import clr
clr.AddReference('RevitAPI')
clr.AddReference("RevitServices")
clr.AddReference('ProtoGeometry')
clr.AddReference("RevitNodes")
clr.AddReference('System')
from Autodesk.Revit.DB import BuiltInCategory
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Plumbing import *
from Autodesk.Revit.DB.Structure import StructuralType
import Autodesk
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
from Autodesk.DesignScript.Geometry import *
from System.Collections.Generic import *
from Autodesk.Revit.DB import FilteredElementCollector, FamilySymbol, Level, Transaction

xCoordinate = 2500
yCoordinate = 0
zCoordinate = 0
doc = DocumentManager.Instance.CurrentDBDocument
basePoint=Point.ByCoordinates(xCoordinate,yCoordinate,zCoordinate) 
symbols = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Columns).WhereElementIsElementType().ToElements()
levels = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()

TransactionManager.Instance.EnsureInTransaction(doc)
symbols[0].Activate()
fam=doc.Create.NewFamilyInstance(basePoint.ToXyz(), symbols[0], levels[0], levels[0], StructuralType.Column)
TransactionManager.Instance.TransactionTaskDone()
1 Like

Hi, you set the level argument twice :wink:
edit: I didn’t say anything I saw that it was the host (always think before speaking, sorry)

cordially
christian.stan

yes :wink:

1 Like

question in passing: the Activate() method of the familySymbol class must be included in the transaction?
cordially
christian.stan

it is not mandatory

1 Like