Selecting Elements by their ID

Hi guys,

I’ve run a search of previous posts but no solution found yet, so here goes:

I’m trying to select several room elements using a list of their Element IDs. I’m using Dynamo 1.2 and the latest release of the archi-lab nodes. The ID to Element node isn’t working when I plug in the list but it does work when I use a simple number node. This looks like a datatype problem, so I’m hoping there the solution here is fairly straightforward?

The output of List.ReplaceItemAtIndex wasn’t working as a valid input for the ID to Element node, so I’ve connected together the String from Object and String to Number nodes to make 100% sure I’m not being an idiot and feeding a non-number into this archi-lab node. Still - no dice!

Any help / pointers would be much appreciated. Thanks for reading!

Ollie

Things just got stranger. I deleted the String.ToNumber node because I know Konrad’s node can take strings as well. But, it’s only recognising a few IDs, not all of them. Again, just to test, I’ve tested the same node against a code block, with a successful result.

Any ideas on why the ID to Element node is being only half-successful?

Just a thought: maybe some of the numbers are doubles? You can check with the ‘Object.Type’ node.

Hi @T_Pover, thanks for the quick response.
I’ve just tried as you suggested and their types are 100% “System.Int32”, so a 32-bit integer.
Hi @Konrad_K_Sobon , does this look odd to you? This is an awesome node package, btw, I use it every day, so thanks for making it! :slight_smile:

You could try upgrading to the latest archi-lab version. It looks like Konrad has replaced the node with this one:

1 Like

That certainly works better - it correctly identifies 2604/3060 rooms in my list.

However, it won’t recognise some particular rooms, which is worrying.
Note: to the right I’ve brought over a watch node from another part of the graph, just to make sure rooms with this ID definitely do exist!

I’m beginning to worry I might have some corrupt room data…

@T_Pover Oh, could it be that this node doesn’t want to list the same room element twice? That might explain why we’re getting most, but not all of the rooms

I would think it would just return double rooms. I can’t take a look under the hood of Konrad’s node, but it should be something like this:

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

ids = IN[0]
	
OUT = [doc.GetElement(x) for x in IN[0]]

if you copy paste that into a python node and input al the integers it should return the rooms you are looking for or return an error message that might give us a bit more insight into what’s going on.

Thanks, T_Pover (taco?) I appreciate the help :slight_smile: Custom Python node returns the following:

Am I giving it the wrong data type? Line 11 is the OUT line

Oops, my bad. It needs elementIds instead of ints. Not at keyboard ATM, I’ll get back to this asap

Try this instead:

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

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

ids = IN[0]

elements = [ElementId(x) for x in ids]
	
OUT = [doc.GetElement(x) for x in elements]

@T_Pover Thanks for the update! Your code is performing exactly the same as Konrad’s :sweat:

Hi @oliver.green

Is it possible for you to drop rvt file here so that we can have closer look at it.

Hi @Kulkul unfortunately that can’t be recommended, it’s a large and relatively unhealthy file. I could potentially upload the Dynamo definition if that would help to clarify how the information is being treated?

@oliver.green Can you show us at least one image showing that room of that id?

@Kulkul Hmm… actually I can’t! “The following Element IDs are invalid and won’t be used: 16059285”.

I can select all of the IDs which @T_Pover 's code / Konrad’s node are finding, but none of the Element IDs which their nodes aren’t finding. Instead I just get that error message…:confused:

This mean that there’s something corrupt with my rooms?

@oliver.green Show us complete screenshot of your graph with there values.

@Kulkul Sorry this is a bit ramshackle, I don’t currently have access to Photoshop.

And here’s the main part of the Python Script being used to extract room data from the doors.

Guys, I think I’ve worked it out - there are several overlapping rooms within the model. Deleting a few of these means the Archi-Lab node and T_Povver’s script can detect a few more room IDs.

Blame it on some dodgy modelling. Thanks for all your help :slight_smile: I very much hope to return the favour some day!

Ollie

1 Like