Isolate Elements in View, how?

Hello,

I am almost done!

import clr

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

#Preparing input from dynamo to revit
elements = UnwrapElement(IN[0])
view = UnwrapElement(IN[1])
ActiveView = FilteredElementCollector(doc,doc.view.Id)
isoElems = []

for items in elements:
	isoElems.append(items.Id)
	

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
view.IsolateElementsTemporary(isoElems)
TransactionManager.Instance.TransactionTaskDone()

OUT = "Done!"

How can I say, do the task in “this” view?

KR

Andreas

replace this line

by this
ActiveView = FilteredElementCollector(doc,view.Id)
or delete it if not necessary

1 Like

2022-02-17_10h17_16
still remains something.

:slight_smile: what is the difference between a list and collection!?

A list is a pure Python Object, a ICollection is a .Net object (embedded by IronPython in your case), and IsolateElementsTemporary need a .Net Collection

try this

isoElems = List[ElementId]()

for item in elements:
	isoElems.Add(item.Id)
2 Likes

that means i need ironpython libraries too?

Actully when i use append,… is there a differnt syntex?

Because ElementId does not exist, i would rather use a as a basket.

import sys
import clr
sys.path.append(r'C:\\Program Files (x86)\\IronPython 2.7\\Lib')

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

#Preparing input from dynamo to revit
elements = UnwrapElement(IN[0])
view = UnwrapElement(IN[1])
ActiveView = FilteredElementCollector(doc,view.Id)
isoElems = List[ElementId]()

for item in elements:
	isoElems.Add(item.Id)
	

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
view.IsolateElementsTemporary(isoElems)
TransactionManager.Instance.TransactionTaskDone()

OUT = "Done!"

it works this way! Thank you

1 Like

It’s to define the type of .Net Collection
read this
https://ironpython.net/documentation/dotnet/dotnet.html#accessing-generic-types

1 Like