iLogic - Create Parameters Using Excel Spreadsheet. How should I change code to work with user text parameters ideas?

iLogic - Create Parameters Using Excel Spreadsheet. How should I change code to work with user text parameters ideas?

michal.skubik
Explorer Explorer
482 Views
6 Replies
Message 1 of 7

iLogic - Create Parameters Using Excel Spreadsheet. How should I change code to work with user text parameters ideas?

michal.skubik
Explorer
Explorer
This code perfectily work with user number parameter but I would like to change it to user text parameters. 

Dim
oDoc As Document = ThisApplication.ActiveDocument Dim OComp As PartComponentDefinition = oDoc.ComponentDefinition Dim oUPs As UserParameters = OComp.Parameters.UserParameters Dim oUP As UserParameter Dim xlsFile As String = "c:\_WORK_AV\Engineering\_Invdata\iLogic\Category.xls" GoExcel.Open(xlsFile, "Sheet1") Dim i As Integer = 2 Dim Param As String Dim List As IList Do Until i = 100 Param = GoExcel.CellValue ("A" & i) If Param = "" Then Exit Do List = GoExcel.CellValues("B" & i, "L" & i) Try Test = oUPs.Item(ParamName).Value Catch oUP = oUPs.AddByExpression(Param, GoExcel.CellValue("B" & i), UnitsTypeEnum.kMillimeterLengthUnits) End Try MultiValue.List(Param) = List i = i + 1 Loop
0 Likes
Accepted solutions (1)
483 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @michal.skubik.  You may just have to switch from using the UserParameters.AddByExpression method, to using the UserParameters.AddByValue method.  That's the one I use when adding text type user parameters.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

michal.skubik
Explorer
Explorer

michalskubik_0-1653490695340.png

 

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

I can see within the image you just posted that you changed:

GoExcel.CellValue("B" & i)

'as it was in your first post to:

GoExcel.CellValues("B" & i)

in your line for creating the parameter.

...remove the "s" from "CellValues" to make it "CellValue", because you are just getting a single value, not multiple values.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

michal.skubik
Explorer
Explorer

Great thank you very much. One more question. Do you know how can I debug this code for check if the values are already exist if yes do not make new.

michalskubik_0-1653493166070.png

 

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Actually, yes.  I didn't notice before, but within the Try part of your Try...Catch block, you are using the wrong parameter name to look for, so it is never finding it.  You seem to be using "ParamName" (without the quotes), instead of "Param" (without the quotes).  Plus, instead of using "Test = oUPs.Item(Param).Value", you can use "oUP = oUPs.Item(Param)", because then you would be setting the value of that variable, the same way you are setting its value in the 'Catch' half of that Try...Catch block.

So...

Replace this:

Test = oUPs.Item(ParamName).Value

with this:

oUP = oUPs.Item(Param)

and I think that might fix it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7

michal.skubik
Explorer
Explorer

Hey, do you think that is it possible change a code to run with model states?

0 Likes