Hi, I have followed your threads about the subject. I've noticed that when it comes to property in phantom, you can use the bill of materials property of the part, you may not have to read it from the property of assembly list model data.
I have found a result but my limitations in programming have not been able to insert it within the rule that you need.
First of all, I think that in order to find father of the father you should use something like this, try it with a large assembly and choose the piece in which your father is phantom, and he will give you back the next father who is not a phantom.
Sub Main()
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oPart As ComponentOccurrence
'Pick part occurrence
oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Seleccione Pieza")
If oPart Is Nothing Then
Exit Sub
Else
Dim partname As String = oPart.Definition.Document.Displayname
MessageBox.Show("the origin part is" & partname, "Title")
Dim Parent As Document = oPart.Definition.Document.ReferencingDocuments.Item(1)
Dim oParentnameA As String = Parent.DisplayName
MessageBox.Show("parent component searched " & oParentnameA, "Title")' parent component searched, should not be phantom
Dim oBOM As BOM
oBOM = ThisApplication.ActiveDocument.ComponentDefinition.BOM
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Unnamed")'Accesing to Model data Column
Call FindParent(oBOMView.BOMRows, 0, oParentnameA )
End If
End Sub
Sub FindParent(Rows As BOMRowsEnumerator, indent As Integer, oParentnameA As String)'
Dim oBOMRow As BOMRow
For Each oBOMRow In Rows
Dim oDef As ComponentDefinition
oDef = oBOMRow.ComponentDefinitions(1)
Dim oParentName As String = oDef.Document.Displayname
If oParentName <> oParentnameA Then
If Not oBOMRow.ChildRows Is Nothing Then
Call FindParent(oBOMRow.ChildRows, indent + 1,oParentnameA)
End If
End If
If oParentName = oParentnameA Then
Dim oBOMStructnumber As String
oBOMStructnumber = oBOMRow.BOMStructure
Dim BOM_Structure As String
If oBOMStructnumber = 51969 Then BOM_Structure = "The Default Structure Type"
If oBOMStructnumber = 51974 Then BOM_Structure = "The inseparable Structure Type"
If oBOMStructnumber = 51970 Then BOM_Structure = "The normal Structure Type"
If oBOMStructnumber = 51971 Then BOM_Structure = "The phantom Structure Type"
If oBOMStructnumber = 51973 Then BOM_Structure = "The purchased Structure Type"
If oBOMStructnumber = 51972 Then BOM_Structure = "reference Structure Type"
If oBOMStructnumber = 51975 Then BOM_Structure = "The Structure Type varies amongst references"
If oBOMStructnumber = 51971 Then
Dim oDocFile As Document
oDocFile = oDef.Document
Dim Parent As Document = oDocFile.ReferencingDocuments.Item(1)
oParentnameA=Parent.DisplayName
Dim oBOM As BOM
oBOM = ThisApplication.ActiveDocument.ComponentDefinition.BOM
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Unnamed")'Accesing to Model data Column
Call FindParent(oBOMView.BOMRows, 0, oParentnameA )
End If
If oBOMStructnumber <> 51971 Then
MessageBox.Show("the parent is " & oParentnameA & "@" & BOM_Structure, "Title")
End If
End If
Next
End Sub
The problem is that once found the value, we should cut the loop, maybe with "exit for" and if instead of a "sub" we use a "function" we could add a "return" and return the value to the sub that we need. I have tried without success, maybe you or maybe the teacher @chandra.shekar.g tell us how to do it if that is the way to the result, or maybe to throw a simpler way.
Regarding the amount I can see, I have not inquired into it yet, regards
Please accept as solution and give likes if applicable.
I am attaching my Upwork profile for specific queries.
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn