Create a Parameter with ilogic

Create a Parameter with ilogic

brett.bouwens
Observer Observer
597 Views
2 Replies
Message 1 of 3

Create a Parameter with ilogic

brett.bouwens
Observer
Observer

Is there a way to create a parameter and add information to the parameter with ilogic.

 

I've attempted Parameters.UserParameters.AddByValue("MAT'L", 1) but it errors out.

 

If Not ParameterExists("MAT'L") Then '

 Parameters.UserParameters.AddByExpression("MAT'L", Value:=0, Units:="") '  Parameters.UserParameters.Item("MAT'L").Value = 1

End If

 

Any ideas? I want to copy rules to parts that carry over a material list and a hardness for each material. I tried to use the material library but there I cannot figure a way to have the material and hardness show up on title blocks. 

 

The idea of having it in ilogic as well is so i can post the rule in old parts too and easily file through and find the right material in the parameter list.

0 Likes
598 Views
2 Replies
Replies (2)
Message 2 of 3

iLimbani
Contributor
Contributor
I believe that (') of MAT'L is commenting out whatever written after that. 
Please try below code.
 
	Try
	oUserParams.Item("MATL").Delete
	Catch
	End Try

	Dim oParams As Parameters
    oParams = oDDef.Parameters

    Dim oUserParams As UserParameters
    oUserParams = oParams.UserParameters

Try
        Dim oMATL As Parameter
        oMATL = oUserParams.Item("MATL")
Catch
        oMATL _VALUE= 0
        Dim ooMATL _VALUE As Double = Round(oMATL _VALUE, 1)
        Dim hformattedValue As String = ooMATL _VALUE.ToString("F0")
        oUserParams.AddByExpression("MATL", hformattedValue, kMillimeterLengthUnits)
End Try
0 Likes
Message 3 of 3

ryan.rittenhouse
Advocate
Advocate

If you want a ParameterExists function like you tried in your request, you can do something like this:

 

Sub Main()
	
	Dim doc As Document = ThisDoc.Document
	
	If Not ParameterExists(doc, "MATL") Then
		doc.ComponentDefinition.Parameters.UserParameters.AddByExpression("MATL", 0, kMillimeterLengthUnits)
	End If
	
End Sub 'Main

Function ParameterExists(doc As Document, parameterName As String) As Boolean

    Dim params As Parameters
    If doc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
        params = doc.Parameters
    Else
        params = doc.ComponentDefinition.Parameters
    End If

    For Each inventorParameter As Parameter In params
        If inventorParameter.Name = parameterName Then Return True
    Next inventorParameter

    Return False

End Function 'ParameterExists
If this solved your problem, or answered your question, please click Accept Solution.
0 Likes