Assign shared parameter automatically to a list

Hi all,

I have a task at hand that I will try to simplify. Basically I have 2 lists that I want to iterate on and only if a certain criteria is met I want to assign a value to a shared parameter.

List1 has sharedParam1 & sharedParam2
List2 has sharedParam3 & sharedParam4.

And only if:

          if item1[sharedParam1] == item2[sharedParam2]:

            item2[sharedParam4] = item1[sharedParam3]

the shared parameter would be assigned to the other item of the list.

I don’t know if my inputs are incorrect or the script itself. Appreciate any help.

Thank you!

Dynamo script:

Load the Python Standard and DesignScript Libraries

import sys
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

The inputs to this node will be stored as a list in the IN variables.

dataEnteringNode = IN

List with the region fills that have an assigned “Unit_number”.

list1 = IN[0]

List with the rooms that have an assigned “Room_unit”.

list2 = IN[1]

The region fill “Unit_number” shared parameter for the individual region fill areas per room.

sharedParam1 = IN[2]

The room “Room_number” shared parameter for the individual rooms.

They are placed on the 1/4" and 1/8" plans as Unit tags.

sharedParam2 = IN[3]

The area from “Region_fill_area” shared parameter for the individual region fill per room.

sharedParam3 = IN[4]

The area from “Room_leasable_area” shared parameter for the individual rooms.

They are placed on the 1/4" and 1/8" plans as Unit tags.

sharedParam4 = IN[5]

Place your code below this line

def UpdateSharedParameter(list1, list2, sharedParam1, sharedParam2, sharedParam3, sharedParam4):
for item1 in list1:
for item2 in list2:
if item1[sharedParam1] == item2[sharedParam2]:
item2[sharedParam4] = item1[sharedParam3]

Example usage

UpdateSharedParameter(list1, list2, sharedParam1, sharedParam2, sharedParam3, sharedParam4)

Assign your output to the OUT variable.

OUT = list2

Please post any code as preformatted text (</>), otherwise the formatting is lost and we can’t follow your code.

It’s hard to tell exactly what your list structure is and how your logic should play out but it definitely sounds doable. You may be able to simplify this with a dictionary (if the condition is based on matching and not specific pairs), otherwise it’s just index matching. We’ll be able to give you more information once you provide some more context.

@Nick_Boyts ,

Sorry I can’t attach a file since I am a new user. Please see the snip attached. This script works but only if the rooms have been created in a particular order so for example from room 1627 to 1630 incrementally. Otherwise the script just fails.

I want to create a better filter so that only items wit ha particular value on a shared parameter get to be picked up.

In order to help you, we need you to provide the appropriate information.

If you’re posting code it needs to be as preformatted text.
image

If you’re posting a screenshot it needs to include the node preview bubbles.
image

From the looks of it you need to match your detail items with your rooms. Right now you just pull them in arbitrary order, but I assume each room has an associated detail item that it needs to get paired up with. How are these two objects related? Is this the idea behind the python code? We need to understand your full process in order to help you identify where the problem actually lies.

Hi @Nick_Boyts ,

Thank you for the suggestion. As I said I am new so I appreciate your patience. I will try to explain it in more detail.

I have created a region fill and 2 shared parameters for the region fill which are “Unit_number” and a parameter that is basically Area overridden so that I get the areas of the rooms on to which I am placing these region fills. We need a very precise SF for the units and the region fills are placed in a working view.

All this info above is on the background, being that I need this info to get into the Room tags that are placed on our 1/4" & 1/8" floor plans. I created 2 new shared parameters for Room as well which basically mimics the “Unit_number” in this case is the “Room_unit” and the “Room_leasable_area” which is a shared parameter the value of which I need to be same as the region fill’s above.

I have to manually input the values for the “Unit_number” and “Room_unit” which isn’t a problem since this way I can control it and it will change during the projects life. And I want to have the list of the rooms created by List.FilterByBoolMask to filter them through the “Room_unit” value so 1627, 1628, 1629 and not from the way I have created the rooms.

There are other people in the model so I can’t control the room creation process which needs to be in order for it to work. This is why I need a way to filter the resulting list from both the Region fills and the rooms so that they are paired correctly and I am sure that the SF from the region fill is transcribed to the room with the same shared parameter for example 1627.

Also, I have an already created script that gets the region fill area and transcribes this to the appropriate shared parameter for the area on the region fills. So what you see attached is the second part of the process I am trying to automate. I can probably merge them at one point but first I want to make sure that they work.

Summary: I want to know how can I use a shared parameter as a filter so that I create a list with the appropriate order.

Thank you!

So if I understand correctly, Unit_number and Room_unit are what tie your filled regions to your rooms. You want to filter the rooms based on the filled region Unit_number so that you can transfer values between the two.

There are a ton of topics on the forum that cover filtering / matching values across two disparate lists. The idea is pretty straight forward: Filter each Room based on its Room_unit value as compared to each Unit_number (using list levels). You use the parameter values in the conditional statement but then filter the rooms. This will result in a sublist for each filled region. If you only have one room per filled region then you can flatten the list to have matching lists, but you don’t have to since the structure is still aligned.

1 Like

Hi @Nick_Boyts ,

Pretty much. So the shared parameter for the unit number will be inputted manually for the filled regions and the room. Maybe I could’ve used only 1 shared parameter but it was more straight forward and gives us more wiggle room when placing the rooms.

I will read carefully on what you responded since I need time to digest it. But just to summarize I am trying to create a filter so that the rooms and region fills are in a list sorted so that their number is incrementally increasing, This would mean that the appropriate area from the region fill would be assigned to the actual room.

What is happening now is that for example from 4 rooms I am deleting the 3rd and then replacing it again. This is screwing with the script so whatever is coming down the line is just incorrect. Only the 1st and 2nd room are getting the appropriate areas assigned to their shared parameter. The list picking up the rooms is going from 1,2,3,4 to 1,2,4,3 since the 3rd room’s ID is probably newer and hence it is being placed on the bottom. This was just a test I did on a new project.

Will reply when I get the time to get into it.

Nonetheless, I appreciate your time and effort!