making FX parameter in any part

making FX parameter in any part

ekjerside
Contributor Contributor
818 Views
6 Replies
Message 1 of 7

making FX parameter in any part

ekjerside
Contributor
Contributor

I need help to make Ilogic that makes fx parameters in any open part just by running the ilogic rule by the user. 

 

Exampel of fx parameters name could be:

 

Tube_diameter set to 1 mm.

Tube_thickness set to 1 mm.

Length_of_tube set to 1 mm.

Inconel_thickness set 1 mm. 

 

thank you very much....

0 Likes
819 Views
6 Replies
Replies (6)
Message 2 of 7

Frederick_Law
Mentor
Mentor
0 Likes
Message 3 of 7

ekjerside
Contributor
Contributor

Why not set them in Template? because it maybe not every part that need the parameter....

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

Hi @ekjerside.  There are literally tons of variations of code for creating new parameters of various types, in various types of documents, so a quick search of this forum would have resulted in a great many useful posts to review.  Below is just another variation you could use for adding a single numerical UserParameter to a part or assembly.

Dim oDoc As Document = ThisDoc.Document
If oDoc.IsModifiable = False Then Exit Sub
If ThisApplication.FileManager.IsInventorComponent(oDoc.FullFileName) = False Then Exit Sub
Dim oUParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
Dim oUParam As UserParameter = Nothing
Dim sParamName As String = "Tube_diameter"
Try
	'Check to see if this Parameter already exists
	oUParam = oUParams.Item(sParamName)
Catch
	'Parameter doesn't exist, so create it
	oUParam = oUParams.AddByExpression(sParamName, "1 mm", UnitsTypeEnum.kMillimeterLengthUnits)
End Try
oDoc.Update
'oDoc.Save

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

ekjerside
Contributor
Contributor

I tried this.

 

Dim oDoc As Document = ThisDoc.Document
If oDoc.IsModifiable = False Then Exit Sub
If ThisApplication.FileManager.IsInventorComponent(oDoc.FullFileName) = False Then Exit Sub
Dim oUParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
Dim oUParam As UserParameter = Nothing
Dim sParamName As String = "Tube_diameter"
Dim sParamName As String = "Tube_thickness"
Dim sParamName As String = "Length_of_tube"
Dim sParamName As String = "Inconel_thickness"
Try
	'Check to see if this Parameter already exists
	oUParam = oUParams.Item(sParamName)
Catch
	'Parameter doesn't exist, so create it
	oUParam = oUParams.AddByExpression(sParamName, "1 mm", UnitsTypeEnum.kMillimeterLengthUnits)
End Try
oDoc.Update
'oDoc.Save

 But got an error:

 

Error on Line 7 : Local variable 'sParamName' is already declared in the current block.
Error on Line 8 : Local variable 'sParamName' is already declared in the current block.
Error on Line 9 : Local variable 'sParamName' is already declared in the current block.

 

what to do?

0 Likes
Message 6 of 7

Frederick_Law
Mentor
Mentor

@ekjerside wrote:

Why not set them in Template? because it maybe not every part that need the parameter....


What's wrong with extra parameters in the Template?

I do lots of sheetmetal.  I have all gauge size setup in template which I'll only use one in the part.  Not use if it's not sheetmetal.

I won't run rules to set the gauge I need every time I design a part.

If users need to remember which rules to run for which part, it already failed.

Just my opinion.

0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

When you need to add multiple parameters at one time, you will need to include a loop to process multiple items.  Here is a very slightly altered version of the earlier rule I posted which includes a loop of those parameter names.

Dim oDoc As Document = ThisDoc.Document
If oDoc.IsModifiable = False Then Exit Sub
If ThisApplication.FileManager.IsInventorComponent(oDoc.FullFileName) = False Then Exit Sub
Dim oUParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
Dim oUParam As UserParameter = Nothing
Dim oParamNames As New List(Of String) From {"Tube_diameter", "Tube_thickness", "Length_of_tube", "Inconel_thickness"}
For Each sParamName In oParamNames
	Try
		'Check to see if this Parameter already exists
		oUParam = oUParams.Item(sParamName)
	Catch
		'Parameter doesn't exist, so create it
		oUParam = oUParams.AddByExpression(sParamName, "1 mm", UnitsTypeEnum.kMillimeterLengthUnits)
	End Try
Next
oDoc.Update
'oDoc.Save

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes