# How to set temporary view?

**URL:** <https://forum.dynamobim.com/t/how-to-set-temporary-view/91015>\
**Category:** Developers\
**Tags:** python\
**Created:** [June 22, 2023, 10:01am UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015 "2023-06-22T10:01:50Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [June 22, 2023, 10:01am UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/1 "2023-06-22T10:01:50Z")

</div>

Hello,

i want to set temporary view on/ off but how

```auto
import clr
import sys

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

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

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

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

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

v = doc.ActiveView;
v.EnableTemporaryViewPropertiesMode(v.Id);

OUT = "done"

```

> **[EnableTemporaryViewPropertiesMode Method](https://www.revitapidocs.com/2015/89d71e79-0770-b235-db89-80b80dd331af.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

… and disable…

KR

Andreas

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [June 22, 2023, 12:07pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/2 "2023-06-22T12:07:32Z")

</div>

… i solved it partly

```auto
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

clr.AddReference("RevitServices")
import RevitServices

from RevitServices.Persistence import *
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
vId = UnwrapElement(doc.ActiveView.ToDSType(True))

TransactionManager.Instance.EnsureInTransaction(doc)
doc.ActiveView.EnableTemporaryViewPropertiesMode(vId.Id)
TransactionManager.Instance.TransactionTaskDone()

OUT = vId

```

how can i swich between on and off ?

KR

Andreas

---

<div class="post-metadata">

**Author:** ![Joelmick](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/joelmick/32/93148_2.png) [@Joelmick](https://forum.dynamobim.com/u/Joelmick)\
**Post date:** [June 22, 2023, 12:17pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/3 "2023-06-22T12:17:12Z")

</div>

You should provide the View Template Id.  
As stated in the Documentation.

Turning the Temp view state off again is a little different.

[https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/c/4cf77c38775f080792b6fe8078e0d3f152ca1ff0.mp4](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/c/4cf77c38775f080792b6fe8078e0d3f152ca1ff0.mp4)

---

<div class="post-metadata">

**Author:** ![Joelmick](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/joelmick/32/93148_2.png) [@Joelmick](https://forum.dynamobim.com/u/Joelmick)\
**Post date:** [June 22, 2023, 12:17pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/4 "2023-06-22T12:17:26Z")

</div>

![Schermafbeelding 2023-06-22 141622](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/0/f085665c2d3d888c0867f3bb3192951edad66c65.png)

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [June 22, 2023, 12:20pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/5 "2023-06-22T12:20:12Z")

</div>

@Joelmick ,

it is driven by a boolean…

is there not a solution like a lightswitch ?

each run is true → false → true …

KR

Andreas

---

<div class="post-metadata">

**Author:** ![Joelmick](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/joelmick/32/93148_2.png) [@Joelmick](https://forum.dynamobim.com/u/Joelmick)\
**Post date:** [June 22, 2023, 12:24pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/6 "2023-06-22T12:24:33Z")

</div>

you mean like this?

[https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/0/409639789972440f30b7f4ac03acd04e646a6179.mp4](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/0/409639789972440f30b7f4ac03acd04e646a6179.mp4)

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [June 22, 2023, 12:26pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/7 "2023-06-22T12:26:32Z")

</div>

@Joelmick ,

yes it is a “one” click solution

background is that i want to create button (on/off)

f.e. shortcuts work in this way for temporary view i have TT i can with TT go on/off

KR

Andreas

---

<div class="post-metadata">

**Author:** ![Joelmick](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/joelmick/32/93148_2.png) [@Joelmick](https://forum.dynamobim.com/u/Joelmick)\
**Post date:** [June 22, 2023, 12:30pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/8 "2023-06-22T12:30:14Z")

</div>

I do not understand what you are trying to do?

You want to create a button and when you click it, the view should be in Temporary properties mode.  
Then when you click it again it should be normal?

Keep in mind that, when I click the my python node, this is only to re-execute Dynamo.

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [June 22, 2023, 12:34pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/9 "2023-06-22T12:34:00Z")

</div>

@Joelmick ,

yes exactly… like a light switch…

on/off just by one click

KR

Andreas

---

<div class="post-metadata">

**Author:** ![Joelmick](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/joelmick/32/93148_2.png) [@Joelmick](https://forum.dynamobim.com/u/Joelmick)\
**Post date:** [June 22, 2023, 12:40pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/10 "2023-06-22T12:40:30Z")

</div>

You are aware that this is already a button in Revit right?

You can assign a short key to it.

[https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/5/0513c33beb0e0ce4a126ec0c3da73c8afa0a9181.mp4](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/5/0513c33beb0e0ce4a126ec0c3da73c8afa0a9181.mp4)

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [June 22, 2023, 12:40pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/11 "2023-06-22T12:40:35Z")

</div>

@Joelmick ,

is this code correct ? it makes nothing

```auto
import clr
import sys

import System

clr.AddReference("System")
from System import *

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

clr.AddReference("RevitServices")
import RevitServices

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

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

from RevitServices.Persistence import *
from RevitServices.Transactions import TransactionManager

bool = IN[0]

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

TransactionManager.Instance.EnsureInTransaction(doc)

activeView = doc.ActiveView
viewTemplateId = activeView.ViewTemplateId

if viewTemplateId != ElementId.InvalidElementId:

	if bool:
		activeView.EnableTemporaryViewPropertiesMode(viewTemplateId)

	else:
		activeView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryViewProperties)
	
TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = "Temporary View"

```

if the single button is not possible… i can create a window with a button on off like  
 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/5/d5979004c10562ea7c23598704a6b55e06990900.png)

---

<div class="post-metadata">

**Author:** ![Joelmick](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/joelmick/32/93148_2.png) [@Joelmick](https://forum.dynamobim.com/u/Joelmick)\
**Post date:** [June 22, 2023, 12:43pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/12 "2023-06-22T12:43:18Z")

</div>

Your code is correct, but your view does not have a view template.

The whole Idea of the Temp View props function is that you apply view properties of a certain view template to you view temporarly. If your view does not have a view tempate, the code does not know which view template you need

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [June 22, 2023, 12:45pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/13 "2023-06-22T12:45:46Z")

</div>

@Joelmick ,

thats right! thanks…

thats mostly the case to have a template

---

<div class="post-metadata">

**Author:** ![Joelmick](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/joelmick/32/93148_2.png) [@Joelmick](https://forum.dynamobim.com/u/Joelmick)\
**Post date:** [June 22, 2023, 12:47pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/14 "2023-06-22T12:47:27Z")

</div>

So is this now resolved? and which of the posts is the solution?

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [June 22, 2023, 12:53pm UTC](https://forum.dynamobim.com/t/how-to-set-temporary-view/91015/15 "2023-06-22T12:53:48Z")

</div>

@Joelmick ,

the next step is to connect it with view settings f.e. highlight roumbounderies, or planregions a.s. o.

Thank you

KR

Andreas
