Hi all
I want cope/cut beams against one another like I want to cope vertical elements against horizontal beams.
I am able to get all horizontal and vertical elements list and I am using python to cope but I am the error as below
The script will look like
The python script I am using by taking reference of Is it possible to change end reference of a beam?
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
if isinstance (IN[0],list):
beams = UnwrapElement(IN[0])
else:
beams = UnwrapElement(IN[0])
if isinstance (IN[0],list):
b = UnwrapElement(IN[1])
else:
b = UnwrapElement(IN[1])
bms = FilteredElementCollector(doc).OfClass(FamilyInstance).FirstElement()
TransactionManager.Instance.EnsureInTransaction(doc)
ref = FamilyInstance.GetReferenceByName(b,"Center (Front/Back)")
for x in beams:
FamilyInstance.AddCoping(x,b)
StructuralFramingUtils.SetEndReference(x,1,ref)
TransactionManager.Instance.TransactionTaskDone()
OUT = bms
Please let me know where I am missing
maybe:
FamilyInstance.AddCoping(x,b)
try to change to:
boo = x.AddCoping(b)
Hi @newshunhk if I change it to x.AddCoping(b) then I am getting the following error
maybe you can try this and modify…
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
if isinstance (IN[0],list):
beams = UnwrapElement(IN[0])
else:
beams = [UnwrapElement(IN[0])]
if isinstance (IN[1],list):
b = UnwrapElement(IN[1])
else:
b = [UnwrapElement(IN[1])]
bms = FilteredElementCollector(doc).OfClass(FamilyInstance).FirstElement()
TransactionManager.Instance.EnsureInTransaction(doc)
for x in beams:
for y in b:
ref = FamilyInstance.GetReferenceByName(y,"Center (Front/Back)")
x.AddCoping(y)
try:
StructuralFramingUtils.SetEndReference(x,0,ref)
StructuralFramingUtils.SetEndReference(x,1,ref)
except:
pass
TransactionManager.Instance.TransactionTaskDone()
OUT = bms
2 Likes
@newshunhk hay it’s working but for only two beams it is getting applied but I want to cope all the vertical beams against all the horizontal beams.
You can see the below picture I want to cope all the vertical beams but only two of them are getting coped on top end but I want to have for both the ends and for all the vertical elements
Please connect horizontal beams to IN[0], vertical beams to IN[1] and try this?
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
if isinstance (IN[0],list):
h_beams = UnwrapElement(IN[0])
else:
h_beams = [UnwrapElement(IN[0])]
if isinstance (IN[1],list):
v_beams = UnwrapElement(IN[1])
else:
v_beams = [UnwrapElement(IN[1])]
TransactionManager.Instance.EnsureInTransaction(doc)
for h in h_beams:
ref = FamilyInstance.GetReferenceByName(h,"Center (Front/Back)")
for v in v_beams:
v.AddCoping(h)
try:
StructuralFramingUtils.SetEndReference(v,0,ref)
StructuralFramingUtils.SetEndReference(v,1,ref)
except:
pass
TransactionManager.Instance.TransactionTaskDone()
OUT = 1
1 Like
Thank you so much @newshunhk I appreciate that you took time for this. Thanks alot.
My final script will look like based on option choosen (Coping of vertical beams with respect to horizontal or coping of horizontal beams with respect to vertical beams)
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
if isinstance (IN[0],list):
h_beams = UnwrapElement(IN[0])
else:
h_beams = [UnwrapElement(IN[0])]
if isinstance (IN[1],list):
v_beams = UnwrapElement(IN[1])
else:
v_beams = [UnwrapElement(IN[1])]
bool = IN[2]
TransactionManager.Instance.EnsureInTransaction(doc)
if bool == True:
for h in h_beams:
ref = FamilyInstance.GetReferenceByName(h,"Center (Front/Back)")
for v in v_beams:
v.AddCoping(h)
try:
StructuralFramingUtils.SetEndReference(v,0,ref)
StructuralFramingUtils.SetEndReference(v,1,ref)
except:
pass
else:
for v in v_beams:
ref = FamilyInstance.GetReferenceByName(v,"Center (Front/Back)")
for h in h_beams:
h.AddCoping(v)
try:
StructuralFramingUtils.SetEndReference(h,0,ref)
StructuralFramingUtils.SetEndReference(h,1,ref)
except:
pass
TransactionManager.Instance.TransactionTaskDone()
OUT = 1
1 Like