Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: ABHUT_9090

Hi @ABHUT_9090.  I created something that you may be able to use.

 

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oBOM As BOM = oADef.BOM
	If Not oBOM.StructuredViewEnabled Then oBOM.StructuredViewEnabled = True
	If oBOM.StructuredViewFirstLevelOnly Then oBOM.StructuredViewFirstLevelOnly = False
	Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
	For Each oRow As BOMRow In oBOMView.BOMRows
		Dim oRowDoc As Document = Nothing
		Try
			oRowDoc = oRow.ComponentDefinitions.Item(1).Document
		Catch
			Continue For 'skip to next BOMRow
		End Try
		If IsNothing(oRowDoc) Then Continue For
		Dim oPartLength As Double = 0.0
		Dim oCProps As PropertySet = oRowDoc.PropertySets.Item("Inventor User Defined Properties")
		Try
			oPartLength = oCProps.Item("LENGTH").Value
		Catch
			Continue For 'skip to next BOMRow
		End Try
		If oPartLength = 0.0 Then Continue For 'skip to next BOMRow
		Dim oQty As Integer = oRow.ItemQuantity
		Dim oTotalLength As Double = (oPartLength * oQty)
		'value may need to have units converted if not correct
		Dim oTotalInchCProp As Inventor.Property = Nothing
		Try
			oTotalInchCProp = oCProps.Item("total inch")
			oTotalInchCProp.Value = oTotalLength
		Catch
			oTotalInchCProp = oCProps.Add(oTotalLength, "total inch")
		End Try
	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) :thumbs_up:.

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)