# Get Assembly views

**URL:** <https://forum.dynamobim.com/t/get-assembly-views/13939>\
**Category:** Uncategorized\
**Tags:** python\
**Created:** [August 11, 2017, 3:49pm UTC](https://forum.dynamobim.com/t/get-assembly-views/13939 "2017-08-11T15:49:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin.Bell](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kevin.bell/32/22476_2.png) [@Kevin.Bell](https://forum.dynamobim.com/u/Kevin.Bell)\
**Post date:** [August 11, 2017, 3:49pm UTC](https://forum.dynamobim.com/t/get-assembly-views/13939/1 "2017-08-11T15:49:12Z")

</div>

Hi,

I’m looking for a method to obtain the views which are associated with an Assembly.

The way I thought of doing this was to obtain all the Assembly Types, using the AssemblyType Class and then obtain their associated views.

This gets the Assembly Types:

```
allassem = FilteredElementCollector(doc).OfClass(AssemblyType)

#Convert room list to elements
allassemt = allassem.ToElements()

nameslist = []

for f in allassemt:
	param = f.LookupParameter("Type Name")
	nameslist.append(param.AsString())

OUT = [nameslist]

```

But I can’t see that the AssemblyType class has any method of getting the views… Is there a better way to do this?

Thanks.

---

<div class="post-metadata">

**Author:** ![Kevin.Bell](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kevin.bell/32/22476_2.png) [@Kevin.Bell](https://forum.dynamobim.com/u/Kevin.Bell)\
**Post date:** [August 11, 2017, 3:56pm UTC](https://forum.dynamobim.com/t/get-assembly-views/13939/2 "2017-08-11T15:56:17Z")

</div>

OK, worked it out myself:

The ViewPlan class has a method called ‘AssociatedAssemblyInstanceId’ which obtains a views assembly.

That was easy!

---

<div class="post-metadata">

**Author:** ![Wuillian\_Medrano](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/wuillian_medrano/32/11074_2.png) [@Wuillian\_Medrano](https://forum.dynamobim.com/u/Wuillian_Medrano)\
**Post date:** [August 12, 2017, 4:30am UTC](https://forum.dynamobim.com/t/get-assembly-views/13939/3 "2017-08-12T04:30:20Z")

</div>

can you elaborate on this, not verse on python, but could really use this on some assembly graphs i use.

---

<div class="post-metadata">

**Author:** ![Kevin.Bell](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kevin.bell/32/22476_2.png) [@Kevin.Bell](https://forum.dynamobim.com/u/Kevin.Bell)\
**Post date:** [August 15, 2017, 1:00pm UTC](https://forum.dynamobim.com/t/get-assembly-views/13939/4 "2017-08-15T13:00:48Z")

</div>

Wuillian, this is the routine I produced, I’m unsure if it does what you want though - it renames all Assembly 3D views to match the Assembly name:

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

# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit

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

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

# Import Revit elements
from Revit.Elements import *

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

import sys
sys.path.append('C:/Program Files (x86)/IronPython 2.7/Lib')
import random

import System

import time

starttime = time.clock()

from math import atan2, radians, cos, sin, degrees, sqrt, ceil

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
adoc = doc.ActiveView

#Variables

# allviews = A FEC of the View Class
# allviewsel	= A FEC of the View Class converted to Elements
# vgettype = States what type of view the view is - GetType
# vgettos = The views 'Title on Sheet' parameter <<< NOT USED
# axolist = A list of axonometric assembly views
# axoassocassem = A list of assemblys associated to the axolist views
# assnames = A list of assembly names
# donerename	= A counter which records if a rename has happened
# faillist = A counter which records if any renames have failed

#User message
TaskDialog.Show("Rename Assembly Axonometric Views", "This routine will rename all Assembly Axonometric views names to match the Assembly name.")

#Create FEC of views within database
allviews = FilteredElementCollector(doc).OfClass(View)

#Convert room list to elements
allviewel = allviews.ToElements()

#Get list of assembly axo views
axolist	= []
for f in allviewel:
	#vgettos = f.LookupParameter("Title on Sheet")
	if f.GetType() == View3D and f.IsAssemblyView == True:
		axolist.append(f)

#Get list of assemblys related to the assembly axo views
axoassocassem = []
for f in axolist:
	axoassocassem.append(f.AssociatedAssemblyInstanceId.IntegerValue)

#Get list of assembly names
assnames = []
for f in axoassocassem:
	ele = ElementId(f)
	elefromdb = doc.GetElement(ele)
	asstype = elefromdb.LookupParameter("Type").AsElementId() 
	assnameele = doc.GetElement(asstype)
	assnames.append(assnameele.LookupParameter("Type Name").AsString())

#Rename axo view names to match assembly name
faillist = 0
donerename = 0
TransactionManager.Instance.EnsureInTransaction(doc)
for f in range(len(axolist)):
	if axolist[f].Name != assnames[f]:
		donerename += 1
		try:
			axolist[f].Name = assnames[f]
		except:
			faillist += 1
TransactionManager.Instance.TransactionTaskDone()

#User message
finalmessage = "Found " + str(len(axolist)) + " Assembly axonometric views\n\n" + "Renamed " + str(donerename) + " Assembly views\n\n" + str(faillist) + " Rename failures"
TaskDialog.Show("Rename Assembly Axonometric Views", finalmessage)

OUT = [axolist, axoassocassem, assnames, donerename, faillist]
```

---

<div class="post-metadata">

**Author:** ![Wuillian\_Medrano](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/wuillian_medrano/32/11074_2.png) [@Wuillian\_Medrano](https://forum.dynamobim.com/u/Wuillian_Medrano)\
**Post date:** [August 15, 2017, 4:15pm UTC](https://forum.dynamobim.com/t/get-assembly-views/13939/5 "2017-08-15T16:15:31Z")

</div>

I was looking for just filtering the assembly Views, so that I can apply a view template. So far I filter all detail views which includes some plan, section views. Can I chop this code down to use to identify all associated assembly views?

---

<div class="post-metadata">

**Author:** ![Kevin.Bell](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kevin.bell/32/22476_2.png) [@Kevin.Bell](https://forum.dynamobim.com/u/Kevin.Bell)\
**Post date:** [August 15, 2017, 7:21pm UTC](https://forum.dynamobim.com/t/get-assembly-views/13939/6 "2017-08-15T19:21:37Z")

</div>

Yes you can always play around with code - its a good way of learning how it works.

Be sure to look at the API help which will explain what each bit does (use the search).

[http://www.revitapidocs.com/](http://www.revitapidocs.com/)

---

<div class="post-metadata">

**Author:** ![patrick\_podeyn](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/patrick_podeyn/32/86368_2.png) [@patrick\_podeyn](https://forum.dynamobim.com/u/patrick_podeyn)\
**Post date:** [December 21, 2018, 4:50pm UTC](https://forum.dynamobim.com/t/get-assembly-views/13939/7 "2018-12-21T16:50:11Z")

</div>

Thank you so much for this! Manipulated the code a bit to add the assembly name to the end of my detail view. Many thank yous again!

---

<div class="post-metadata">

**Author:** ![RAugustine](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@RAugustine](https://forum.dynamobim.com/u/RAugustine)\
**Post date:** [December 8, 2022, 4:00am UTC](https://forum.dynamobim.com/t/get-assembly-views/13939/8 "2022-12-08T04:00:54Z")

</div>

I know this is a really old post, but this helped me out so much. I was able to manipulate the code to get my Sheet, Detail Views are original 3D Ortho Views converted to AutoCAD during our Revit conversion! Sooooo helpful!!

---

<div class="post-metadata">

**Author:** ![nburr3551](https://avatars.discourse-cdn.com/v4/letter/n/bbce88/32.png) [@nburr3551](https://forum.dynamobim.com/u/nburr3551)\
**Post date:** [January 16, 2025, 12:33am UTC](https://forum.dynamobim.com/t/get-assembly-views/13939/9 "2025-01-16T00:33:11Z")

</div>

I have used this code for quite awhile. In updating to 2025 the code no longer collects any views in python 3. I ran the automatic update to update the python code but not sure what needs to be modified on the assembly view collection code.
