Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Determining if references are missing before opening an IAM file

5 REPLIES 5
Reply
Message 1 of 6
Sanjay.Gangadhara
1544 Views, 5 Replies

Determining if references are missing before opening an IAM file

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!

5 REPLIES 5
Message 2 of 6
GVDB
in reply to: Sanjay.Gangadhara

Hi Sanjay,

 

i have a similar problem.

Did you find a solution for this?

 

regards,

 

Geert

Message 3 of 6
Owner2229
in reply to: GVDB

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
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 4 of 6
GVDB
in reply to: Owner2229

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

 

 

 

 

 

 

Message 5 of 6
Owner2229
in reply to: GVDB

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

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 6 of 6
MechMachineMan
in reply to: GVDB

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

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report