- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have 2 different codes that I wish to combine but I am having quite a bit of trouble. Each code works perfectly fine on their own but I need to combine them in order to do what I want. The first code adds up the "weights" of each component (ipart, iassembly, and CC component) within the assembly based off a custom iproperty, if a component does not have this iproperty it prompts the user to input one. This total is then presented to the user.
Class ThisRule
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 oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
oWeightList = New List(Of Double)
RecursivelyProcessComponents(oOccs)
Dim oTotaliPartsWeight As Double = oWeightList.Sum
MsgBox("Total Tool Weight = " & oTotaliPartsWeight & " kg", vbInformation, "Total Tool Weight")
End Sub
Dim oWeightList As List(Of Double)
Sub RecursivelyProcessComponents(oComps As ComponentOccurrences)
If oComps Is Nothing OrElse oComps.Count = 0 Then Exit Sub
For Each oComp As ComponentOccurrence In oComps
If oComp.Suppressed Then Continue For
If TypeOf oComp.Definition Is VirtualComponentDefinition Then Continue For
If TypeOf oComp.Definition Is WeldsComponentDefinition Then Continue For
Dim oCompDoc As Document = Nothing
Try : oCompDoc = oComp.Definition.Document : Catch : End Try
If oComp.IsiAssemblyMember Then
Dim oMember As iAssemblyMember = oComp.Definition.iAssemblyMember
oWeightList.Add(CDbl(oMember.Row.Item("Weight [Custom]").Value))
ElseIf oComp.IsiPartMember Then
Dim oMember As iPartMember = oComp.Definition.iPartMember
oWeightList.Add(CDbl(oMember.Row.Item("Weight [Custom]").Value))
Else 'it is not iAssemblyMember or iPartMember
Dim bCCMember As Boolean = False
Try : bCCMember = oComp.Definition.IsContentMember : Catch : End Try
If bCCMember = True Then
Dim oPropValue As Object = Nothing
Try : oPropValue = oCompDoc.PropertySets.Item(4).Item("Weight").Value : Catch : End Try
Try : oWeightList.Add(CDbl(oPropValue)) : Catch : End Try
Else 'it is not an iAssemblyMember, not an iPartMember, and not Content Center member
Dim Result As Integer
Result = MessageBox.Show("Would You Like To Input a Temporary Weight For This Part?", _
"No Part Weight Detected for '" & oComp.Name & "'", MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
If Result = 6 Then
Dim Returnmyparam As String = InputBox("Input Weight in kg ", "Weight Input Prompt for '" & _
oComp.Name & "'", "")
'If Returnmyparam = "" Then Continue For
Dim oWeightCProp As Inventor.Property = Nothing
Try
oWeightCProp = oCompDoc.PropertySets.Item(4).Item("Weight")
Catch
oWeightCProp = oCompDoc.PropertySets.Item(4).Add(CDbl(Returnmyparam), "Weight")
End Try
oWeightList.Add(CDbl(Returnmyparam))
ElseIf Result = 7 Then
ElseIf Result = 2 Then
Return
End If
End If
End If
Next
End Sub
End Class
The second code is separate due to specific Content Center Components being structural shapes with a user inputted length and therefore cannot work the same way using the "weight" custom iproperty. Instead this code simply takes the components masses and adds them up.
Sub Main
Dim doc As AssemblyDocument = ThisApplication.ActiveDocument
Dim occs As ComponentOccurrences = doc.ComponentDefinition.Occurrences
Dim mass As Double
For Each refDoc As Document In doc.AllReferencedDocuments
If TypeOf refDoc Is AssemblyDocument Then Continue For
If Not refDoc.ComponentDefinition.IsContentMember Then Continue For
Dim list As New List(Of String)
list.Add("Profile 1")
list.Add("Profile 2")
list.Add("Profile 3")
list.Add("Profile 4")
list.Add("Profile 5")
list.Add("Profile 6")
list.Add("Profile 7")
list.Add("Profile 8")
list.Add("Profile 9")
list.Add("Profile 10")
list.Add("Profile 11")
Dim check As Boolean = False
For Each s As String In list
If refDoc.DisplayName.Contains(s) Then
check = True
Exit For
End If
Next
If check = False Then Continue For
Dim qty As Integer = occs.AllReferencedOccurrences(refDoc).Count
mass += refDoc.ComponentDefinition.MassProperties.Mass * qty
Next
MessageBox.Show(mass & " kg")
End Sub
I am looking to combine these 2 codes in order to get a grand total. I am not a very experienced coder so in-depth help would be greatly appreciated. Please let me know if you have any further questions. Thank you!
Solved! Go to Solution.