iProperty and User Parameter creation with iLogic

iProperty and User Parameter creation with iLogic

To_Efficiency_and_Beyond
Enthusiast Enthusiast
1,004 Views
10 Replies
Message 1 of 11

iProperty and User Parameter creation with iLogic

To_Efficiency_and_Beyond
Enthusiast
Enthusiast

I am working on an external rule that is set to run when opening any .ipt or .iam file. This rule checks existence of some properties and creates them if needed. This will be a big time saver for us as we revamp our system. Most of the rule is working as expected.

The issue is that the entire section involving Model Type fails. It will not create the multi-value custom parameter, nor will it create the custom iProperty. Any suggestions on where I went wrong would be super helpful!

doc = ThisDoc.Document
customPropertySet = doc.PropertySets.Item("Inventor User Defined Properties")
Dim TextValue As String
Dim NumValue As Double
Dim DateValue As Date
Dim YesNoValue As Boolean

'[Make sure Finish property exists
Try
      prop = customPropertySet.Item("Finish")
Catch
      'Assume error means not found
      customPropertySet.Add(TextValue, "Finish")
End Try
']
'[Make sure Model Type property exists
Try
      prop = customPropertySet.Item("Model Type")
Catch
	'Assume error means not found
	Dim ParamName As String = "ModelType"
	Dim oComp As PartComponentDefinition = doc.ComponentDefinition
	Dim oUPs As UserParameters = oComp.Parameters.UserParameters
	Dim oUP As UserParameters
	Dim List1 As New ArrayList
		List1.Add("NORMAL")
		List1.Add("REFERENCE")
		List1.Add("FIXTURE")
		
	Try
		Test = oUPs.Item(ParamName).Value
	Catch		
		oUP = oUPs.AddByExpression(ParamName, List1.Item(0), UnitsTypeEnum.kTextUnits)
	End Try
	
	customPropertySet.Add("", "Model Type")
End Try
']
'[Make sure Tool MFG property exists
Try
      prop = customPropertySet.Item("Tool MFG")
Catch
      'Assume error means not found
      customPropertySet.Add(TextValue, "Tool MFG")
End Try
']
'[Make sure Tool Model property exists
Try
      prop = customPropertySet.Item("Tool Model")
Catch
      'Assume error means not found
      customPropertySet.Add(TextValue, "Tool Model")
End Try
']

 

0 Likes
Accepted solutions (2)
1,005 Views
10 Replies
Replies (10)
Message 2 of 11

WCrihfield
Mentor
Mentor

Hi @To_Efficiency_and_Beyond.  I believe I know what is going wrong with your rule code.  Too many document variables near the start.  You are using your "doc" variable to get the custom iProperties PropertySet, but you are trying to use the "oDoc" variable, which has no value set to it, to get the PartComponentDefinition, then the UserParameters.  That will not work.  Use the "doc" variable there, instead of the "oDoc" variable.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 11

To_Efficiency_and_Beyond
Enthusiast
Enthusiast

@WCrihfield I gave that a try, still errors out. Also should note that this is an external rule (it seems to matter sometimes).

I updated the original post with the code cleaned up a bit.

0 Likes
Message 4 of 11

A.Acheson
Mentor
Mentor
Accepted solution

A few other things

1. The parameter name(ParamName)  cannot have spaces like the parameter value/iproperty. Change to "ModelType"

Dim ParamName As String = "Model Type"

 

2. The multivalue text parameter can't be set using a standard array. 

Dim List1 As New ArrayList
		List1.Add("NORMAL")
		List1.Add("REFERENCE")
		List1.Add("FIXTURE")
		

There is a special method using extra quotes which isn't very user friendly, so instead use the ilogic snippet

MultiValue.SetList(“ModelType”, "NORMAL", "REFERENCE", "FIXTURE")

 

3. The code is set up to add a parameter to a part only.

Dim oComp As PartComponentDefinition = doc.ComponentDefinition

It will fail for an assembly. You can convert oComp declaration to the generic base class "ComponentDefinition" see link to API help.

This way you can work with either an assembly or part. 

 

4. Also as an addition it would be good practice to declare the property set and or the property.  This way you gain access to the underlying methods and properties without having to refer to documentation  etc. 

Dim customPropertySet as PropertySet
Dim prop as [Property]

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 11

To_Efficiency_and_Beyond
Enthusiast
Enthusiast

1. I found this mistake just before you replied 🙂

2. My understanding is that the process here would be to first create the user parameter as a text type, then use the multi-value snippet to convert and fill values.. is this correct? If so, I am still struggling with creating the user parameter initially. Please advise.

3. Fixed! Thanks for spotting this!

4. The first part makes sense:

Dim customPropertySet as PropertySet

For the second part, are you suggesting that I use it in this exact form, including brackets? or are you suggesting that I choose something to replace the bracketed portion? If it is the later, I am lost 😞

0 Likes
Message 6 of 11

To_Efficiency_and_Beyond
Enthusiast
Enthusiast
Accepted solution

Update... I got it mostly fixed!

It creates the parameter, it creates most or all of the custom iproperties.

Depending on what iproperties(s) already exist, it will choose a (seemingly) random iproperty creation line and throw an error. It may or may not create the iproperty that throws the error.

To fix the issue, I defined a blank value:

Dim TextValue As String = ""

Here is the finish product:

doc = ThisDoc.Document
Dim customPropertySet As PropertySet = doc.PropertySets.Item("Inventor User Defined Properties")
Dim TextValue As String = ""
'Dim NumValue As Double
'Dim DateValue As Date
'Dim YesNoValue As Boolean

'[Make sure Finish property exists
Try
	prop = customPropertySet.Item("Finish")
Catch
	'Assume error means not found
	customPropertySet.Add(TextValue, "Finish")
End Try
']

'[Make sure Model Type property exists
Try
	prop = customPropertySet.Item("Model Type")
Catch
	'Assume error means not found
	Dim ParamName As String = "ModelType"
	Dim oComp As ComponentDefinition = doc.ComponentDefinition
	Dim oUPs As UserParameters = oComp.Parameters.UserParameters

	Try
		Test = oUPs.Item(ParamName).Value
	Catch
		oUPs.AddByValue(ParamName, "NORMAL", UnitsTypeEnum.kTextUnits)
		MultiValue.SetList(“ModelType”, "NORMAL", "REFERENCE", "FIXTURE")
	End Try

	customPropertySet.Add(TextValue, "Model Type")
End Try
']

'[Make sure Tool MFG property exists
Try
	prop = customPropertySet.Item("Tool MFG")
Catch
	'Assume error means not found
	customPropertySet.Add(TextValue, "Tool MFG")
End Try
']

'[Make sure Tool Model property exists
Try
	prop = customPropertySet.Item("Tool Model")
Catch
	'Assume error means not found
	customPropertySet.Add(TextValue, "Tool Model")
End Try
']
0 Likes
Message 7 of 11

A.Acheson
Mentor
Mentor

Here are two ways to  correctly declare for a property object. Just place it at the top of the rule. Then you can access all of the properties and methods.

AAcheson_0-1661535257524.png

 

1.

Dim prop as [Property]

 2.

Dim prop as inventor.Property

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 8 of 11

To_Efficiency_and_Beyond
Enthusiast
Enthusiast

@A.Acheson wrote:

2. The multivalue text parameter can't be set using a standard array. 

Dim List1 As New ArrayList
		List1.Add("NORMAL")
		List1.Add("REFERENCE")
		List1.Add("FIXTURE")
		

There is a special method using extra quotes which isn't very user friendly, so instead use the ilogic snippet

MultiValue.SetList(“ModelType”, "NORMAL", "REFERENCE", "FIXTURE")

 


Coming back to this point for a something new that I am working on.. can you think of any way around this? It would be very helpful to auto-compile a list from an ilogic rule and then have it update a multi-value parameter. See example:

 

... many entries

ElseIf
Parameter("Size") = "1/8 STD PIPE" Then Parameter("ODDim") = 0.405 Parameter("WallDim") = 0.088 iProperties.Value("Custom", "Nominal Size") = a iProperties.Value("Custom", "SCH") = STD ElseIf Parameter("Size") = "1/8 XS PIPE" Then Parameter("ODDim") = 0.405 Parameter("WallDim") = 0.095 iProperties.Value("Custom", "Nominal Size") = a iProperties.Value("Custom", "SCH") = XS

... many more entries

Auto-compile a list consisting of each Parameter("Size") value, then populate the multi-value list in the actual Size parameter.

The reason this would be so advantageous is that this part template is managed via an external rule. Adding a new size to the external rule could then update all of the parts that it controls when they are opened.

 

Thoughts? 😋

0 Likes
Message 9 of 11

A.Acheson
Mentor
Mentor

Just a one liner needed. 

'Set MultiValue Parameter From arraylist
MultiValue.List("Size") = List1

And an example here notice the use of New List instead of New Arraylist. Just another more specific way to right a list of string. 

Dim List1 As New List(Of String)
List1.Add("NORMAL")
List1.Add("REFERENCE")
List1.Add("FIXTURE")

'Set MultiValue Parameter From arraylist
MultiValue.List("Size") = List1

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 10 of 11

To_Efficiency_and_Beyond
Enthusiast
Enthusiast

That makes sense.

I am having difficulty writing something to search through the rule and compile that list.

Say I want to search through the last piece of code I posted and find all the size values, in this case  "1/8 STD PIPE" and "1/8 XS PIPE" and add them to the list. How would you do that?

0 Likes
Message 11 of 11

A.Acheson
Mentor
Mentor

It sounds like this should be done manually by the user. It is rare that you update a multivalue list often. Your code is manually typed in and is built around what is contained in the list. You can update the multivalue list directly from excel if you want. maybe you can post the code your using to clarify the workflow your attempting.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes