Get the centre line of a cable tray using python

Hi all,

I am looking for a way to retrieve a line that is found in GeometryElement like the image below.

I have tried calling a location curve to get the center line, but the origin point of it is occasionally a bit off from the actual origin point that the cable tray is drawn.

I expected that I can get a solid and a line using the code below, but the result is a only solid.

import clr
from Autodesk.DesignScript.Geometry import *

from Autodesk.Revit.DB import *

elem = UnwrapElement(IN[0])

op = Options()
geo = elem.get_Geometry(op)

OUT = geo

Can I get any advice on it?
Thank you.

can you use directly the LocationCurve ?

1 Like

Hi @c.poupin,

Thank you for your advice.
I had tried calling the LocationCurve, but when it comes to the origin point of it, it didn’t retrieve a proper value like the image below.
I don’t know why it happens, but such cases occur occasionally.
The line getting from Geometry.Element shows the correct value as drawn in Revit, so I am now looking for getting this line as the workaround.

Do you by any chance have any idea why the origin point of the LocationCurve has a different value from the actual origin point?
Thank you.

you can use GetEndPoint() method instead of Origin property

here is a comparison of the 3 methods

import clr
import sys
import System
from Autodesk.DesignScript.Geometry import *

from Autodesk.Revit.DB import *
import  Autodesk.Revit.DB as DB

import Revit

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

def get_CableTrayOrigin_1(e):
    return e.Location.Curve.Origin.ToPoint()
def get_CableTrayOrigin_2(e):
    return e.Location.Curve.GetEndPoint(0).ToPoint()
def get_CableTrayOrigin_3(e):
    opt = Options()
    opt.View = doc.ActiveView
    geoset = e.get_Geometry(opt)
    for g in geoset:
        if isinstance(g, DB.Curve):
            p = g.Origin.ToPoint()
            return p

elem = UnwrapElement(IN[0])

OUT = get_CableTrayOrigin_1(elem), get_CableTrayOrigin_2(elem), get_CableTrayOrigin_3(elem)

Nevertheless, knowing that the origin of the curve is located on the fitting is interesting

1 Like

Hi @c.poupin,

Thank you very much for your help!
It works perfectly like the image.
I don’t still get how opt.View works in your code which may be the pivotal part of the 3rd method.

Thank you!

1 Like