Inventor crashing when adding a partdocument with unresolved links

Inventor crashing when adding a partdocument with unresolved links

Daan_M
Collaborator Collaborator
146 Views
1 Reply
Message 1 of 2

Inventor crashing when adding a partdocument with unresolved links

Daan_M
Collaborator
Collaborator

Hi,

 

I've got a code that mirrors all partfiles in a folder, but i notice Inventor keeps crashing when a partfile with unresolved link goes through the loop.

 

Not sure what causes the error but it's probably when the derive takes place.

 

It could be solved by breaking all links in the main for each loop, before calling the private function.

 

How can i solve this in the best way?

 

Full code:

 

Imports System.Windows.Forms
Imports System

Sub Main
	oInvApp = ThisApplication
	Dim oTemplate As String = "Templates\Standard.ipt"
	
	Dim oFBD = New FolderBrowserDialog()
	oFBD.ShowDialog()
	oFBD.SelectedPath	
	If String.IsNullOrEmpty(oSFolder) Then Exit Sub
	Dim oFiles() As String = IO.Directory.GetFiles(oSFolder, "*.ipt")
	If oFiles.Length = 0 Then Exit Sub
	Dim i As Integer = -1 
	
	
		For Each oFile In oFiles
			
			i = i + 1	
			
			Dim oFileName As String = IO.Path.GetFileName(oFiles(i))
			Dim oFileNameWE As String = IO.Path.GetFileNameWithoutExtension(oFiles(i))
			Call MirDer(oFiles(i), oFileNameWE, oSFolder)

		
		On Error Resume Next 

		Next
	
	
End Sub
	
	Dim oInvApp = ThisApplication
	
Private Function MirDer(ByVal oFileName As String, ByVal oFileNameWE As String, ByVal oSFolder As String)
	
	Dim CopyDoc As PartDocument = oInvApp.Documents.Add(kPartDocumentObject, oTemplate, False)
	Dim oPCD As Inventor.PartComponentDefinition = CopyDoc.ComponentDefinition
	Dim oDPD As Inventor.DerivedPartDefinition 
	oDPD = oPCD.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(oFileName)
	oDPD.IncludeAllSolids = DerivedComponentOptionEnum.kDerivedIncludeAll
	
	
	oDPD.MirrorPlane = kDerivedPartMirrorPlaneXY
	
	Dim oDPC As DerivedPartComponent = oPCD.ReferenceComponents.DerivedPartComponents.Add(oDPD)
 	oDPC.BreakLinkToFile()
	
	CopyDoc.Update()
	
	Dim OutputFolder As IO.DirectoryInfo = IO.Directory.CreateDirectory(oSFolder & "\Output")
	CopyDoc.SaveAs(OutputFolder.FullName & "\" & oFileNameWE & "_MIRROR_.ipt", False)
	CopyDoc.Close(True)
	
End Function

 

 

0 Likes
147 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor

Hi @Daan_M 

 

Maybe you can have a look at the reference file descriptors for the part file. If they don't exist then there is an issue.

See forum post here.  

As an alternative work around you could wrap the call of the function in a try catch statement or if that doesn't work go into where the issue is which is creating the DerivedPartDefinition.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes