I-logic help: creating and removing parameters from a multi-list parameter

I-logic help: creating and removing parameters from a multi-list parameter

Anonymous
Not applicable
1,697 Views
4 Replies
Message 1 of 5

I-logic help: creating and removing parameters from a multi-list parameter

Anonymous
Not applicable

Hi, I am trying to automatically create parameters using I-logic BASED upon a existing multivalue list

the code i have currently been using 

Dim lidlist = {1,2,3,4,5,6,7,8}For Each lid As Integer In lidList
oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
oParameter=oMyParameter.AddByExpression("lid_", "500", "mm")
Next

gives me this output

error.png

 

What i would like it to do is look like this

nicelogic.png

 

Idealy i would like it to stop at each iteration and ask the user for input, and create only the amount of lids as selected in the parameter "lids"
is anyone able to help me out?

 

kind regards,

 

Matt Hansen

0 Likes
Accepted solutions (1)
1,698 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

So, I got it To create the values as I wanted it to.

 

 

'all hard work by matthansen'
'lids is now a single value parameter, removes silliness caused by array naming'
vals
= lids oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters For loop_ctr = 1 To vals Try parametro= Parameter.Param("lid_"&loop_ctr) Catch PromptVar=InputBox("Enter the width in mm for lid "&loop_ctr, "Enter Value", "500") oMyParameter.AddByExpression("lid_"&loop_ctr, PromptVar, "mm") End Try Next  

 But heres the kicker, how do i get it to automatically delete parameters that MIGHT exist if some naughty engineer has constantly been changing there mind and i now have values outside my set range.

in a separate rule 

vals=lids
param= Parameter.Param("lid_"&vals)
For T = lids To 20
    Try 
    paramtest = Parameter.Param("lid_"&T)     
    paramtest.delete
    Catch
    End Try
Next 

 

0 Likes
Message 3 of 5

MechMachineMan
Advisor
Advisor
try something like:

'Place before all subs m -akes Like function case insensitive
Option Compare Text

'Modify as req'd and place in sub/function
For each oParam in oParams
If oParam.Name Like "Lid_*" '* is wildcare for any char
oParam.Delete
End if
Next



*NOTE: You will likely have problems with sheet metal files as they actually contain 2 sets of parameters; 1 for the folded model definition, and 1 for the flattened model definition*

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 4 of 5

Anonymous
Not applicable

Hi Justin, 
I am a bit of a novice to vba/ilogic and dont really understand your suggestion.
could you elaborate on what the code should look like?

 

0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

so here is my solution

to create the parameters

'where "lids" is your intended parameter to create 
vals
= lids oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters 'count variable is "loop_ctr"
For loop_ctr = 1 To vals 'check to see if parameter exists, if it does the code will leave the existing value in place
Try parametro= Parameter.Param("lid_"&loop_ctr) Catch
'when paramater does not exist create it PromptVar=InputBox("Enter the width in mm for lid "&loop_ctr, "Enter Value", "500") oMyParameter.AddByExpression("lid_"&loop_ctr, PromptVar, "mm") End Try Next

to delete the unwanted parameters

'ask if you actually want to delete a parameter
Dim
question As String question = MessageBox.show("Do you want to delete some lids?","Delete a lid",MessageBoxButtons.OKCancel) 'if you don't the rule will exit If question=vbCancel Then Return End If 'rule will ask what you want to delete Dim entryToDelete As String entryToDelete = InputBox("Please enter the lid to delete","Delete The following lid:",MessageBoxButtons.OkCancel) Dim entryDelete As Integer entryDelete = CStr(entryToDelete) odoc=ThisDoc.Document Dim param As Parameter param=oDoc.ComponentDefinition.Parameters.Item("lid_"&entryDelete) param.Delete
'note, each time you want to delete a parameter you run this rule

Not really satisfied because I have to select each parameter that i dont want, but it works for my application where i will use this in a higher level assembly to delete and resize components  

0 Likes