I have a C++ code which I use to open an assembly file via the Application.Documents.Open method. Before opening the file, however, I would like to be able to determine if all references (i.e. all the individual part files making up the assembly) can be found. At the point of the code where I would need to make this determination, I have the Application object and the name of the assembly file that I wish to open. Is there an API function which will allow me to make the necessary determination prior to calling the Application.Documents.Open method? That way, if there are unresolved references, I can choice not to call the method and simply return from my code with an approprite error message. Thanks!
Hi Sanjay,
i have a similar problem.
Did you find a solution for this?
regards,
Geert
Hey, I don't know about C++, but you can try to translate this (VB.Net):
'You have to set up iApp first, eighter use active inventor or Apprentice server Dim oDoc As Inventor.Document = iApp.Documents.Open("MyDocPath", False) Dim oRefFile As FileDescriptor For Each oRefFile In oDoc.File.ReferencedFileDescriptors Dim FilePath As String = oRefFile.FullFileName If Not System.IO.File.Exist(FilePath) Then 'File doesn't exist. 'Here you can place some kind of code that would look for the file in another folder. End If Next oDoc.Close(False) 'Close the iApp
Hi Mike,
thanks for your reply.
maybe I must explain first what I try to do.
I'm writing a migration program in C# to migrate all of our inventor models to Inventor 2017.
I can't use the tasksheduler migration tool of Inventor because we must do all kind of stuff with our models to migrate.
I also can't use Apprentice server by migration files. So I must use inventor in silent mode to open and migrate the models.
But the problem is when I try to open the assemblies it often opens the dialog "Unresolved links" so the program stops.
I even tried InventorApp.SilentOperation = True but with migration it still shows the dialog.
So that's why I want to check before I open the assembly if there are unresolved references and skip these and write this in a logfile.
Other suggestions?
regards,
Geert
It's true you can't use Apprentice to migrate files, but you can still use it to list the doc's references.
You can't, however, replace the references. Actualy you can, but you can't save the document because it would need migration and Apprentice doesn't support that (I can see why and it doesn't please me).
So, all you can do is open the document in Apprentice an check for missing files. Then maybe supply the missing files in the appropriate locations and/or open the documents with none missing files.
You can also try this (it works for me in VB.Net, but apprentice is way faster in this):
1) Open hidden (visible=false) Inventor
2) Set SilentOperation to true
3) Open hidden document
4) List the referenced documents and check for missing ones
5) Process other operations
6) Save
7) Close hidden document
😎 Close hidden Inventor
I wrote a vbscript that handles this on a per document basis.
Copy this text into a text file. Save with the file extension as ".vbs"
Run.
Profit.
Dim filename Dim oParentsWithMissingColl Dim outputstring Dim oAllFilesList Call Main Sub Main() Dim resp resp = MsgBox("Is your last open Inventor set to the proper project for the file you wish to open?", 4, "MacroMagic") If resp = 7 Then WScript.Quit End If filename = InputBox("Input Assembly To Search For Missing References", "VbScript Magics") If filename = "" Then WScript.Quit End If Set oParentsWithMissingColl = CreateObject("System.Collections.Arraylist") Call GrabReferences If oParentsWithMissingColl.Count > 0 Then Call OpenInventorFilesFromColl End If Set oParentsWithMissingColl = Nothing oTextSave = "C:\Users\Public\Documents\iLogicBuffer.txt" Set fso = CreateObject("Scripting.FileSystemObject") Set oWrite = fso.CreateTextFile(oTextSave, True) oWrite.WriteLine("File Checked: " & filename) oWrite.WriteLine ("") oWrite.WriteLine ("Missing Files") oWrite.WriteLine (outputstring) oWrite.WriteLine ("") oWrite.WriteLine ("All Files:") oWrite.WriteLine (oAllFilesList) oWrite.Close Dim WshShell Dim oExev Set WshShell = CreateObject("WScript.Shell") Set oExec = WshShell.Exec("notepad " & oTextSave) Set oExec = Nothing Set WshShell = Nothing End Sub Sub GrabReferences() On Error Resume Next Dim invApprenticeApp Set invApprenticeApp = CreateObject("Inventor.ApprenticeServer") Dim invApprenticeDoc Set invApprenticeDoc = invApprenticeApp.Open(filename) Dim oFM Set oFM = invApprenticeApp.FileManager Dim oMainFile Set oMainFile = oFM.Files(filename) If oFM Is Nothing Then Exit Sub End If Dim oSubFile Dim oFD Dim oAddHeader For Each oSubFile In oMainFile.AllReferencedFiles oAllFilesList = oAllFilesList & vbCrLf & oSubFile.FullFileName oAddHeader = True For Each oFD In oSubFile.ReferencedFileDescriptors If oFD.ReferenceMissing = True Then oFName = oFD.FullFileName If oAddHeader = True Then outputstring = outputstring & " ### RDD Count: " & oSubFile.ReferencedFileDescriptors.Count & " ### - " & oSubFile.FullFileName & vbCrLf Call oParentsWithMissingColl.Add(oSubFile.FullFileName) oAddHeader = False End If If oFD.ReferenceSuppressed = True Then outputstring = outputstring & " _Suppresed Ref: " & oFName & vbCrLf Else outputstring = outputstring & " " & oFName & vbCrLf End If End If Next Next invApprenticeApp.Close Set invApprenticeApp = Nothing End Sub Sub OpenInventorFilesFromColl() Dim invApp Set invApp = CreateObject("Inventor.Application") invApp.Visible = True 'Do Until invApp.Ready = True ' WScript.Sleep 100 'Loop 'On Error resume Next 'Call invApp.DesignProjectManager.DesignProjects.ItemByName("Z:\Something.ipj").Activate invApp.SilentOperation = True For Each oItem In oParentsWithMissingColl Call invApp.Documents.Open(oItem, True) Next invApp.SilentOperation = False Set invApp = Nothing End Sub