Message 1 of 2
Inventor crashing when adding a partdocument with unresolved links
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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