Search code examples
pythonapirevit

Getting Workset id's from the open project Revit API + python


I am trying to get a list of workset name and id's from the active document using Revit API inside of Python node in Dynamo. I am trying to access workset table but this code returns nothing:

doc = __doc__

workset = ActiveWorkset(doc)
active_id = workset.ActiveWorksetId()

OUT = active_id

For now I was just trying to see if i can get active workset first but even that doesnt work.


Solution

  • I haven't tried this in Dynamo, but my trusty RevitPythonShell thinks this should work:

    worksetTable = doc.GetWorksetTable()
    activeId = worksetTable.GetActiveWorksetId()
    workset = worksetTable.GetWorkset(activeId)
    

    this is based on the example from the Revit 2014 API document in the SDK...

    The output:

    >>> workset
    <Autodesk.Revit.DB.Workset object at 0x000000000000002E [Autodesk.Revit.DB.Workset]>
    

    Based on your example, you probably want to do this at the end:

    OUT = activeId