Hi,
I’m trying to write descriptions to model elements by reading from an excel spreadsheet. I’m able to read from the example excel (physical_components.xlsx) that’s found within the Resources folder of the Python4Capella project. When I try to change the example path to the excel I wish to read, I produce an attribute error where:
File “L/Python4Capella/utilities/CapellaPlatform.py”, line 50, in getAbsolutePath
except ImportError:
AttributeError: ‘NoneType’ object has no attribute ‘getLocation’
This leads me to believe that it’s not able to read the xlsx file for some reason. However, in the example excel, I am able to edit that file and read the excel file from that example excel only. Is there something that I’m missing in the file path? Example of my code below (<----- indicates the erroneous lines):
if len(argv) != 2:
aird_path = '/test/test.aird'
xlsx_path = "/Python4Capella/resources/physical_components.xlsx" **<---- This line works**
#xlsx_path = "/Python4Capella/resources/test_components.xlsx" **<----- This line does not work (direct copy of the excel file just with name changed)**
else:
aird_path = argv[0]
xlsx_path = argv[1]
model = CapellaModel()
model.open(aird_path)
se = model.get_system_engineering()
xlsx_file = CapellaPlatform.getWorkspaceFile(xlsx_path)
xlsx_file_name = CapellaPlatform.getAbsolutePath(xlsx_file)
print("Read " + xlsx_file_name)
wb = load_workbook(xlsx_file_name)
ws = wb.active
row = ws.max_row
column = ws.max_column
for i in range(1, row + 1):
a = ws.cell(row = i, column = 1)
print(a.value)
for j in se.get_physical_architecture().get_all_contents_by_type(PhysicalComponentPkg):
if j.get_name() == "test Elements":
for x in j.get_all_contents_by_type(PhysicalComponent):
if (x.get_sid):
if x.get_id() == a.value:
b = ws.cell(row = i, column = 2)
try:
x.set_sid(b.value)
except:
pass
Note: I have no issues running this script and setting the sid of each component with the supplied sample file, I just can’t change the file path without receiving the error.