User Parameter link to iproperties

User Parameter link to iproperties

syafiqfarhan
Enthusiast Enthusiast
617 Views
4 Replies
Message 1 of 5

User Parameter link to iproperties

syafiqfarhan
Enthusiast
Enthusiast
Dim oPartDoc As Document
oPartDoc = ThisDoc.Document

If oPartDoc.DocumentType = kPartDocumentObject Then

	Dim oPartCompDef As PartComponentDefinition
		oPartCompDef = oPartDoc.ComponentDefinition
		
Dim oParams As Parameters
		oParams=oPartCompDef.Parameters
				
		Dim oUserParams As UserParameters
		oUserParams=oParams.UserParameters       
		
		Dim oAwesomeParameter As Parameter                     
				
		Try
			otester = oUserParams.Item("Profile")
			Catch
oInsulationType=oUserParams.AddByValue("Profile", "Plate", kTextUnits) 
MultiValue.SetList("Profile", "Plate", "HEA", "HEB", "Pipe", "Sample")
			End Try
            End If

Parameter.Param("Profile").ExposedAsProperty = False
Parameter.Param("Profile").IsKey = True



If oPartDoc.DocumentType = kPartDocumentObject Then

	Dim oPartCompDef As PartComponentDefinition
		oPartCompDef = oPartDoc.ComponentDefinition
		
Dim oParams As Parameters
		oParams=oPartCompDef.Parameters
				
		Dim oUserParams As UserParameters
		oUserParams=oParams.UserParameters       
		
		Dim oAwesomeParameter As Parameter                     
				
		Try
			otester = oUserParams.Item("t")
			Catch
oInsulationType = oUserParams.AddByValue("t", " ", kTextUnits) 
			End Try
            End If

Parameter.Param("t").ExposedAsProperty = False
Parameter.Param("t").IsKey = True

If oPartDoc.DocumentType = kPartDocumentObject Then

	Dim oPartCompDef As PartComponentDefinition
		oPartCompDef = oPartDoc.ComponentDefinition
		
Dim oParams As Parameters
		oParams=oPartCompDef.Parameters
				
		Dim oUserParams As UserParameters
		oUserParams=oParams.UserParameters       
		
		Dim oAwesomeParameter As Parameter                     
				
		Try
			otester = oUserParams.Item("Unit")
			Catch
oInsulationType=oUserParams.AddByValue("Unit", "MM", kTextUnits) 
MultiValue.SetList("Unit", "MM", "INCH", "Sample")
			End Try
            End If

Parameter.Param("Unit").ExposedAsProperty = False
Parameter.Param("Unit").IsKey = True

Hi all, I want to make my "t" value link to my iproperties. Is there a possible way?

syafiqfarhan_0-1639551747346.png

 

 

0 Likes
Accepted solutions (1)
618 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @syafiqfarhan.  Unfortunately, right now, since we can't set either text type or boolean type user parameters for 'export' or 'expose as property', there is not really a way to actually 'link' an iProperty to that parameter.  I have used a fairly simple iLogic rule for such situations for years though, that you might find useful here.  It still doesn't actually create a 'link', but it is the next best thing, because it keeps the iProperty up-to-date with the parameter of the same name.  Here is a link to one of my contribution posts where that code is posted.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

syafiqfarhan
Enthusiast
Enthusiast

@WCrihfield 

is there any possibility to check the value for my property "t" by running a code? so I think we can put its value manually in User Parameter. 

 

And also any method to check both items are the same value?

eg: iproperties "t" = 40 and user parameter size also = 40

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Sure.  There are lots of ways of doing these things, but there is some iLogic code you can use as a starter.  It will try to find both the user parameter and the iProperty, then prepare a report about if they are found, what their values are, and if their values are equal.  I also left some code commented out that will attempt to copy the value of the iProperty to the value of the user parameter if the iProperty is found.  And if the user parameter does not exist yet, it creates it with the same value as the iProperty.  You can un-comment that if you want.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Exit Sub
Dim oPartDoc As PartDocument = ThisDoc.Document

oUParams = oPartDoc.ComponentDefinition.Parameters.UserParameters
Dim oUParam As UserParameter
For Each oUP As UserParameter In oUParams
	If oUP.Name = "t" Then oUParam = oUP
Next

oCProps = oPartDoc.PropertySets.Item("Inventor User Defined Properties")
Dim oCProp As Inventor.Property
For Each oCP As Inventor.Property In oCProps
	If oCP.Name = "t" Then oCProp = oCP
Next

Dim oReport As String
Dim oUPVal, oIPVal As String
If oUParam Is Nothing Then
	oReport = "Parameter = (Not Found)"
Else
	oUPVal = CStr(oUParam.Value)
	oReport = "Parameter = " & oUPVal
End If
If oCProp Is Nothing Then
	oReport = oReport & vbCrLf & "iProperty = (Not Found)"
Else
	oIPVal = CStr(oCProp.Value)
	oReport = oReport & vbCrLf & "iProperty = " & oIPVal
End If
If oUPVal = oIPVal Then
	oReport = oReport & vbCrLf & "They Are Equal"
Else
	oReport= oReport & vbCrLf & "They Are Not Equal"
End If
MsgBox(oReport, , "")

'If oUParam IsNot Nothing And oCProp IsNot Nothing Then
'	oUParam.Value = oIPVal
'ElseIf oUParam Is Nothing And oCProp IsNot Nothing Then
'	oUParam = oUParams.AddByValue("t", oIPVal)
'End If

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

JMGunnar
Collaborator
Collaborator

I  Use  

oUParam.expression = oIPVal

before 

oUParam.Value = oIPVal

 

If oUParam IsNot Nothing And oCProp IsNot Nothing Then
	oUParam.Expression = oIPVal
ElseIf oUParam Is Nothing And oCProp IsNot Nothing Then
	oUParam = oUParams.AddByValue("THICKNESS", oIPVal)
End If

 

 

0 Likes