Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, i wrote / copy-paste a simple rule that read a quantity in a part and set some value in custom iPropriety.
Work well in part contest but now i need to iterate the rule in all the part in assembly.
I try some code but whitout any result. Someone can help?
This is the rule that work fine in the part component:
Dim oPart As PartDocument = ThisApplication.ActiveEditDocument Dim oCompDef As PartComponentDefinition = oPart.ComponentDefinition Dim baseUnits As String = oCompDef.BOMQuantity.BaseUnits Dim unitQuantity As String = oCompDef.BOMQuantity.UnitQuantity 'Dim quantityType As String = oCompDef.BOMQuantityTypeEnum Dim quantity As Object = Nothing MessageBox.Show(unitQuantity, "unitQuantity") If baseUnits = "mm" Then Dim UQN As Integer = InStrRev(unitQuantity," ",-1) UQ = Left(unitQuantity,UQN) DIMENSIONI = CDblAny(UQ) QTA = CStr(CDblAny(UQ)/1000) For i=1 To Len(QTA) If Mid$(QTA, i, 1)= "," Then Mid$(QTA, i, 1) = "." Next MessageBox.Show(DIMENSIONI, "UQ") MessageBox.Show(QTA, "QTA") iProperties.Value("Custom", "QTA") = QTA iProperties.Value("Custom", "DIMENSIONI") = DIMENSIONI End If
And this is the try for iterate in all the part in assembly that don't work:
Sub Main () Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument Dim oAsmDef As AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition Dim oLeafOccs As ComponentOccurrencesEnumerator oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences Dim oOcc As ComponentOccurrence Dim oBrowserNode As String For Each oOcc In oLeafOccs Try Dim baseUnits As String = oOcc.ComponentDefinition.BOMQuantity.BaseUnits Dim unitQuantity As String = oOcc.ComponentDefinition.BOMQuantity.UnitQuantity 'Dim quantityType As String = oCompDef.BOMQuantityTypeEnum 'MessageBox.Show(unitQuantity, "unitQuantity") If baseUnits = "mm" Then Dim UQN As Integer = InStrRev(unitQuantity," ",-1) Dim UQ As String = Left(unitQuantity,UQN) Dim DIMENSIONI As String = CDblAny(UQ) Dim QTA As Integer = CStr(CDblAny(UQ)/1000) For i=1 To Len(QTA) If Mid$(QTA, i, 1)= "," Then Mid$(QTA, i, 1) = "." Next oOcc.iProperties.Value("Custom", "QTA") = QTA oOcc.iProperties.Value("Custom", "DIMENSIONI") = DIMENSIONI End If Catch 'Do Nothing End Try Next End Sub
Solved! Go to Solution.