Get Assembly views




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")

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?


Assembly-How to get all view already created

OK, worked it out myself:

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

That was easy!


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


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
from Autodesk.DesignScript.Geometry import *

# Import RevitNodes
import Revit

import Autodesk
from Autodesk.Revit.DB import *

from Autodesk.Revit.UI import *

# Import Revit elements
from Revit.Elements import *

# Import DocumentManager
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


# 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:

#Get list of assemblys related to the assembly axo views
axoassocassem = []
for f in axolist:

#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
for f in range(len(axolist)):
	if axolist[f].Name != assnames[f]:
		donerename += 1
			axolist[f].Name = assnames[f]
			faillist += 1

#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]


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?


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).