How to Use "AssociatedAssemblyInstanceId" in Dynamo

Hello,

Hi everyone, can someone help me with a problem. I want to find views that are associated with my assembys. I want to rename these specific views and not all the assembly views.

how can I do this? I found this “AssociatedAssemblyInstanceId” But I have no idea how to use it

@Niels ,

you can start with this


KR
Andreas

it doesnt work it only gets the assemblys in a view. And I want the specific views of a assembly

Hi,
here 2 solutions

Solution with GetDependentElements


import clr
import sys
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

assembly = UnwrapElement(IN[0])

def get_AssocViews(elem):
	filterElem = ElementClassFilter(clr.GetClrType(DB.View))
	lst_assoc_views_ids = elem.GetDependentElements(filterElem)
	lst_assoc_views = [doc.GetElement(xId) for xId in lst_assoc_views_ids]
	#return [v for v in lst_assoc_views if not isinstance(v, DB.ViewSheet)]
	# OR
	return lst_assoc_views

toList = lambda x : x if hasattr(x, '__iter__') else [x]

#Preparing input from dynamo to revit
lstelems = toList(UnwrapElement(IN[0]))
	
OUT = [get_AssocViews(x) for x in lstelems ]

Solution with AssociatedAssemblyInstanceId

import clr
import sys
import System
from System.Collections.Generic import List
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

assembly = UnwrapElement(IN[0])

def get_AssocViews(assembly):
    filter_v = System.Predicate[System.Object](lambda x : x.AssociatedAssemblyInstanceId == assembly.Id)
    all_instance_view = List[DB.Element](FilteredElementCollector(doc).OfClass(DB.View).WhereElementIsNotElementType().ToElements()).FindAll(filter_v)
    return all_instance_view

toList = lambda x : x if hasattr(x, '__iter__') else [x]

#Preparing input from dynamo to revit
lstelems = toList(UnwrapElement(IN[0]))

OUT = [get_AssocViews(x) for x in lstelems ]
5 Likes

it doest work with mine

image

@Niels ,

try to run it in Ironpython2


KR
Andreas

I had multiple elements instead of one element

@Niels ,

you can implement a function is called IsInstance…

to solve the issue regarding list or single item

KR

Andreas

@Niels

because you have no input object

I updated the codes for a list of input objects

1 Like