Error with OS Lib - revit could not complete the external command

Do you have this error when you use OS Lib? If i delete OS dir and past string path to “open json” all goes without problem…

My “error” code:

from Autodesk.Revit.UI.Selection import *
from Autodesk.Revit.DB import *
from pyrevit import forms
from rpw import revit
import json
import os

doc = revit.doc
uidoc = revit.uidoc


class CustomISelectionFilter(ISelectionFilter):
    def __init__(self, nom_categorie):
        self.nom_categorie = nom_categorie

    def AllowElement(self, e):
        if e.Category.Name in self.nom_categorie:
            # if self.nom_categorie.Contains(e.Category.Name):
            # if e.Category.Name == self.nom_categorie:
            return True
        else:
            return False

    def AllowReference(self, ref, point):
        return True


def pick_objects(title="Pick", filter=""):
    with forms.WarningBar(title=title):
        return uidoc.Selection.PickObjects(ObjectType.Element, CustomISelectionFilter(filter))


dir = os.path.dirname(os.path.abspath(__file__))

# Pick schacko element
air_terminal = pick_objects(title="Pick schacko DQJ", filter="Air Terminals")

# Write air flow
air_flow = forms.ask_for_string(prompt="Write air supply", title="Insulation")
air_flow = round(float(air_flow), -1)
air_flow = int(air_flow)
print(air_flow)


# Get DQJ sizes
with open(os.path.join(dir, "schacko_DQJ_sq_supply.json")) as file:
    dqj_dict = json.load(file)
    print(dqj_dict[str(air_flow)])

selected_dqj = forms.SelectFromList.show(dqj_dict[str(
    air_flow)], title="Select DQJ which you want to pick", multiselect=False, button_name='Select DQJ')
selected_dqj_size = selected_dqj[0][3::]
print(selected_dqj_size)

String path…

with open("C:\Users\pawel\Documents\GitHub\PYLAB\PYLAB.extension\PYLAB.tab\DuringTests.Panel\DQJ_Calc.pushbutton\schacko_DQJ_sq_supply.json", "r") as file:
    dqj_dict = json.load(file)

Ok, so os.chdir works but i stil don’t know why it doesn’t work with other methods…

os.chdir(os.path.dirname(os.path.abspath(__file__)))

Isn’t dir a reserved name or a method?
You assigned a dir variable…

1 Like

Maybe, i will look at it