<?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: Creating a &amp;quot;dynamic&amp;quot; user parameter in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-a-quot-dynamic-quot-user-parameter/m-p/11509986#M31310</link>
    <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2924318"&gt;@mrawesomelemons&lt;/a&gt;.&amp;nbsp; I agree with that too.&amp;nbsp; I also created a slightly modified version of your code that you can try out, to see if it works any better for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oDoc As Document = ThisDoc.Document
Dim UParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
For Each UserParam As UserParameter In UParams
	If UserParam.Name = "PartNumber" Then UserParam.Delete
Next
Dim PN As String = oDoc.PropertySets.Item(3).Item("Part Number").Value
Dim PNParam As UserParameter = UParams.AddByValue("PartNumber", PN, UnitsTypeEnum.kTextUnits)
PNParam.Comment = "Set by a rule, do not alter"
oDoc.Update&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, keep in mind that if you want to access the parameters in a drawing type document, that type of document does not have a 'ComponentDefinition', so its Parameters are directly under the Document object (DrawingDocument.Parameters.UserParameters).&amp;nbsp; I assumed this code above was working with a Part or an Assembly.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Oct 2022 14:47:05 GMT</pubDate>
    <dc:creator>WCrihfield</dc:creator>
    <dc:date>2022-10-26T14:47:05Z</dc:date>
    <item>
      <title>Creating a "dynamic" user parameter</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-a-quot-dynamic-quot-user-parameter/m-p/11509093#M31308</link>
      <description>&lt;P&gt;I am trying to create a script that turns the part number into a user parameter. The reason is that I want to use the part number in a text field on an .idw. Creating a parameter allows me to do this. Since I do not want endless amounts of these parameters I thought about deleting the parameter if it exists and then create it again.&lt;/P&gt;&lt;P&gt;So far I came up with the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Dim PartNumber As Parameter
'Define parameter in the current user parameters of the current document
Param = ThisApplication.ActiveDocument.ComponentDefinition.Parameters
UserParam = Param.UserParameters

For Each UserParam In Param
	'Check if the parameter PartNumber exists
	If UserParam.Name = "PartNumber"
		'Delete the parameter if it does exist
		Parameter.Param("PartNumber").Delete
	End If
Next

'Create the parameter
PartNumber = UserParam.AddByValue("PartNumber", iProperties.Value("Project", "Part Number"), UnitsTypeEnum.kTextUnits)
'Set a comment
Parameter.Param("PartNumber").Comment = "Set by a rule, do not alter"

'Update file
iLogicVb.UpdateWhenDone = True&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The codes work seperately (meaning the for loop deleting the parameter if it exists works and the creation of the parameter itself works) but together they do not. The error message I get is: "The public member AddByValue for type UserParameter was not found."&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;What am I doing wrong?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 08:54:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-a-quot-dynamic-quot-user-parameter/m-p/11509093#M31308</guid>
      <dc:creator>mrawesomelemons</dc:creator>
      <dc:date>2022-10-26T08:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a "dynamic" user parameter</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-a-quot-dynamic-quot-user-parameter/m-p/11509951#M31309</link>
      <description>&lt;P&gt;In the for each loop where you check if it exist you can use instead of the ilogic snippet.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;UserParam.Delete&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Later you ask for a part number and take it from the drawing document. Will this be where you want to extract that information.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Also have you tried just using a custom iProperty instead of parameter? This would be a more direct route.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 14:30:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-a-quot-dynamic-quot-user-parameter/m-p/11509951#M31309</guid>
      <dc:creator>A.Acheson</dc:creator>
      <dc:date>2022-10-26T14:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a "dynamic" user parameter</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-a-quot-dynamic-quot-user-parameter/m-p/11509986#M31310</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2924318"&gt;@mrawesomelemons&lt;/a&gt;.&amp;nbsp; I agree with that too.&amp;nbsp; I also created a slightly modified version of your code that you can try out, to see if it works any better for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oDoc As Document = ThisDoc.Document
Dim UParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
For Each UserParam As UserParameter In UParams
	If UserParam.Name = "PartNumber" Then UserParam.Delete
Next
Dim PN As String = oDoc.PropertySets.Item(3).Item("Part Number").Value
Dim PNParam As UserParameter = UParams.AddByValue("PartNumber", PN, UnitsTypeEnum.kTextUnits)
PNParam.Comment = "Set by a rule, do not alter"
oDoc.Update&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, keep in mind that if you want to access the parameters in a drawing type document, that type of document does not have a 'ComponentDefinition', so its Parameters are directly under the Document object (DrawingDocument.Parameters.UserParameters).&amp;nbsp; I assumed this code above was working with a Part or an Assembly.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 14:47:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-a-quot-dynamic-quot-user-parameter/m-p/11509986#M31310</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-10-26T14:47:05Z</dc:date>
    </item>
  </channel>
</rss>

