# Asign Active Workset

**URL:** <https://forum.dynamobim.com/t/asign-active-workset/80319>\
**Category:** Developers\
**Tags:** dynamo\
**Created:** [August 25, 2022, 1:50pm UTC](https://forum.dynamobim.com/t/asign-active-workset/80319 "2022-08-25T13:50:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsrBIM](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@dsrBIM](https://forum.dynamobim.com/u/dsrBIM)\
**Post date:** [August 25, 2022, 1:50pm UTC](https://forum.dynamobim.com/t/asign-active-workset/80319/1 "2022-08-25T13:50:47Z")

</div>

Hi, I would Like to know if there is a way to set Dynamo as an Active Workset.

I was looking I could see that there is an option with the Id of the Workset but I can not find a Node or a method in python to do it, Thank you.

I would like to control it for future Scripts for my Team, If I can get access to the data about the Workset that is assigned .

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

---

<div class="post-metadata">

**Author:** ![GavinNicholls](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gavinnicholls/32/190442_2.png) [@GavinNicholls](https://forum.dynamobim.com/u/GavinNicholls)\
**Post date:** [August 25, 2022, 1:56pm UTC](https://forum.dynamobim.com/t/asign-active-workset/80319/2 "2022-08-25T13:56:36Z")

</div>

Yes you can get the worksettable from the active document, then set the workset that is active by Id:

Method to get workset table from document:

> **[GetWorksetTable Method](https://www.revitapidocs.com/2022/b02ace6c-4643-cea6-9545-ea41822731f3.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

Method to set active workset by id for worksettable:

> **[SetActiveWorksetId Method](https://www.revitapidocs.com/2022/9f11d796-ca5c-93d9-51e1-67cf8da9baf2.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

The same, but to get the workset:

> **[GetActiveWorksetId Method](https://www.revitapidocs.com/2022/4755e6d9-c31c-32cc-7cf5-aac19dc12dff.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

---

<div class="post-metadata">

**Author:** ![dsrBIM](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@dsrBIM](https://forum.dynamobim.com/u/dsrBIM)\
**Post date:** [August 25, 2022, 2:03pm UTC](https://forum.dynamobim.com/t/asign-active-workset/80319/3 "2022-08-25T14:03:21Z")

</div>

> [@GavinNicholls](#):
>
> Method to get workset table from document:

Thank you GavinCrump, It is a good Started 😁

---

<div class="post-metadata">

**Author:** ![GavinNicholls](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gavinnicholls/32/190442_2.png) [@GavinNicholls](https://forum.dynamobim.com/u/GavinNicholls)\
**Post date:** [August 25, 2022, 2:29pm UTC](https://forum.dynamobim.com/t/asign-active-workset/80319/4 "2022-08-25T14:29:58Z")

</div>

Here’s the code to set it as well, had to get to a computer…

```auto
# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au

# Boilerplate text
import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

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

# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

# Get the workset as input
ws = IN[0]

# Get workset table
table = doc.GetWorksetTable()

# Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

# Try to set the workset
try:
	table.SetActiveWorksetId(ws.Id)
	OUT = True
except:
	OUT = False

TransactionManager.Instance.TransactionTaskDone()

```

[set workset.dyn](https://forum.dynamobim.com/uploads/short-url/sZct1V8ltUwUdf1RMvX1U6uyru1.dyn) (11.3 KB)

 ![set workset](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/b/fbdfba20433925d08d33a68229ffe73d219fb063.png)

---

<div class="post-metadata">

**Author:** ![dsrBIM](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@dsrBIM](https://forum.dynamobim.com/u/dsrBIM)\
**Post date:** [August 25, 2022, 3:07pm UTC](https://forum.dynamobim.com/t/asign-active-workset/80319/5 "2022-08-25T15:07:06Z")

</div>

That is Perfect it is what I wanted.Now I can continue with my Script, the goal of it is to bring it to C# to the macro editor.

But I do not know exactly do the macro run when I open a file(Just what I can do it when I open Revit, close or run a macro ), I want that the macro editor set a workset depending on the user name (all this is controlled ).

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

I wanted to add a Module as the Module \_Startup but I tried to do the same in the Internal Startup adding the Initialize method.

Is something that you can help or should I open a new topic?

Thank you Very much in advance

---

<div class="post-metadata">

**Author:** ![GavinNicholls](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gavinnicholls/32/190442_2.png) [@GavinNicholls](https://forum.dynamobim.com/u/GavinNicholls)\
**Post date:** [August 25, 2022, 10:32pm UTC](https://forum.dynamobim.com/t/asign-active-workset/80319/6 "2022-08-25T22:32:59Z")

</div>

That’s one to ask over on the revit forums.
