<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Set Parameter Doesn't Create / How to Create Parameter in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/set-parameter-doesn-t-create-how-to-create-parameter/m-p/13118806#M4734</link>
    <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":face_with_tears_of_joy:"&gt;😂&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;&amp;nbsp; I tend to agree.&amp;nbsp; There is definitely more to it than what we want there to be.&amp;nbsp; But with more control comes more complexity.&amp;nbsp; There are lots of possible ways to change the code process, and using a 'referenced' resource is likely the way to go, for the sake of repeatability and efficiency.&lt;/P&gt;
&lt;P&gt;I'm on my way out for the day, or I would post more stuff.&amp;nbsp; Unfortunately, if you are using Inventor 2022 or newer, we also have to work around the possibility that ModelStates may be involved, and whether or not the Document our routine is attempting to work with is either 'the factory' version, or a 'member' version of that Document.&amp;nbsp; We will not be able to 'write' directly to a 'member' version, so a universal routine for creating/setting a parameter unfortunately needs to be even more complicated than what I showed an example of.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Oct 2024 19:10:55 GMT</pubDate>
    <dc:creator>WCrihfield</dc:creator>
    <dc:date>2024-10-30T19:10:55Z</dc:date>
    <item>
      <title>Set Parameter Doesn't Create / How to Create Parameter</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/set-parameter-doesn-t-create-how-to-create-parameter/m-p/13118577#M4731</link>
      <description>&lt;P&gt;For some reason, parameter("name") function doesn't create parameters that don't exist, which is not something I've seen before. Regardless, I need a parameter to be created and set via iLogic. I don't see anything obvious in Snippets &amp;gt; Parameters and all solutions on the forum are cumbersome, horrendously out of date, or don't work.&lt;BR /&gt;&lt;BR /&gt;What is the current method to set parameters if they exist or create and set if they don't exist then export it to iProperties?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cstarker6VCG4_0-1730309832514.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1427721iE383CB5283DC2833/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cstarker6VCG4_0-1730309832514.png" alt="cstarker6VCG4_0-1730309832514.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 17:42:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/set-parameter-doesn-t-create-how-to-create-parameter/m-p/13118577#M4731</guid>
      <dc:creator>cstarker6VCG4</dc:creator>
      <dc:date>2024-10-30T17:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Set Parameter Doesn't Create / How to Create Parameter</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/set-parameter-doesn-t-create-how-to-create-parameter/m-p/13118641#M4732</link>
      <description>&lt;P&gt;None of the standard/installed iLogic 'snippets' will actually 'create' a new parameter, if it does not already exist.&amp;nbsp; That is generally done using Inventor API code, since there are no iLogic shortcut snippets for that task.&amp;nbsp; But there are several different types of parameters, and multiple different types of units that a parameter can have, and some can have a list of possible values to choose from.&amp;nbsp; So, there are two main methods used for creating them.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=UserParameters_AddByExpression" target="_blank" rel="noopener"&gt;UserParameters.AddByExpression&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=UserParameters_AddByValue" target="_blank" rel="noopener"&gt;UserParameters.AddByValue&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which one is right for a specific situation depends on what units you want it to have, and how you need to define its value/expression.&amp;nbsp; If it is going to have an 'equation' in its 'expression', or refer to the name of another parameter, then you will need to use the AddByExpression method.&amp;nbsp; Otherwise you can usually use the AddByValue method.&amp;nbsp; Below is just one possible example code that is designed to work for any type of document.&amp;nbsp; Parts, assemblies, and drawings can all have parameters, but they are differently, depending on the document type you are working with.&amp;nbsp; Not only that, but when using Inventor's API to create parameters, you have to keep units conversion in mind.&amp;nbsp; Because all 'raw numbers' in a rule, that are supposed to represent any type of 'measurement' value, will be understood as 'database units'.&amp;nbsp; For length/distance that is centimeters, for angles that is radians, and so on, no matter what units your document is set to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oDoc As Document = ThisDoc.Document
Dim oUParams As UserParameters = Nothing
If (TypeOf oDoc Is AssemblyDocument) OrElse (TypeOf oDoc Is PartDocument) Then
	oUParams = oDoc.ComponentDefinition.Parameters.UserParameters
ElseIf TypeOf oDoc Is DrawingDocument Then
	oUParams = oDoc.Parameters.UserParameters
End If
If oUParams Is Nothing Then Return
Dim sParamName As String = "MyParam1"
Dim oParamValue As Double = 15.125
Dim oUParam As UserParameter = Nothing
Try
	oUParam = oUParams.Item(sParamName)
Catch
	oUParam = oUParams.AddByValue(sParamName, oParamValue, UnitsTypeEnum.kInchLengthUnits)
End Try
If oUParam.Value &amp;lt;&amp;gt; oParamValue Then
	Try
		oUParam.Value = oParamValue
	Catch
		'what to do if setting its value fails
	End Try
End If
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only 'iLogic' in that example is the 'ThisDoc.Document' phrase used in the first line.&amp;nbsp; All the rest is Inventor API.&lt;/P&gt;
&lt;P&gt;This example does not include exposing the parameter to create a custom iProperty, but that is also done using additional Inventor API code.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=UserParameter_IsKey" target="_blank" rel="noopener"&gt;UserParameter.IsKey&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=UserParameter_ExposedAsProperty" target="_blank" rel="noopener"&gt;UserParameter.ExposedAsProperty&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After the above property is set to True for that UserParameter, then you will be able to access the following property, and the properties of the object types it returns.&amp;nbsp; The below line exposes all the additional possible settings you can see within the Format Custom Properties type dialog.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=UserParameter_CustomPropertyFormat" target="_blank" rel="noopener"&gt;UserParameter.CustomPropertyFormat&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-CustomPropertyFormat" target="_blank" rel="noopener"&gt;CustomPropertyFormat&lt;/A&gt;&amp;nbsp;object&lt;/P&gt;
&lt;P&gt;...and so on&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 18:05:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/set-parameter-doesn-t-create-how-to-create-parameter/m-p/13118641#M4732</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2024-10-30T18:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Set Parameter Doesn't Create / How to Create Parameter</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/set-parameter-doesn-t-create-how-to-create-parameter/m-p/13118745#M4733</link>
      <description>&lt;P&gt;Good God, I was expecting a 2-line block at most. All of that to just create and set a parameter? There is no way I am putting that down each time a parameter is written so now this discussion becomes...&lt;BR /&gt;&lt;BR /&gt;How do I make a global (accessible by any iLogic rule) function that sets a pre-existing parameter or creates and sets a non-existing parameter? I understand how to declare a function in the scope of a single rule. Now I need a to create a library to contain this and access it with another rule. This is what I have so far. It doesn't work, of course.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;Class&lt;/SPAN&gt; &lt;SPAN&gt;thisRule&lt;/SPAN&gt;
	&lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;main&lt;/SPAN&gt;()
		&lt;SPAN&gt;Function&lt;/SPAN&gt; &lt;SPAN&gt;createSetParameter&lt;/SPAN&gt;(&lt;SPAN&gt;sParamName&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt;, &lt;SPAN&gt;sParamType&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt;, &lt;SPAN&gt;oParamValue&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Decimal&lt;/SPAN&gt;)
				&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Document&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Document&lt;/SPAN&gt;
			&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oUParams&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;UserParameters&lt;/SPAN&gt; = &lt;SPAN&gt;Nothing&lt;/SPAN&gt;
			&lt;SPAN&gt;If&lt;/SPAN&gt; (&lt;SPAN&gt;TypeOf&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt; &lt;SPAN&gt;Is&lt;/SPAN&gt; &lt;SPAN&gt;AssemblyDocument&lt;/SPAN&gt;) &lt;SPAN&gt;OrElse&lt;/SPAN&gt; (&lt;SPAN&gt;TypeOf&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt; &lt;SPAN&gt;Is&lt;/SPAN&gt; &lt;SPAN&gt;PartDocument&lt;/SPAN&gt;) &lt;SPAN&gt;Then&lt;/SPAN&gt;
				&lt;SPAN&gt;oUParams&lt;/SPAN&gt; = &lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;ComponentDefinition&lt;/SPAN&gt;.&lt;SPAN&gt;Parameters&lt;/SPAN&gt;.&lt;SPAN&gt;UserParameters&lt;/SPAN&gt;
			&lt;SPAN&gt;ElseIf&lt;/SPAN&gt; &lt;SPAN&gt;TypeOf&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt; &lt;SPAN&gt;Is&lt;/SPAN&gt; &lt;SPAN&gt;DrawingDocument&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
				&lt;SPAN&gt;oUParams&lt;/SPAN&gt; = &lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Parameters&lt;/SPAN&gt;.&lt;SPAN&gt;UserParameters&lt;/SPAN&gt;
			&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
			&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oUParams&lt;/SPAN&gt; &lt;SPAN&gt;Is&lt;/SPAN&gt; &lt;SPAN&gt;Nothing&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt; &lt;SPAN&gt;Return&lt;/SPAN&gt;
			&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;sParamName&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt; = &lt;SPAN&gt;"MyParam1"&lt;/SPAN&gt;
			&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oParamValue&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Double&lt;/SPAN&gt; = 15.125
			&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oUParam&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;UserParameter&lt;/SPAN&gt; = &lt;SPAN&gt;Nothing&lt;/SPAN&gt;
			&lt;SPAN&gt;Try&lt;/SPAN&gt;
				&lt;SPAN&gt;oUParam&lt;/SPAN&gt; = &lt;SPAN&gt;oUParams&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;sParamName&lt;/SPAN&gt;)
			&lt;SPAN&gt;Catch&lt;/SPAN&gt;
				&lt;SPAN&gt;oUParam&lt;/SPAN&gt; = &lt;SPAN&gt;oUParams&lt;/SPAN&gt;.&lt;SPAN&gt;AddByValue&lt;/SPAN&gt;(&lt;SPAN&gt;sParamName&lt;/SPAN&gt;, &lt;SPAN&gt;oParamValue&lt;/SPAN&gt;, &lt;SPAN&gt;sParamType&lt;/SPAN&gt;)
			&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Try&lt;/SPAN&gt;
			&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oUParam&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt; &amp;lt;&amp;gt; &lt;SPAN&gt;oParamValue&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
				&lt;SPAN&gt;Try&lt;/SPAN&gt;
					&lt;SPAN&gt;oUParam&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt; = &lt;SPAN&gt;oParamValue&lt;/SPAN&gt;
				&lt;SPAN&gt;Catch&lt;/SPAN&gt;
					&lt;SPAN&gt;MessageBox&lt;/SPAN&gt;.&lt;SPAN&gt;Show&lt;/SPAN&gt;(&lt;SPAN&gt;"Could not set parameter."&lt;/SPAN&gt;, &lt;SPAN&gt;"Error"&lt;/SPAN&gt;)
				&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Try&lt;/SPAN&gt;
			&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
		&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Function&lt;/SPAN&gt;
	&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;
&lt;SPAN&gt;end&lt;/SPAN&gt; &lt;SPAN&gt;class&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Secondary question: where is all the official documentation? I looked up how to create function libraries and all I'm getting is forum posts for very specific situations, often 3+ years old. Otherwise, I would not need to ask so often here.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 18:44:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/set-parameter-doesn-t-create-how-to-create-parameter/m-p/13118745#M4733</guid>
      <dc:creator>cstarker6VCG4</dc:creator>
      <dc:date>2024-10-30T18:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Set Parameter Doesn't Create / How to Create Parameter</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/set-parameter-doesn-t-create-how-to-create-parameter/m-p/13118806#M4734</link>
      <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":face_with_tears_of_joy:"&gt;😂&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;&amp;nbsp; I tend to agree.&amp;nbsp; There is definitely more to it than what we want there to be.&amp;nbsp; But with more control comes more complexity.&amp;nbsp; There are lots of possible ways to change the code process, and using a 'referenced' resource is likely the way to go, for the sake of repeatability and efficiency.&lt;/P&gt;
&lt;P&gt;I'm on my way out for the day, or I would post more stuff.&amp;nbsp; Unfortunately, if you are using Inventor 2022 or newer, we also have to work around the possibility that ModelStates may be involved, and whether or not the Document our routine is attempting to work with is either 'the factory' version, or a 'member' version of that Document.&amp;nbsp; We will not be able to 'write' directly to a 'member' version, so a universal routine for creating/setting a parameter unfortunately needs to be even more complicated than what I showed an example of.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 19:10:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/set-parameter-doesn-t-create-how-to-create-parameter/m-p/13118806#M4734</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2024-10-30T19:10:55Z</dc:date>
    </item>
  </channel>
</rss>

