Dear Developers,
I was wondering how we can manage to select all elements by input values by using python script:
- element category
and - if element is at workset which is open
I am totally new in python and looking forward your support.
Thanks.
Dear Developers,
I was wondering how we can manage to select all elements by input values by using python script:
@kvusal .
check out this:
'''
GET ALL USER CREATED WORKSETS
'''
__author__ = 'min.naung/mgjean @https://twentytwo.space/contact'
__twitter__ = '@_mgjean'
__version__ ='1.0.0'
# dynamo version - 1.3.2
# import common language runtime
import clr
# clr.AddReference loads and imports .net assembly(dll) as python module
# load RevitAPI.dll and RevitServices.dll
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")
# import all classes from Revit DB
from Autodesk.Revit.DB import FilteredWorksetCollector,WorksetKind
# import document manager
from RevitServices.Persistence import DocumentManager
# import transaction manager
from RevitServices.Transactions import TransactionManager
# instantiate current document
doc = DocumentManager.Instance.CurrentDBDocument
# collect user created worksets
worksets = FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset).ToWorksets()
# return list structure [[name,workset],[]...[]]
OUT = [[i.Name,i] for i in worksets]
it does not solve the opened one! but it is a starting point!
Your question is unclear, reading it as wanting elements in the active (open) workset. Pretty sure to identify the open/active workset this will do:
From there you can apply a workset element filter to get objects on the active workset:
OP, I suggest looking into Dynamo python primer which teaches you the fundamentals of element collectors and element properties. This is not a beginner friendly workflow if you know no Python/Revit API - work your way up to it:
This is the code for getting elements on the active workset:
# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au
# Boilerplate text
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
# Current doc
doc = DocumentManager.Instance.CurrentDBDocument
# Get active workset
wstb = doc.GetWorksetTable()
wsid = wstb.GetActiveWorksetId()
# Make filter and get elements
filter = ElementWorksetFilter(wsid)
elements = FilteredElementCollector(doc).WherePasses(filter).ToElements()
# Preparing output to Dynamo
OUT = elements
If you want to see if an element is on an open workset, you can use the property above by getting the elements workset and then asking that workset if it is open:
# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au
# Boilerplate text
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
# Current doc
doc = DocumentManager.Instance.CurrentDBDocument
# Get active workset
elements = IN[0] if isinstance(IN[0], list) else [IN[0]]
isOpen = []
for e in elements:
id = UnwrapElement(e).WorksetId
workset = doc.GetWorksetTable().GetWorkset(id)
isOpen.append(workset.IsOpen)
# Preparing output to Dynamo
OUT = isOpen