05-24-2022
11:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
05-24-2022
11:00 AM
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)
.
If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)