# List all User Selected Elements to Log File

**URL:** <https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710>\
**Category:** Revit\
**Tags:** dynamo\
**Created:** [July 13, 2018, 5:37pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710 "2018-07-13T17:37:23Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![sobhan.kouhestani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sobhan.kouhestani/32/51312_2.png) [@sobhan.kouhestani](https://forum.dynamobim.com/u/sobhan.kouhestani)\
**Post date:** [July 13, 2018, 5:37pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/1 "2018-07-13T17:37:23Z")

</div>

Hello all,  
I attach the image of my dynamo codes here. I want to extract the IDs of selected elements via dynamo. More specifically, if someone in Revit selects an element to modify it, we can use the code to export its ID in an excel file. (I suppose we need to run it with the automatic run setting). The problem is that “Select Model Elements” node does not work with automatic setting and I should select the elements from dynamo manually.  
\*This will help me to optimize my search algorithm to compare IFC files more effectively.

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/0/502dbcf88a65ab08e169d91b83edb1ab0358ed8e.PNG)

Sincerely,  
Sobhan

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [July 13, 2018, 7:52pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/2 "2018-07-13T19:52:31Z")

</div>

Have you searched the forum for an answer? There are many topics on selecting elements by ID. Such as [Use ID to select objects in Revit](https://forum.dynamobim.com/t/use-id-to-select-objects-in-revit/2738/3)

---

<div class="post-metadata">

**Author:** ![sobhan.kouhestani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sobhan.kouhestani/32/51312_2.png) [@sobhan.kouhestani](https://forum.dynamobim.com/u/sobhan.kouhestani)\
**Post date:** [July 13, 2018, 10:19pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/3 "2018-07-13T22:19:07Z")

</div>

Hello Ewan,  
Thank you for the quick response. I searched the forum, but I didn’t find anything similar to my problem. it is the opposite of the post you have mentioned; in my problem, whenever the designer manually selects an object, Dynamo should return the element ID. I use this piece of code and run it periodically (every 1000ms) and it works for me:

```
import clr
clr.AddReference ( "RevitAPIUI" ) 
from Autodesk.Revit.UI import *

clr.AddReference( "RevitServices " ) 
import RevitServices 
from RevitServices.Persistence import DocumentManager 
doc = DocumentManager.Instance.CurrentDBDocument 
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument 

clr.AddReference("RevitNodes") 
import Revit 
clr.ImportExtensions(Revit.Elements)

sel = uidoc.Selection
obType = Selection.ObjectType.Element
ref = sel.PickObject(obType, "Select Element.")
element = doc.GetElement(ref.ElementId)

OUT = element 

```

However, it causes a problem for the designer; i.e. the revit environment will be always in the selection mode. I attached a picture to exemplify the problem for you (it is always in the selection mode).

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/7/970e9c48032e09d73f7cf5fafdb6b3471b077161.png)

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [July 13, 2018, 11:13pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/4 "2018-07-13T23:13:10Z")

</div>

So you want to essentially run a background process that makes a list of all the elements in the model that are modified by users? And use that list to highlight elements in between IFC model snapshots? Like what Navisworks is able to do but with Dynamo inside the Revit environment? Just clarifying 😀

---

<div class="post-metadata">

**Author:** ![sobhan.kouhestani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sobhan.kouhestani/32/51312_2.png) [@sobhan.kouhestani](https://forum.dynamobim.com/u/sobhan.kouhestani)\
**Post date:** [July 13, 2018, 11:21pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/5 "2018-07-13T23:21:34Z")

</div>

Yesss, that’s exactly it. 😃

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [July 13, 2018, 11:58pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/6 "2018-07-13T23:58:01Z")

</div>

Have a read of this discussion, it points to some intersesting options as well as considerarions for different workflows. Realtime tracking in revit creates a lot of ‘noise’ transaction data, but filtering out the ids would be possible.  
I didn’t end up looking at a macro, but might take a quick look Monday. [How to find who deleted elements](https://forum.dynamobim.com/t/how-to-find-who-deleted-elements/19484/3)

---

<div class="post-metadata">

**Author:** ![sobhan.kouhestani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sobhan.kouhestani/32/51312_2.png) [@sobhan.kouhestani](https://forum.dynamobim.com/u/sobhan.kouhestani)\
**Post date:** [July 15, 2018, 3:26pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/7 "2018-07-15T15:26:31Z")

</div>

The problem is solved; every element which is selected (Realtime tracking) will be shown in dynamo with its timestamp. I attached the code here.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/8/08d1e7b92d7ac8a2ca60eff9dacc2e4a95d0ee3c.png)

[x.dyn](https://forum.dynamobim.com/uploads/short-url/1Msi6GQIZjDVeF6rfedaf9vNNE9.dyn) (2.6 KB)

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [July 15, 2018, 8:47pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/8 "2018-07-15T20:47:56Z")

</div>

👍 Nice Solution @sobhan.kouhestani are you going to combine it with a **Write.To…** node to create a running record? Which format do you think you will use? CSV, TXT, XLS, SQL?

---

<div class="post-metadata">

**Author:** ![sobhan.kouhestani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sobhan.kouhestani/32/51312_2.png) [@sobhan.kouhestani](https://forum.dynamobim.com/u/sobhan.kouhestani)\
**Post date:** [July 16, 2018, 4:41am UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/9 "2018-07-16T04:41:03Z")

</div>

Thanks!  
I am trying to write it into XLS or CSV. Previously, I tried to write data into XLS format (using excel writer node in dynamo), but I could not save different data on the same sheet of the same file; it was erasing the former and saving the latter on it (so I was loosing the former). Also, I tried different things but didn’t work with this node.  
Now, I want to use panda library of python to do this action, however Python node in dynamo doesn’t recognize this category. What’s your suggestion?

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [July 16, 2018, 10:38am UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/10 "2018-07-16T10:38:46Z")

</div>

Have a quick read of this post. I can’t prep a test case using your code till tomorrow but this may give you some ideas on appending the new data. CSV and XLS are where I would be starting also. 👍

> [@Append items to a list of lists](https://forum.dynamobim.com/t/append-items-to-a-list-of-lists/9062):
>
> I thought that was really a simple procedure but I couldn’t find a solution here in the forum. All I want to do is to be able to vary a slider, do some calculations, get a list of values and append it to a “main” list of lists (Which would be initially empty). Then whenever I change the intial values, some calculations will take place, and the output list of values should be appended to the main list. At the end, the list should be copied to a csv file. A very simple script is attached where i…

---

<div class="post-metadata">

**Author:** ![sobhan.kouhestani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sobhan.kouhestani/32/51312_2.png) [@sobhan.kouhestani](https://forum.dynamobim.com/u/sobhan.kouhestani)\
**Post date:** [July 17, 2018, 6:27pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/11 "2018-07-17T18:27:12Z")

</div>

The problem is not solved yet. There is no “passthrough” node in Dynamo, anymore; so, I am trying to use “transaction.start” and “transaction.end” to solve the problem.  
Once It’s solved, I’ll share the code here.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [July 17, 2018, 6:30pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/12 "2018-07-17T18:30:35Z")

</div>

You can write your own passthrough or wait node in a code block. It’s pretty simple.

`{wait,passthrough}[1]`

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [July 17, 2018, 9:32pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/13 "2018-07-17T21:32:44Z")

</div>

Have a go with this @sobhan.kouhestani😉

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/3/d39c837d32f3fbe3f59d5fd39c0149a4115bd7d0.png)

Element Selection Logger Code

```
# Original Script by EwanO 2018 (Sastrugi Package) 
# Use as you like :-)
# This code creates and appends items to a CSV file on the Desktop that
# lists elements fed to the input.

import clr
import System
from System.IO import Directory

import sys
# load python
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

import os

## set the output directory and gather log data
main_dir = 'C:\Users'
user = os.environ.get('USERNAME')
dir = main_dir + '\\' + user + '\\Desktop'

# generate the file name for the log file
eid=(IN[0])
filename = (str("Element_Log" + '.csv'))

# createss the log file (csv) and appends the input data.
fd = open(dir + '\\' + filename,'a')
fd.write(str(eid))
fd.close()

OUT = str("Element Logged")

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/3/3343e0f58d57ff7ba9e9895b785aff9ab0ee8eda.png)

---

<div class="post-metadata">

**Author:** ![sobhan.kouhestani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sobhan.kouhestani/32/51312_2.png) [@sobhan.kouhestani](https://forum.dynamobim.com/u/sobhan.kouhestani)\
**Post date:** [July 17, 2018, 10:33pm UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/14 "2018-07-17T22:33:19Z")

</div>

This code works like a charm…  
Thank you very much Ewan.

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [July 18, 2018, 3:12am UTC](https://forum.dynamobim.com/t/list-all-user-selected-elements-to-log-file/23710/15 "2018-07-18T03:12:52Z")

</div>

Topic renamed to improve forum search results 😀
