Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic code to create a User Parameter

35 REPLIES 35
Reply
Message 1 of 36
gary.belisle
28222 Views, 35 Replies

iLogic code to create a User Parameter

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!

---------------------------------------------------------------------
i7-4800MQ Dell Precision M6800, Win 7 Enterprise 64-bit, 16GB RAM
Autodesk Product Design Suite Ultimate 2015
Autodesk Vault Professional 2015
PLM 360
35 REPLIES 35
Message 2 of 36
ravikmb5
in reply to: gary.belisle


@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

 

 

Please mark this response as Problem Solved if it answers your question.
----------------------------------------------------------------------------------------------
Ravi Kumar MB,
i7 860 Dell Studio XPS Win 7 64 bit 12 Gb RAM & HP Z220 SFF Workstation
Autodesk Inventor Certified professional 2016
Email: ravikmb5@gmail.com





Message 3 of 36
gary.belisle
in reply to: ravikmb5

Thank you Ravi. That works.

---------------------------------------------------------------------
i7-4800MQ Dell Precision M6800, Win 7 Enterprise 64-bit, 16GB RAM
Autodesk Product Design Suite Ultimate 2015
Autodesk Vault Professional 2015
PLM 360
Message 4 of 36
Anonymous
in reply to: gary.belisle

it's possible to try,catch and add a user parameter in each parts of assembly with ilogic???

Message 5 of 36
ekinsb
in reply to: Anonymous

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


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 6 of 36
Anonymous
in reply to: ravikmb5

oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
oParameter=oMyParameter.AddByValue("Material", "Steel, S275", UnitsTypeEnum.kTextUnits)
MultiValue.SetList("Material", "Keruing Board", "Aluminum 1050", "Aluminum Alloy 5251", "Aluminum Alloy 5454 h22", "Aluminum 6061", "Domex 460 MCD", "DX51D Z275", "GRP", "Nylon 6/6", "Plywood, Finish", "Rubber", "Rubber EPDM", "Steel, S275", "Steel, S275JR", "Steel, S355", "Steel, S355J0", "Steel, S355J2+N", "Steel, S355JR")

for example creates multi value parameters
Message 7 of 36
Anonymous
in reply to: ravikmb5

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
Message 8 of 36
ravikmb5
in reply to: Anonymous


@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 

Please mark this response as Problem Solved if it answers your question.
----------------------------------------------------------------------------------------------
Ravi Kumar MB,
i7 860 Dell Studio XPS Win 7 64 bit 12 Gb RAM & HP Z220 SFF Workstation
Autodesk Inventor Certified professional 2016
Email: ravikmb5@gmail.com





Message 9 of 36
Anonymous
in reply to: ravikmb5

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.

 

Message 10 of 36
Logos_Atum
in reply to: ravikmb5

@ravikmb5

 

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.

 

Dogs aren´t flammable.
Message 11 of 36
ravikmb5
in reply to: Logos_Atum

oUserParams.AddByExpression("EXPRESSION", _
Inventor.UnitsTypeEnum.kUnitlessUnits)

 

U CAN USE THIS FOR ADDING BY EXPRESSION

Please mark this response as Problem Solved if it answers your question.
----------------------------------------------------------------------------------------------
Ravi Kumar MB,
i7 860 Dell Studio XPS Win 7 64 bit 12 Gb RAM & HP Z220 SFF Workstation
Autodesk Inventor Certified professional 2016
Email: ravikmb5@gmail.com





Message 12 of 36
Logos_Atum
in reply to: gary.belisle

MORBO SEND HIS REGARDS TO YHE HUMAN WYRMIN


:))))))
Dogs aren´t flammable.
Message 13 of 36
cencinaNB2ET
in reply to: ravikmb5

Yes,

what needs to change to work in an Assembly?

Thanks

Message 14 of 36
cencinaNB2ET
in reply to: cencinaNB2ET

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
Message 15 of 36
DeerSpotter
in reply to: cencinaNB2ET

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
Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
Message 16 of 36
cencinaNB2ET
in reply to: DeerSpotter

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


Message 17 of 36
DeerSpotter
in reply to: cencinaNB2ET

Thank you for sharing your knowledge. 

This is going to change every thing for me for all my ilogic coding. 
image.png

image.png
image.pngimage.png

 

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. 🙂

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
Message 18 of 36
Biju.Veedu
in reply to: ravikmb5

Hi, 

is there any ilogic rule available to creating user parameters in flat pattern stage ? 

Flat pattern parameters.jpg

Message 19 of 36
WCrihfield
in reply to: Biju.Veedu

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

EESignature

Message 20 of 36
Biju.Veedu
in reply to: WCrihfield

@WCrihfield thanks for the info. but I want to stay that parameters at flat stage. Manually typing each one is very painful.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report