Remove missing OLE Links using ReferencedOLEFileDescriptor

By Wayne Brill

Here is a VBA example that uses the Delete method of the ReferencedOLEFileDescriptor in a part file to remove OLE links. SilentOperation of the Application is set to True to avoid dialogs.

Also the Dirty property of the document is set to True. I found that without doing this the save did not save to disk with the removed Links.

This ivb has code that removes the links in a part as well as removing the links in parts in an assembly. It is an update to the AssemblyCount VBA example in the API help.

 Download RemoveOLELinks

 

Public Sub oleLinksDelete()
          
    ThisApplication.SilentOperation = True
    
     Dim oPartDoc As PartDocument
     Set oPartDoc = ThisApplication.ActiveDocument
    
     Dim bSaveDoc As Boolean
     bSaveDoc = False
   
     Dim oRefOleFileDesc As ReferencedOLEFileDescriptor
    
     If oPartDoc.ReferencedOLEFileDescriptors.Count > 0 Then
        
         For Each oRefOleFileDesc In _
                       oPartDoc.ReferencedOLEFileDescriptors
              'Debug.Print oRefOleFileDesc.ReferenceStatus
             
              If oRefOleFileDesc.ReferenceStatus = _
                                      kMissingReference Then
                  ' Debug.Print oRefOleFileDesc.DisplayName
                  oRefOleFileDesc.Delete
                  oPartDoc.Dirty = True
                  bSaveDoc = True
              End If
            Next oRefOleFileDesc
         
          If bSaveDoc = True Then
              oPartDoc.Save
              bSaveDoc = False
          End If
      End If
    ' Be sure to set this back to False
     ThisApplication.SilentOperation = False
End Sub


Comments

2 responses to “Remove missing OLE Links using ReferencedOLEFileDescriptor”

  1. Is there a way to perform this type of operation using .NET? If there was a way of dealing with OLE links in something like C#, that would be very useful to me. Thanks!

  2. Wayne Brill Avatar
    Wayne Brill

    Hi Josh,
    You can copy VBA code to VB.NET. It will automatically remove the VBA Set statements. You can then fix the enums. (they need to be fully qualified – like ReferenceStatusEnum.kMissingReference) You can then use a translator to get it to C#. I used this one:
    http://www.developerfusion.com/tools/convert/vb-to-csharp/
    Here is the converted coded. (I didn’t test it). You would need to make ThisApplication the Inventor Application in your code.
    public void oleLinksDelete()
    {
    ThisApplication.SilentOperation = true;
    PartDocument oPartDoc = default(PartDocument);
    oPartDoc = ThisApplication.ActiveDocument;
    bool bSaveDoc = false;
    bSaveDoc = false;
    ReferencedOLEFileDescriptor oRefOleFileDesc = default(ReferencedOLEFileDescriptor);
    if (oPartDoc.ReferencedOLEFileDescriptors.Count > 0) {
    foreach ( oRefOleFileDesc in oPartDoc.ReferencedOLEFileDescriptors) {
    //Debug.Print oRefOleFileDesc.ReferenceStatus
    if (oRefOleFileDesc.ReferenceStatus == ReferenceStatusEnum.kMissingReference) {
    // Debug.Print oRefOleFileDesc.DisplayName
    oRefOleFileDesc.Delete();
    oPartDoc.Dirty = true;
    bSaveDoc = true;
    }
    }
    if (bSaveDoc == true) {
    oPartDoc.Save();
    bSaveDoc = false;
    }
    }
    // Be sure to set this back to False
    ThisApplication.SilentOperation = false;
    }
    Thanks,
    Wayne

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading