Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 66754

Re: How to connect a horizontal cable tray with a vertical cable tray by Revit A

$
0
0

Hi!

 

I tried to create a vertical cable tray and connect it to the existing horizontal tray manually, but it didn't work for me, e.g. Revit didn't create tee fitting in my case, so may I and you miss something?

 

I wrote a Revit Python Shell script (without any checks, that should be presented in a production code), that successfully creates a tee fitting when cable tray is horizontal. Look at this small example, please:

from Autodesk.Revit.DB.Electrical import *

def FindCableTrayConnector(cableTray, point):
	return filter(lambda x: x.Origin.IsAlmostEqualTo(point), cableTray.ConnectorManager.Connectors)[0]

existingTray = selection[0] # you should select a horizontal cable tray before running this script

pt = existingTray.Location.Curve.Evaluate(0.5, True)

tx = Transaction(doc, "create cable tray")
tx.Start()

ptEnd = pt + existingTray.Location.Curve.Direction.CrossProduct(XYZ.BasisZ)*10
# ptEnd = pt + 10*XYZ.BasisZ # in such case NewTeeFitting returns None and there no fitting is created

branchCableTray = CableTray.Create(doc, existingTray.GetTypeId(), pt, ptEnd, existingTray.ReferenceLevel.Id)

newCurve = existingTray.Location.Curve.Clone()

newCurve.MakeBound(0, 0.5*existingTray.Location.Curve.Length)

existingTray.Location.Curve = newCurve

newCableTray = doc.GetElement(ElementTransformUtils.CopyElement(doc, existingTray.Id, pt - existingTray.Location.Curve.GetEndPoint(0))[0])

doc.Regenerate()

c1 = FindCableTrayConnector(existingTray, pt)
c2 = FindCableTrayConnector(newCableTray, pt)
c3 = FindCableTrayConnector(branchCableTray, pt)

print doc.Create.NewTeeFitting(c1, c2, c3)

tx.Commit()

Viewing all articles
Browse latest Browse all 66754

Trending Articles