iLogic: Find Parent of derived part with broken link in an assembly

iLogic: Find Parent of derived part with broken link in an assembly

fabimann
Contributor Contributor
930 Views
8 Replies
Message 1 of 9

iLogic: Find Parent of derived part with broken link in an assembly

fabimann
Contributor
Contributor

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

0 Likes
931 Views
8 Replies
Replies (8)
Message 2 of 9

Michael.Navara
Advisor
Advisor

Once the link to file is broken, you are not able to restore them and also read any information about them. Only DerivedPartComponent.Name remains (something like Part1.ipt)

 

0 Likes
Message 3 of 9

fabimann
Contributor
Contributor

Does DerivedPartComponent.Name refer to the the name of the parent? Not sure if that is described properly, I'm looking for the name of the parent or base-component as marked below. As the name is stated in the Inventor-browser I assume that it could be read out using iLogic or am I wrong?

 

Thanks

 

Unbenannt.PNG

0 Likes
Message 4 of 9

Ralf_Krieg
Advisor
Advisor

Hello

 

The DerivedPartComponent.Name is AFAIK the DisplayName of the part document. This can be the document name, but can also be something different. If you don't override the display name, it is the document name by default.


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 5 of 9

fabimann
Contributor
Contributor

Hello Michael,

thanks, I'll give it a try after the holidays.

Best regards

Fabian

0 Likes
Message 6 of 9

fabimann
Contributor
Contributor

Happy new year 🙂

 

So DerivedPartComponent.Name is the basically what I am looking for. I understand that it might not  state the actual filename, if the component has been renamed in the Inventor browser.

 

It might still be useful as a hint to look further into an error. So I'd also like to export that data into the Excel-tabel. Unfortunately I'm not able to do so, could you please help again and adapt the code above.

 

Thanks

Fabian

0 Likes
Message 7 of 9

Ralf_Krieg
Advisor
Advisor

Hello

 

Did you find a solution? Sorry, I'm very late. Just lost focus on this thread.

One possible solution is to grab the filename out of the feature name.

Dim RefPartList, RefPartSourceList As New ArrayList()
Dim XLSXfolder, XLSXfileName, XLSXfile, XLSXtable As String
Dim XLSXrowBegin, XLSXrow As Integer

break
'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()

Dim oRefFeature As ReferenceFeature
For Each refDoc As PartDocument In partDefs
    'Add derived part to list    
    RefPartList.Add(refDoc)	
	
    'get reference feature in derived part (assuming there's just one)
	oRefFeature = refDoc.Componentdefinition.Features.ReferenceFeatures.Item(1)
    'Add missing file to list
	RefPartSourceList.Add( Split(oRefFeature.Name,":").Last)
Next

'Excel Export

XLSXfolder = "C:\temp\"
XLSXfileName = "temp.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) = refDocMis 
	XLSXrow = XLSXrow + 1
Next

GoExcel.Save

MessageBox.Show("Done", ":-)", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)

R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 8 of 9

fabimann
Contributor
Contributor

Hello,

thanks for getting back on this topic. I tried to find a solution with your hints but was not able to get it to work. I will try your code after my holiday.

Thanks again

Fabian

0 Likes
Message 9 of 9

fabimann
Contributor
Contributor

Hello @Ralf_Krieg ,

sorry for my late reply, it took some time to catch up after the holidays. Unfortunately your code doesn't work with my assembly. I commented out parts of the code, it seems that one problems starts with:

 

oRefFeature = refDoc.ComponentDefinition.Features.ReferenceFeatures.Item(1)

 

Did the code work with your assembly, what could cause this error?

 

Thank you

Fabian

0 Likes