Hi @Innercia
Try out the below code. Check the "Make the new changes" lines to ensure you know what the new changes will be and also check you are targeting the right user parameter. It is currently set up for mm conversion. I suggest to test on a small non production assembly to ensure you know what the changes will be.
Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oTransaction As Transaction = ThisApplication.TransactionManager.StartTransaction(oAsm, "FG Updates") 'Make this a single transaction
For Each oDoc As Document In oAsm.AllReferencedDocuments 'Traverse all referenced documents
If oDoc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") _' Frame generator component
AndAlso oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject _ 'Part
AndAlso oDoc.IsModifiable _'Not read only CC/Library document
AndAlso Not oDoc.DocumentInterests.HasInterest("SkeletonDoc") _'(not reference skeleton)
AndAlso oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc).Count > 0 'Exists in assembly (not derived base component)
oDoc = TryCast(oDoc, PartDocument)
Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oUserParam As UserParameter = oCompDef.Parameters.UserParameters.Item("G_L")
'Delete parameter expression and add back in to force an update to occur e.g precision to become active
Dim currentValue As String = oUserParam.Expression
oUserParam.Expression = "0"
oUserParam.Expression = currentValue
'Make the new changes
oUserParam.Precision = 0
oUserParam.ExposedAsProperty = True
oUserParam.IsKey = False
oUserParam.CustomPropertyFormat.Precision = kZeroDecimalPlacePrecision
oDoc.UnitsOfMeasure.LengthDisplayPrecision = 0
oDoc.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMillimeterLengthUnits
oCompDef.BOMQuantity.BaseUnits = "mm"
oCompDef.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kParameterBOMQuantity, oUserParam)
'Read the new changes
'Logger.Info("BASE QTY: " & oCompDef.BOMQuantity.GetEvaluatedBaseQuantity(BOMQuantityTypeEnum.kParameterBOMQuantity))
'Logger.Info("UNIT QTY: " & oCompDef.BOMQuantity.UnitQuantity)
'Customize part numbers
'oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = oDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value
End If
Next
oAsm.Update
oTransaction.End 'End the trasaction
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan