Create Beams by Python bolck

revit
python
dynamo

#1

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

#2

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;

#3

thank so much!


#4

awesome thankuuuuuuuuuu


#5

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


#6

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;

#7

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

#8

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


#9

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


#10

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