Message 1 of 9
iLogic: Find Parent of derived part with broken link in an assembly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
in an assembly I'm trying to find derived parts with a broken link. These should be listed to an Excel file along with the file name of the missing parent.
This is what I already figured out with the help of this forum. But now I'm struggeling to list the name of the parent as well:
Dim RefPartList, RefPartSourceList As New ArrayList()
Dim XLSXfolder, XLSXfileName, XLSXfile, XLSXtable As String
Dim XLSXrowBegin, XLSXrow As Integer
'Find derived parts with broken link to parent
Dim doc As AssemblyDocument = ThisDoc.Document
Dim partDefs = doc.AllReferencedDocuments.Cast(Of Document).
Where(Function(refDoc) refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject).
Where(Function(refDoc) refDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count <> 0).
Where(Function(refDoc) refDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1).LinkedToFile <> True).
ToList()
For Each refDoc As PartDocument In partDefs
RefPartList.Add(refDoc)
Next
'Find derived parts with broken link to parent
'*************
'Add code here
'*************
'Excel Export
XLSXfolder = "C:\temp\"
XLSXfileName = "test.xlsx"
XLSXfile = XLSXfolder & XLSXfileName
XLSXtable = "Tabelle1"
XLSXrowBegin = 1
XLSXrow = XLSXrowBegin + 1
GoExcel.CellValue(XLSXfile, XLSXtable, "A" & XLSXrowBegin) = "Derived Part with missing reference to parent"
GoExcel.CellValue(XLSXfile, XLSXtable, "B" & XLSXrowBegin) = "Missing parent"
'Derived Part with missing reference to parent
XLSXrow = XLSXrowBegin + 1
For Each refDoc In RefPartList
CellFileName = "A" & XLSXrow
GoExcel.CellValue(XLSXfile, XLSXtable, CellFileName) = refDoc.DisplayName
XLSXrow = XLSXrow + 1
Next
'Missing parent
XLSXrow = XLSXrowBegin + 1
For Each refDocMis In RefPartSourceList
CellFileName = "B" & XLSXrow
GoExcel.CellValue(XLSXfile, XLSXtable, CellFileName) = oParent
XLSXrow = XLSXrow + 1
Next
GoExcel.Save
MessageBox.Show("Done", ":-)", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
Any help is much appreciated. Have a merry Christmas.
Best regards
Fabian