Placing Lighting Fixtures along Cable trays


I am new to Dynamo, and I am trying to create what I think is a simple program for automatically placing Lighting Fixtures along Cable Trays.

So far my program creates curves along the cable trays and puts points along the curve on which the Lighting fixtures are placed. But that’s not enough.

Here is my program

My problems:
I need to rotate the lighting fixtures so that they have the same rotation as the curves in all directions x,y and z.

I would like to join curves that are split by for example a tee connection. One of the problems (atleast for me) here is that Tee connections etc. only have a point in the geometry, not a line, as far as I can see. Also I do not know how to join two lines that have a small separation, ref. images:

How it looks in Revit

I would also like it for the Lighting Fixtures (which is a MagiCAD object) to get a Reference Level when placed. I have not looked very much at this yet, but I’ve found that when I place these objects with dynamo, the Reference Level parameter actually doesn’t seem to exist in the object.

I have had some progression, and I can now place the Lighting Fixtures along Cable Trays with the correct rotation and distance from them in the z-axis.

Now I only need to figure out how to give the Lighting Fixtures a Reference Level value.
For some reason that parameter dissapears from the Lighting Fixture when placed with Dynamo.

Also: I would like to place the points on which the fixtures are placed so that the first and last lighting fixtures are placed closer to each end of the cabletray, and the other fixtures are evenly spread between. Sort of like this:
Where “[” & “]” are each end of the cable tray and “{x}” is a lighting fixture. ("=" is something like a segment length)

Lighting Fixture placed with Dynamo
Lighting Fixture placed manually

This is the program so far:

Hi @andre.abotnes

Refer this post Level Parameter Bug - Read only

Thank you for your reply!

I have now tried the following:
I created the nodes as described in the post, and edited the python script the way i understood it should be made.

I got the following error from the python node:
“Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 24, in
AttributeError: ‘str’ object has no attribute ‘Id’”

Python script:
import clr
from Autodesk.Revit.DB import *

import Revit

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

element = UnwrapElement(IN[0])
ref_level = UnwrapElement(IN[1])
offset = IN[2]


for i,x in enumerate(element):

This is line 24: ref_levelid = ref_level[i].Id

object_param_level = x.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM)

object_level = doc.GetElement(object_param_level.AsElementId())

object_param_offset = x.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM)

object_newoffset = offset[i]



OUT = element

What might be wrong?