# Casting active view

**URL:** <https://forum.dynamobim.com/t/casting-active-view/53714>\
**Category:** Developers\
**Created:** [August 4, 2020, 2:02pm UTC](https://forum.dynamobim.com/t/casting-active-view/53714 "2020-08-04T14:02:20Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [August 4, 2020, 2:02pm UTC](https://forum.dynamobim.com/t/casting-active-view/53714/1 "2020-08-04T14:02:20Z")

</div>

How to cast active view to 3d view in python

DocumentManager.Instance.CurrentDBDocument.ActiveView

---

<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:** [August 4, 2020, 2:06pm UTC](https://forum.dynamobim.com/t/casting-active-view/53714/2 "2020-08-04T14:06:48Z")

</div>

If you’re looking to set the active view check out this post.

> [@Call View to Open](https://forum.dynamobim.com/t/call-view-to-open/17903/3):
>
> I think I actually just figured this out… import clr clr.AddReference("RevitNodes") import Revit clr.ImportExtensions(Revit.GeometryConversion) from Revit.Elements import \* clr.AddReference('System') from System.Collections.Generic import \* clr.AddReference('RevitAPI') from Autodesk.Revit.DB import \* clr.AddReference('RevitServices') import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instanc…

---

<div class="post-metadata">

**Author:** ![FabioDeAgostini](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/fabiodeagostini/32/93820_2.png) [@FabioDeAgostini](https://forum.dynamobim.com/u/FabioDeAgostini)\
**Post date:** [August 4, 2020, 2:33pm UTC](https://forum.dynamobim.com/t/casting-active-view/53714/3 "2020-08-04T14:33:16Z")

</div>

When you unwrap it should enough, because python manage itself casting.  
UnwrapElement( v ) where v is you _Dynamo_ view

---

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [August 5, 2020, 7:45am UTC](https://forum.dynamobim.com/t/casting-active-view/53714/4 "2020-08-05T07:45:46Z")

</div>

Iam accessing the active view directly from the python node … all i need to cast the view in the third parameter in that code line  
ReferenceIntersector(filter, FindReferenceTarget.Face , “the active plan view that i need to be casted into 3d view”), i know that the python do the cast for me but error appears says that “expected View3D , got ViewPlan”

---

<div class="post-metadata">

**Author:** ![FabioDeAgostini](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/fabiodeagostini/32/93820_2.png) [@FabioDeAgostini](https://forum.dynamobim.com/u/FabioDeAgostini)\
**Post date:** [August 5, 2020, 9:08pm UTC](https://forum.dynamobim.com/t/casting-active-view/53714/5 "2020-08-05T21:08:26Z")

</div>

Are you sure that the active view is not a plan?  
It seems so.  
Maybe it was a plan? probably the script need to refresh, try changing something at beginning of script

---

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [August 6, 2020, 5:49am UTC](https://forum.dynamobim.com/t/casting-active-view/53714/6 "2020-08-06T05:49:47Z")

</div>

The active view is a plan not a 3D plan but i want to cast type it to 3D .  
My code is something similar to the code in the picture but in python

 ![Screenshot_20200806-074512_File Commander](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/5/659599e4b87dbf2e9b04a567e627bfc47a6eee43.jpeg)

---

<div class="post-metadata">

**Author:** ![jshial](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jshial/32/91559_2.png) [@jshial](https://forum.dynamobim.com/u/jshial)\
**Post date:** [August 6, 2020, 8:39am UTC](https://forum.dynamobim.com/t/casting-active-view/53714/7 "2020-08-06T08:39:19Z")

</div>

> **[Dynamic Typing vs Static Typing in Python | PrepInsta](https://prepinsta.com/python/dynamic-typing-vs-static-typing-in-python/)**
>
> Dynamic Typing vs Static Typing in Python programming language with comparison and frequently asked questions are available on the above page.

---

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [August 6, 2020, 12:12pm UTC](https://forum.dynamobim.com/t/casting-active-view/53714/8 "2020-08-06T12:12:44Z")

</div>

That means ,it is impossible to cast objects in python?

---

<div class="post-metadata">

**Author:** ![jshial](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jshial/32/91559_2.png) [@jshial](https://forum.dynamobim.com/u/jshial)\
**Post date:** [August 6, 2020, 1:02pm UTC](https://forum.dynamobim.com/t/casting-active-view/53714/9 "2020-08-06T13:02:40Z")

</div>

you don’t need casting for this case. Likewise, for example, **LocationCurve** & **LocationPoint** both derived from **Location** class. But when u code in Python it will just be like **elem.Location.Point** or **elem.Location.Curve**. Whereas in C# it would be like how you did it **( (LocationCurve) elem.Location).Curve**.

---

<div class="post-metadata">

**Author:** ![FabioDeAgostini](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/fabiodeagostini/32/93820_2.png) [@FabioDeAgostini](https://forum.dynamobim.com/u/FabioDeAgostini)\
**Post date:** [August 7, 2020, 6:51am UTC](https://forum.dynamobim.com/t/casting-active-view/53714/10 "2020-08-07T06:51:44Z")

</div>

again, if your error is this

> “expected View3D , got ViewPlan”

the point is not casting the view ( [as I told you](https://forum.dynamobim.com/t/casting-active-view/53714/3) ) but you are feeding a wrong view to the method. I know the ReferenceIntersector and everything run fine from my side.  
If you need a specific help, please post your code snipped at least 🙂

---

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [August 7, 2020, 5:30pm UTC](https://forum.dynamobim.com/t/casting-active-view/53714/11 "2020-08-07T17:30:39Z")

</div>

yeah , i got it know that python make the casting for me , and i really was feeding a wrong view to the method . but here is a new problem , the element is a pipe , i got it’s location (so it curve based) , and i get the end point of this curve , i want to get the hitting point of the element above the end of pipe, but it gives me null however , there is an element from the same category filter above the pipe.

```
    import clr

import System
from System import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

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

doc = DocumentManager.Instance.CurrentDBDocument
view = doc.ActiveView

element = UnwrapElement(IN[1])
geo = element.Location.Curve.EndPoint
vector = XYZ(0,0,1)

kk = Enum.ToObject(BuiltInCategory, IN[0].Id)
filter = ElementCategoryFilter(kk)
refi = ReferenceIntersector(filter, FindReferenceTarget.Face, view)
refc = refi.FindNearest(geo , vector)
reference = refc.GetReference();
intpoint = reference.GlobalPoint

OUT = intpoint
```

---

<div class="post-metadata">

**Author:** ![Daniel\_Woodcock1](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Daniel\_Woodcock1](https://forum.dynamobim.com/u/Daniel_Woodcock1)\
**Post date:** [August 8, 2020, 9:34am UTC](https://forum.dynamobim.com/t/casting-active-view/53714/12 "2020-08-08T09:34:05Z")

</div>

This is unrelated to the question posed and should really have another thread raised (just so other users with a similar question can find the right answer).

However…When doing ray casting, it is sometimes useful to bring the origin back a little. If the point and face are coincident, the ray might not intersect (since they both lie in the same plane this may return null). You could use `Curve.GetPointAtParameter(0.9)` and use this as your origin, this way you ensure that the origin does not lie in the plane of the face.

You should also do a little null checking to avoid warnings should an intersection not be found. Say `if not refc == None:` `OUT = refc.GetReference().GlobalPoint` otherwsie `else: OUT = None`.

Additionally, you should also check if the ActiveView is of type View3D. For example `if doc.ActiveView.ViewType == ViewType.ThreeD:` then perform intersection test, `else: OUT == "Please open a 3D view to run this node"`.

Or you could wrap it all up in a try except and handle errors accordingly.

---

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [August 10, 2020, 1:11pm UTC](https://forum.dynamobim.com/t/casting-active-view/53714/13 "2020-08-10T13:11:17Z")

</div>

Thank you , that’s was very useful for me ,but i can not find GetPointAtParameter() method at revit api document

---

<div class="post-metadata">

**Author:** ![Daniel\_Woodcock1](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Daniel\_Woodcock1](https://forum.dynamobim.com/u/Daniel_Woodcock1)\
**Post date:** [August 10, 2020, 5:24pm UTC](https://forum.dynamobim.com/t/casting-active-view/53714/14 "2020-08-10T17:24:15Z")

</div>

Sorry, my bad, it’s a dynamo method. I see you are purely using Revit API, so Instead use…

`geo.Evaluate(0.9, True)`

This will return an XYZ of 90% along that line. You can play with this value so it is a tighter fit to the endpoint, say 0.95.

---

<div class="post-metadata">

**Author:** ![Daniel\_Woodcock1](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Daniel\_Woodcock1](https://forum.dynamobim.com/u/Daniel_Woodcock1)\
**Post date:** [August 12, 2020, 3:12pm UTC](https://forum.dynamobim.com/t/casting-active-view/53714/15 "2020-08-12T15:12:17Z")

</div>

Hi @eng.elfeky,

Can you mark the post @FabioDeAgostini submitted earlier as the solution as this was actually the correct solution to your original question…

> [@FabioDeAgostini](#):
>
> again, if your error is this
> 
> > “expected View3D , got ViewPlan”
> 
> the point is not casting the view ( [as I told you](https://forum.dynamobim.com/t/casting-active-view/53714/3) ) but you are feeding a wrong view to the method. I know the ReferenceIntersector and everything run fine from my side.  
> If you need a specific help, please post your code snipped at least 🙂

It’s only so when people search for the solution to that specific question they know what was the actual solution. The rest after that is a bonus! 😉
