CHANGE CUSTOMPROPERTY FORMAT IN ASSEMBLY ENVIROMENT

CHANGE CUSTOMPROPERTY FORMAT IN ASSEMBLY ENVIROMENT

Innercia
Explorer Explorer
312 Views
1 Reply
Message 1 of 2

CHANGE CUSTOMPROPERTY FORMAT IN ASSEMBLY ENVIROMENT

Innercia
Explorer
Explorer

Hi, Im try to change g_l Properties for a frame placed, by assembly enviroment. I can Do it 1 by 1 parts, but i need to do n the general assembly.

Code for parts.

Sub MAIN()
	oMyParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
	 oParameter = Parameter.Param("B_L")
        oParameter.ExposedAsProperty = True
        oParameter.IsKey = False
oParameter.CustomPropertyFormat.Precision = kZeroDecimalPlacePrecision


End Sub   

code For assembly Doent works...
Sub MAIN()
	Dim oDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
	Dim oOcc As ComponentOccurrence
	For Each oOcc In oDef.Occurrences
	Try
	oParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
		 oParameter = Parameter.Param("B_L")
        oParameter.ExposedAsProperty = True
        oParameter.IsKey = False
oParameter.CustomPropertyFormat.Precision = kZeroDecimalPlacePrecision
RuleParametersOutput()
Catch
	MessageBox.Show(oOcc.Name & " does not have the parameter named as G_L")
	
	End Try

Next
InventorVb.DocumentUpdate
End Sub

 

0 Likes
Accepted solutions (1)
313 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor
Accepted solution

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
0 Likes