Selecting Levels by Name

Hi there,

I have one question regarding Levels in Dynamo.

I have a script, creating (depending on parameters) different Levels.

e.g.:

OK_A

OK_B1

OK_B2

OK_B3

OK_C1

OK_C2

now the Levels OK_B1-3 may vary if they are implemented or not. Leaving a possible minimum of:

OK_A

OK_B1

OK_C1

OK_C2

so far so good.

Now in my next step I want to create columns using these levels. This is where my question is located. Is there a way to creat a Code Block with e.g. “OK_B1” as a fixed term for the level OK_B1? Because if I run the script creating only one B the transition von B to C wont work without opening the script selecting the right level in the list…

I want to creat a list with levels (by using CodeBlocks with fiexed names), kicking null values out of the list and add the last valid value on top of OK_C1.

Thank you in advance.

I hope I could state my problem properly :wink:

Kind regards
Timur

You could do this with Python as below, or just use Level.ByName from the WombatDynamo package.

image

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

#Preparing input from dynamo to revit
run = IN[0]
name = IN[1]

#Do some action in a Transaction

if run:
	fec = FilteredElementCollector(doc).OfClass(Level).ToElements()
	for l in fec:
		if l.Name == name:
			OUT = l
else:
	OUT = "Set Run to True"

You can also achieve this using out-of-the-box-nodes!

User_Chosen_Levels.dyn (18.2 KB)

1 Like

And I just noticed that you tagged in DesignScript, so here is that version too :slight_smile:

User_Chosen_Levels_DesignScript.dyn (9.6 KB)

2 Likes

Hey there,

@SeanP the Python script does the job! :slight_smile:

One Question, do I have to set it up like this if I want to collect all levels? Or can I get along with one Python script block somehow??

@solamour
this method looks interessting aswell. My problem here is, that I don’t get the Code Block bottom left [“LEvel 2”… ]; to work. It won’t turn active.

Thanks a lot!

@solamour
this method looks interessting aswell. My problem here is, that I don’t get the Code Block bottom left [“LEvel 2”… ]; to work. It won’t turn active.

Simply replace the "Level 2" orange text with your Level names :slight_smile: Such as "OK_FT4"!

In the code block I use a square brace [ to start a List, and on the next line I use a String (Text) of each Level name (In my file: it was “Level 2” etc.), followed by a comma to finish the line. You an have as many lines as you wish, with the final line not having a comma. To end the List I finish with a square brace ] and to end the code block’s… block of code (hah… weird to type this!), you use a semi-colon ;.

I did that :wink: but it looks like this:

It would need to be modified a little to make it work on a List if you are wanting to give it multiple Level names.

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

#Preparing input from dynamo to revit
run = IN[0]
names = IN[1]

#Do some action in a Transaction
levels = []

if run:
	fec = FilteredElementCollector(doc).OfClass(Level).ToElements()

	for l in fec:
		for n in names:
			if l.Name == n:
				levels.Add(l)
	OUT = levels
else:
	OUT = "Set Run to True"

1 Like

Which version of Dynamo are you in? If it’s before Dynamo 2.0 please try replacing the square braces [ ] with curley ones { }.

1 Like

@solamour thats the point. :slight_smile:

ok so both ways working just fine! Any idea which one of those uses less RAM?

my script is getting quite big already so I try to save everywhere I can.

1 Like

To use the least RAM you can take either ZeroTouch (C# Custom Nodes) or Python - In both cases you will want to not return intermediate objects to the graph :slight_smile:

For example - if you are building an array of points, then offsetting those points upwards, creating a line and then creating a cone from that line this is a lot of Geometry being held in memory. If you use Nodes, each step will be present in their respective nodes. If you use either method above (ZT or Python) and Dispose() of the geometry inside - simply returning only the cone, then all the other geometrical elements will not be held in RAM.

This is most noticeable with either large data-sets, or Geometry. For your workflow above it’s pretty negligible.