CHANGE USER PAREMETERS UNIT

CHANGE USER PAREMETERS UNIT

Luis_Pacheco_3D
Advocate Advocate
917 Views
3 Replies
Message 1 of 4

CHANGE USER PAREMETERS UNIT

Luis_Pacheco_3D
Advocate
Advocate

I need to change User parameter units for all parts of my assemblie without opening each one sepárately.

 

Dim oParam As Parameter
Dim oParamFormat As CustomPropertyFormat

Try
oParam = Parameter.Param("Height")
oParam.ExposedAsProperty = True
oParamFormat = oParam.CustomPropertyFormat
oParamFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
Catch
End Try


Try
oParam = Parameter.Param("Width")
oParam.ExposedAsProperty = True
oParamFormat = oParam.CustomPropertyFormat
oParamFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
Catch
End Try

 Currently, I use this rule but it only works on active file and I waste time opening one by one.

0 Likes
Accepted solutions (1)
918 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Luis_Pacheco_3D.  I wasn't sure if your assembly included any sub-assemblies or not, or if you wanted them to be processed, or if you only wanted just the actual parts only to be effected, or how many levels down you wanted this code to effect, so I just set it up to attempt to process 'all referenced documents' of the main assembly.  That will encompass all sub-assemblies and all parts at all levels of the assembly.  I used a separate Sub routine to do the bulk of the work, to leave the main Sub cleaner and shorter.

This iLogic rule should do the trick.

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	SetParamProps(oADoc, "Height")
	SetParamProps(oADoc, "Width")
	For Each oRefDoc As Document In oADoc.AllReferencedDocuments
		SetParamProps(oRefDoc, "Height")
		SetParamProps(oRefDoc, "Width")
	Next
End Sub

Sub SetParamProps(oDoc As Document, oParamName As String)
	If Not (TypeOf oDoc Is PartDocument) And Not (TypeOf oDoc Is AssemblyDocument) Then Exit Sub
	For Each oParam As Inventor.Parameter In oDoc.ComponentDefinition.Parameters
		If oParam.Name = oParamName Then
			If Not oParam.ExposedAsProperty Then
				oParam.ExposedAsProperty = True
			End If
			Try
				oParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
			Catch oEx As Exception
				'MsgBox(oEx.Message & vbCrLf & oEx.StackTrace,,"")
			End Try
		End If
	Next
End Sub

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)

Message 3 of 4

Luis_Pacheco_3D
Advocate
Advocate
Thank you. It works.

If I want to change all the user parameters there are, without having to put the existing ones in the rule, is it possible?

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

It may be possible to set up that way, but the rule's code would definitely have to change.  If any documents have any text type or boolean type parameters, those can't be 'exposed as property' yet, because that is not supported in either the Parameters dialog or in the API yet.  So if you are planning on exposing all user parameters as custom iProperties, you will have to filter those out.  You could still work around this issue and create a custom iProperty with the same name and value as the text or boolean type parameter, but it won't be kept automatically up to date like the other numerical ones that are 'exposed' are.  This deeper updating issue can also be dealt with using events, but that's a more complex issue for another time.  Would you want this new version of the rule to do the exact same thing, just without specifying any parameter names and have it attempt to process all UserParameters instead?  And would you want the code to create those custom iProperties for any of the text or boolean type user parameters it comes across, even though they won't be kept up-to-date?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes