Skip to content

Commit 33b9ec4

Browse files
committed
Fixed issue of handling missing comma
If you edit the CSV file in e.g. Excel and there was no Comment, then the comma at the end of the line will be removed. It’s better to handle that in the code when importing data from the CSV file
1 parent b2ab7e0 commit 33b9ec4

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

ParameterIO.bundle.zip

-6.01 KB
Binary file not shown.

ParameterIO_Python.manifest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"id": "96adeab4-7e93-41f4-a4cc-90aba9a8be25",
55
"author": "Wayne Brill, Autodesk",
66
"description": {
7-
"": "Allows you to select a CSV (comma seperated values) file and then edits existing Attributes. Also allows you to write parameters to a file"
7+
"": "Enables users to update parameters from or save them to a CSV (Comma Separated Values) file"
88
},
9-
"version": "1.0",
9+
"version": "1.0.0",
1010
"runOnStartup": true,
1111
"supportedOS": "windows|mac"
1212
}

ParameterIO_Python.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def writeTheParameters(theFileName):
230230
def readTheParameters(theFileName):
231231
app = adsk.core.Application.get()
232232
design = app.activeProduct
233-
233+
ui = app.userInterface
234234
try:
235235
paramsList = []
236236
for oParam in design.allParameters:
@@ -244,21 +244,24 @@ def readTheParameters(theFileName):
244244
nameOfParam = valsInTheLine[0]
245245
unitOfParam = valsInTheLine[1]
246246
expressionOfParam = valsInTheLine[2]
247-
comentOfParamFromFile = valsInTheLine[3]
248-
#need to remove the return character from the comment
249-
commentOfParamList = comentOfParamFromFile.split("\n")
250-
commentOfParam = commentOfParamList[0]
247+
commentOfParam = ''
248+
# comment might be missing
249+
if len(valsInTheLine) > 3:
250+
comentOfParamFromFile = valsInTheLine[3]
251+
#need to remove the return character from the comment
252+
commentOfParamList = comentOfParamFromFile.split("\n")
253+
commentOfParam = commentOfParamList[0]
254+
251255
# if the name of the paremeter is not an existing parameter add it
252256
if nameOfParam not in paramsList:
253257
valInput_Param = adsk.core.ValueInput.createByString(expressionOfParam)
254258
design.userParameters.add(nameOfParam, valInput_Param, unitOfParam, commentOfParam)
255259
#update the values of existing parameters
256260
else:
257-
paramInModel = design.userParameters.itemByName(nameOfParam)
261+
paramInModel = design.allParameters.itemByName(nameOfParam)
258262
paramInModel.unit = unitOfParam
259263
paramInModel.expression = expressionOfParam
260264
paramInModel.comment = commentOfParam
261-
ui = app.userInterface
262265
ui.messageBox('Finished reading and updating parameters')
263266
except:
264267
if ui:

0 commit comments

Comments
 (0)