Read from csv file

I have a list of worksets in csv file
and i’m trying to create those worksets in revit with
python script based on @eirannejad script.

please help with the errors i’m new to python and revit API.

the code:

“”“Create worksets from a list and set defautl visibility”""

import csv

from Autodesk.Revit import DB

def set_workset_default_visiblity(d, workset, state):
wdvs = DB.WorksetDefaultVisibilitySettings.GetWorksetDefaultVisibilitySettings(d)
wdvs.SetWorksetVisibility(workset.Id, state)

def create_workset(d, name):
return DB.Workset.Create(d, name)

workset_names = []

Path = ‘D:\Test\worksets.csv’

with open(Path, encoding=‘utf8’, newline=’’) as csvfile:
reader = csv.DictReader(csvfile)

for row in reader:


if doc.IsWorkshared:
t = DB.Transaction(doc, “Create Worksets”)

# make your model changes here
for name in workset_names:
    ws = create_workset(doc, name)
    """if "Hidden" in name:
        set_workset_default_visiblity(doc, ws, False)"""


I did not try your code but the RPS tells you to change the encoding argument of the open() function

change your with open ([...], encoding='utf-8',[...])

at least that is what the Exception Thrown mentions on the first line after the >>> in the RPS windows. Advice here, these exceptions are usually fairly explicit if you take the time to read it. in your case _ even though it is not always the case, it is quite explicit:
open() has a bad keyword argument for the encoding argument.

1 Like

The open that you are using is the bultin lowlevel open function in python. The one that has the encoding= parameter, is from the codecs module that is designed to wrap the builtin open to allow for automatic handling of various encodings:

import codecs

with, encoding='utf-8') as csv_file_handle:
    # ....

File stands for the full file path with the file name?

Yes. just like the builtin open() function