Sorting List of elements to correspond with another list of elements

Hello all I need some help here, heres what I’m trying to accomplish.

For this specific project we have been having a problem where our lights won’t move with what we have copy monitored. All of our lights are off by a hair and the architect is bugging us about it. I’m trying to make a script to automate this for us in case of problems like this in the future.

Here was my way of approaching.

  1. Get lights from linked model and our model.
  2. Get the locations of the lights.
  3. Match the corresponding copy monitored light with the architect’s light location.
  4. Move the light to that location.

The main problem I am running in to is making a light from our model move to the correct location from link. For example its a list of 100 lights, number 8 on our model list is in room “A” but number 8 on the linked model list is in room “B”.

If anyone has any insight please let me know.

I know there is problably some other ways of doing this which my other thought was to get the list of points from each light and get it to move to the nearest point (since they are only off by a few inches). I’m not too great with geometry so if anyone has insight on that.

(I’ve tried sorting by sortbykey but couldn’t get it to work, I could’ve been doing it wrong because I’m not too great at sorting list.)

How are you identifying which lights correspond to which linked elements? If you can’t define how they’re supposed to be related then you create that relationship. Unfortunately Copy/Monitor doesn’t track any actual element data, so you can’t get it from that relationship. Do the lights have matching labels between models? A Mark value or anything like that? If not, then you’d have to do a geometry comparison, which can be pretty computationally heavy and require quite a few assumptions.

No mark value or anything like that to identify. I was going to go the geometry route and get the point of each light and try and make them correspond by whichever point from list A is closest to whichever point from list B. But I also thought once I do get the points to correspond how am i suppose to get the element again.

Rather than reorder your list of points/elements to match the linked elements, you can reorder the linked points to match your list. Then you don’t have to do any re-mapping of points to elements as your list will be unchanged.

  1. Find the closest point from the list of linked fixtures to your list of light locations.
  2. Get the vector from your point to the corresponding link point.
  3. Move your element along that vector.

That’s what im struggling with.

  1. How do I get the closest point from the list of linked fixtures to the list of my light locations?

I’m not sure how to sort that list other than by sort natural so its smallest to greatest (on linked side) then do the same with my lights.

The other problem I’m now running into (could be easier to solve). The way i’m getting my light fixtures gets them as family instances, so i’m getting an error when trying to use a node that moves an ‘element’.

You can use Geometry.DistanceTo to get the distance to every point and then sort those points by distance (SortByKey). Then you just take the first point in each sublist (the point with the lowest distance to your fixture) and that should represent the corresponding linked element - assuming that the closest fixture is the copy/monitored one.

You’ll have to show us what you’re doing there. As long as your fixtures aren’t constrained, they should work with that node.

image

I fixed the error, the list.sortnatural was throwing it off.

You need to get and sort the distance, not the point. You won’t be able to sort points.

Sorry im really struggling with this. I’m very bad with geometry. I have my distances but isn’t it getting a distance from say list A,0 to list B,0? Since my distances are so far it can lead me to believe that the points i’m comparing aren’t corresponding because they should all be less than 6 inches away.

I would also like to include that I stumbled upon this node and set it up accordingly

Unfortunately I can’t get it to work properly.

You need to correct your list structure first. Your lights are in a single list but the linked lights are a list of a list; Flatten them into a single list. Then you can use list levels (@L1) to force each of your points to get the distance to every one of the linked points. Then you can sort the distances/points in each sublist using SortByKey.

EDIT: That node could be helpful but I’m not familiar with it. I’m guessing you still need to fix your list structure.

Sorry I don’t have a great understanding around list levels. Please elaborate / help

I suggest you work your way through the Dynamo Primer to get a better understanding of some of the basics. List structure and the utilization of list levels will make everything a lot easier.

You want to match the list level to the structure that you want your node logic to correlate to. In this case, one item (@L1) to one list (default, no list levels) for the distance.