Placing Lighting Fixtures along Cable trays

Hello

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:
1.
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:
Dynamo:

Revit:
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:
[={x}==={x}==={x}==={x}=]
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 - #7 by SimonG

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
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB 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

doc = DocumentManager.Instance.CurrentDBDocument

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

TransactionManager.Instance.EnsureInTransaction(doc)

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]

object_param_level.Set(ref_levelid)
object_param_offset.Set(object_newoffset)

TransactionManager.Instance.TransactionTaskDone()

OUT = element


What might be wrong?