I want to use iLogic to create User Parameters with Multi-Value lists filled with info from an excel spreadsheet. What is the code to create a new User Parameter? I can't seem to find it in the help wiki.
Thanks!
@gary.belisle wrote:I want to use iLogic to create User Parameters with Multi-Value lists filled with info from an excel spreadsheet. What is the code to create a new User Parameter? I can't seem to find it in the help wiki.
Thanks!
Format:HTML Format
Version:1.0
StartHTML: 165
EndHTML: 7452
StartFragment: 314
EndFragment: 7420
StartSelection: 314
EndSelection: 314
oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
'Setting an userParameter as inches
oParameter=oMyParameter.AddByExpression("Length_inch", "3", UnitsTypeEnum.kInchLengthUnits)
oParameter=oMyParameter.AddByExpression("Width_inch", "3", "in")
'Setting an userParameter as Millimeteres
oParameter=oMyParameter.AddByExpression("Length_mm", "3", UnitsTypeEnum.kMillimeterLengthUnits)
oParameter=oMyParameter.AddByExpression("Width_mm", "3", "mm")
'Setting an userParameter as text parameter
oParameter=oMyParameter.AddByValue("color", "bule", UnitsTypeEnum.kTextUnits)
oParameter=oMyParameter.AddByValue("color", "red", UnitsTypeEnum.kTextUnits)
oParameter=oMyParameter.AddByValue("color", "yellow", UnitsTypeEnum.kTextUnits)
the above example creates single user parameters
but i dont know wheteher there is a way to create a Multi-value user parameter
Thank you Ravi. That works.
it's possible to try,catch and add a user parameter in each parts of assembly with ilogic???
Take a look at this blog post for some help with updating parts associated with an assembly.
http://modthemachine.typepad.com/my_weblog/2013/08/updating-parts-through-an-assembly.html
Thanks ravikmb5 your rule works wel when I run it as an external rule. But how can I make it work without having to open the part. I.e in edit mode so the parameter is created in the part being edited. At the moment it creates the parameter but in the assembly.
Here is how i changed it:
SyntaxEditor Code Snippet
oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters 'Setting an userParameter as text parameter oParameter=oMyParameter.AddByValue("JOB_NUMBER", "", UnitsTypeEnum.kTextUnits) oParameter=oMyParameter.AddByValue("JOB_DESCRIPTION", "", UnitsTypeEnum.kTextUnits)
Regards
Andrew
@Anonymous wrote:
Thanks ravikmb5 your rule works wel when I run it as an external rule. But how can I make it work without having to open the part. I.e in edit mode so the parameter is created in the part being edited. At the moment it creates the parameter but in the assembly.
edit mode
i guess u are in assembly mode......
do u want to create part parameters from assy
Thanks for your reply.....
Yes, I am in the .iam and want to run a rule to insert custom parameters into the parts to automatically change the "Project" parameter by entering a value in a form, but at the moment I have to open every part to copy and run the rule. In stead of just double clicking on the part and running the rule.
Hello Ravik,
that just saved my day. I tried to get to know the internal name for the parameter - tried to "call",
well tried and tried to declare a parameter existing as a value to copy the value... also tried to declare,
yet got to a lambada error message. Declaring the open document was part of the idea.... yet.
I am not skilled at all.
Can I ask for the reference you´re using?
And thank you very much for making that work.
oUserParams.AddByExpression("EXPRESSION", _
Inventor.UnitsTypeEnum.kUnitlessUnits)
U CAN USE THIS FOR ADDING BY EXPRESSION
I got it... sorry I added a version of Brian Ekins Code
Dim Doc As AssemblyDocument
Doc = ThisApplication.ActiveDocument
Dim userParams As UserParameters
Dim param As Parameter
userParams = Doc.ComponentDefinition.Parameters.UserParameters
param = userParams.AddByValue("Name_User_Parameter","SomeValue",UnitsTypeEnum.kTextUnits)
For Each oPara As Parameter In userParams
Dim oName As String = oPara.Name
If oName = " Name_User_Parameter _1" Then
oPara.Delete
End If
Next
i dont think a lot of people understand how much this is a gold mine.
Here is my end result of how i used your code:
Dim Doc As AssemblyDocument Doc = ThisApplication.ActiveDocument Dim userParams As UserParameters Dim param As Parameter userParams = Doc.ComponentDefinition.Parameters.UserParameters param = userParams.AddByValue("PUMP_MATERIAL", "CAST IRON", UnitsTypeEnum.kTextUnits) For Each oPara As Parameter In userParams Dim oName As String = oPara.Name If oName = "PUMP_MATERIAL_1" Then oPara.Delete End If Next 'set list of values MultiValue.SetList("PUMP_MATERIAL", "CAST IRON", "STAINLESS") 'Dim booleanParam As Object standard = InputRadioBox("Select a Material", _ "CAST IRON", "STAINLESS", True, Title := "iLogic") If standard = True Then Parameter("PUMP_MATERIAL") = "CAST IRON" Else Parameter("PUMP_MATERIAL") = "STAINLESS" End If
Yes That's Right
You can have more control over your files this way.
Here is the code you posted, I added a few things.
SyntaxEditor Code Snippet
Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisDoc.Document Dim oAsmDef As AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition Dim param As Parameter Dim userParams As UserParameters userParams = oAsmDef.Parameters.UserParameters Dim All_New_Parameters As New ArrayList For Each oPara As Parameter In userParams If oPara.Name = "PUMP_MATERIAL" Then GoTo Skip_Creation End If Next Dim Options_Available As New ArrayList Options_Available.Add("CAST IRON") Options_Available.Add("STAINLESS") oParameter = userParams.AddByValue("PUMP_MATERIAL", Options_Available(0), UnitsTypeEnum.kTextUnits) MultiValue.List("PUMP_MATERIAL") = Options_Available MultiValue.SetValueOptions(True, DefaultIndex := 0, NumericCompare := "=") All_New_Parameters.Add("PUMP_MATERIAL") Skip_Creation : Dim standard As Boolean standard = InputRadioBox("Select a Material", "CAST IRON", "STAINLESS", standard, Title := "iLogic") If standard = True Then Parameter("PUMP_MATERIAL") = "CAST IRON" Else Parameter("PUMP_MATERIAL") = "STAINLESS" End If ''''' Just in Case you have more copies - Delete them Dim Copies_To_Delete As New ArrayList For t = 0 To All_New_Parameters.Count - 1 Copies_To_Delete.Add(All_New_Parameters(t) + "_1") Copies_To_Delete.Add(All_New_Parameters(t) + "_1" + "_2") Next t For Each oPara As Parameter In userParams If Copies_To_Delete.Contains(oPara.Name) Then oPara.Delete End If Next iLogicVb.UpdateWhenDone = True
Thank you for sharing your knowledge.
This is going to change every thing for me for all my ilogic coding.
Dim oDoc As AssemblyDocument = TryCast(ThisDoc.Document, AssemblyDocument) Dim compDef As AssemblyComponentDefinition = oDoc.ComponentDefinition If Parameter("PUMP_MATERIAL") = "CAST IRON" Then For Each oComp In compDef.Occurrences For Each oConstraint In oComp.Constraints If kPartDocumentObject Then If iProperties.Value(oComp.Name, "Project", "Description") = "CASTIRONSTATOR" Then oComp.Visible = True 'turn on End If If iProperties.Value(oComp.Name, "Project", "Description") = "STAINLESSSTATOR" Then oComp.Visible = False 'turn off End If If iProperties.Value(oComp.Name, "Project", "Description")="CASTIRON" Then If oConstraint.Name = "VERTICALCI" Then oComp.Visible = True iProperties.Value("Custom", "Orientation")="VERTICAL" End If If oConstraint.Name = "RIGHTCI" Then oComp.Visible = False End If If oConstraint.Name = "LEFTCI" Then oComp.Visible = False End If End If If iProperties.Value(oComp.Name, "Project", "Description")="STAINLESS" Then If oConstraint.Name = "VERTICALSS" Then oComp.Visible = False End If If oConstraint.Name = "RIGHTSS" Then oComp.Visible = False End If If oConstraint.Name = "LEFTSS" Then oComp.Visible = False End If End If End If Next Next End If If Parameter("PUMP_MATERIAL") = "STAINLESS" Then For Each oComp In compDef.Occurrences For Each oConstraint In oComp.Constraints If kPartDocumentObject Then If iProperties.Value(oComp.Name, "Project", "Description") = "STAINLESSSTATOR" Then oComp.Visible = True 'turn on End If If iProperties.Value(oComp.Name, "Project", "Description") = "CASTIRONSTATOR" Then oComp.Visible = False 'turn off End If If iProperties.Value(oComp.Name, "Project", "Description")="STAINLESS" Then If oConstraint.Name = "VERTICALSS" Then oComp.Visible = True iProperties.Value("Custom", "Orientation")="VERTICAL" End If If oConstraint.Name = "RIGHTSS" Then oComp.Visible = False End If If oConstraint.Name = "LEFTSS" Then oComp.Visible = False End If End If If iProperties.Value(oComp.Name, "Project", "Description")="CASTIRON" Then If oConstraint.Name = "VERTICALCI" Then oComp.Visible = False End If If oConstraint.Name = "RIGHTCI" Then oComp.Visible = False End If If oConstraint.Name = "LEFTCI" Then oComp.Visible = False End If End If End If Next Next End If
i have it then set for all the buttons the same way (left, right, vertical). This way i control all of my model types through a simple form.
Hope that i possibly showed you something as well. 🙂
Hi,
is there any ilogic rule available to creating user parameters in flat pattern stage ?
Hi @Biju.Veedu .
While in that Flat Pattern mode/environment, you can still create user parameters manually, and so you can still create them by code the same way too, but when done by code, they just don't shop up right away in the parameters dialog box. Once you go back to the normal folded part mode/environment then you can see that the user parameter you created by code while in Flat Pattern mode was really created.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb:or you can Explore My CONTRIBUTIONS
Wesley Crihfield
@WCrihfield thanks for the info. but I want to stay that parameters at flat stage. Manually typing each one is very painful.