Create Beams by Python block

I’ve tried to create beams by Python block using methods as follow from RevitAPI 2018:


I want to achieve this by using the second overload which is in the red-line box, but when I finish my code I met an error said ‘NewFamilyInstance() takes at least 5 arguments (4 given)’, but the method that I want use exzactly needs 4. I am really confused and upset about this. Could anyone be so kind to help me to find the right way to create beams by method provided by RevitAPI?
the code is as follow:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import TaskDialog

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB.Events import *
from Autodesk.Revit.DB import *
from Autodesk.Revit.Creation import *
from Autodesk.Revit.DB.Structure import *
from math import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

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

import System
#def


DOC = DocumentManager.Instance.CurrentDBDocument
UIAPP = DocumentManager.Instance.CurrentUIApplication
UIDOC = UIAPP.ActiveUIDocument
VER = DOC.Application.VersionName.replace("Autodesk Revit","")
LOC = DOC.Application.Language == Autodesk.Revit.ApplicationServices.LanguageType.Chinese_Simplified


Lines=IN[0]
BeamType=IN[1]
RefLevel=IN[2]


Beams=[]
for l in Lines:
    rvl=l.ToRevitType()
    beam=Autodesk.Revit.Creation.Document.NewFamilyInstance(rvl, BeamType, RefLevel, Autodesk.Revit.DB.Structure.StructuralType.Beam)
    Beams.append(beam)


TransactionManager.Instance.TransactionTaskDone()


OUT=Beams

Here is for your reference and code is provided below …

# dynamo version - 1.3.0 

import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")

from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument;

lines = IN[0];
beams = [];

# list 
if isinstance(lines, list):
	lines = UnwrapElement(lines);
else:
	lines = UnwrapElement([lines]);

#current view level
level = doc.ActiveView.GenLevel;

#collect family symbol
fsymbol = FilteredElementCollector(doc).OfClass(FamilySymbol).OfCategory(BuiltInCategory.OST_StructuralFraming).ToElements()[0];

#transaction start
TransactionManager.Instance.EnsureInTransaction(doc);

for line in lines:
	
	#create beam
	beam = doc.Create.NewFamilyInstance(line.GeometryCurve, fsymbol, level, Structure.StructuralType.Beam);
	beams.append(beam);

#transaction end
TransactionManager.Instance.TransactionTaskDone();

OUT = beams;
8 Likes

thank so much!

awesome thankuuuuuuuuuu

can u give same script for column by using rectangle instead of lines your using for beam

My guess would be to simply replace the word “Beam” with “Column” in this line:
“beam = doc.Create.NewFamilyInstance(line.GeometryCurve, fsymbol, level, Structure.StructuralType.Beam);”

so that the end looks like this:

	#create beam
	column = doc.Create.NewFamilyInstance(line.GeometryCurve, fsymbol, level, Structure.StructuralType.Column);
	columns.append(column);

#transaction end
TransactionManager.Instance.TransactionTaskDone();

OUT = columns;

hi @ramsaik495,

I write a script for column too, it’s a bit different with beam creation way because of their family nature …
For instance, Beam can create by your curves(lines) geometry and Column can only be created on the origin point. In this example, I created at the start point of each line.

Anyway, the code is provided below and @Jonathan.Olesen your guess is so close :grinning:

# dynamo version - 1.3.0 

import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")

from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument;

lines = IN[0];
columns = [];

# list 
if isinstance(lines, list):
	lines = UnwrapElement(lines);
else:
	lines = UnwrapElement([lines]);

#current view level
level = doc.ActiveView.GenLevel;

#collect family symbol
fsymbol = FilteredElementCollector(doc).OfClass(FamilySymbol).OfCategory(BuiltInCategory.OST_StructuralColumns).ToElements()[0];


#transaction start
TransactionManager.Instance.EnsureInTransaction(doc);

for line in lines:
	
	#create column
	column = doc.Create.NewFamilyInstance(line.GeometryCurve.GetEndPoint(0), fsymbol, level, Structure.StructuralType.Column);	
	columns.append(column);

#transaction end
TransactionManager.Instance.TransactionTaskDone();

OUT = columns
3 Likes

Damn, my ‘‘guess’’ was solely based on the apparent logic in the script :slight_smile: glad I was somewhat close :slight_smile:

Thanku so much jean & one more question
There is any option to create column one the rectangle instead of line

Thanks for giving reply
iam tried like that but its showing an error

hi @jean
can u give the same program for duct by line

There you go @ramsaik495,

import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")

from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Mechanical import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument;

lines = IN[0];
ductType = UnwrapElement(IN[1]);

ducts = [];

# list 
if isinstance(lines, list):
	lines = UnwrapElement(lines);
else:
	lines = UnwrapElement([lines]);

#current view level
level = doc.ActiveView.GenLevel;

#collect family symbol
fsymbol = FilteredElementCollector(doc).OfClass(MechanicalSystemType).ToElements()[0];


#transaction start
TransactionManager.Instance.EnsureInTransaction(doc);

for line in lines:
	
	#create duct
	duct = Duct.Create(doc, fsymbol.Id,ductType.Id, level.Id, line.GeometryCurve.GetEndPoint(0), line.GeometryCurve.GetEndPoint(1));	
	ducts.append(duct);

#transaction end
TransactionManager.Instance.TransactionTaskDone();

OUT = ducts
1 Like

hi @jean

thanku jean its working

hi @jean

it showing error as below
can u solve these error

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 36, in
AttributeError: ‘NoneType’ object has no attribute ‘Id’

Thank you!!!

1 Like

Hi Jean, how are you?

I have a similar problem, but I only have points to insert columns, instead of rows. How should the points code be?

I tried something like that:

import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")

from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument;

points = IN[0];
columns = [];

l0 = len(points)
#current view level
level = doc.ActiveView.GenLevel;

#collect family symbol
fsymbol = FilteredElementCollector(doc).OfClass(FamilySymbol).OfCategory(BuiltInCategory.OST_StructuralColumns).ToElements()[0];


#transaction start
TransactionManager.Instance.EnsureInTransaction(doc);

for i in range(0,l0):
	point = points[i]
	#create column
	column = doc.Create.NewFamilyInstance(point, fsymbol, level, Structure.StructuralType.Column);	
	columns.append(column);

#transaction end
TransactionManager.Instance.TransactionTaskDone();

OUT = columns

hi @brenofilipe, yes … what you did is correct. You can directly loop through your input(list of points) for point in points : ...

1 Like