how to remove ole links

how to remove ole links

GosponZ
Collaborator Collaborator
3,681 Views
4 Replies
Message 1 of 5

how to remove ole links

GosponZ
Collaborator
Collaborator

I do have code this code to remove ole links but it works on part level.

1. Is it possible to run this code from assembly and remove ole links from each part.

Some images with no reason knowing to me att. to each part in my assembly and can't check in vault. Shouldn't be tool for easy removal, and not to go part by part waste a lot time for nothing.

2. What make this situation?

 

Please experts I need help ASAP. This happened and it just pain.

 

Thank you All.

 

0 Likes
Accepted solutions (1)
3,682 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor

The following code makes the OLE links visible in the browser, so that you can easily delete the through the UI.

 

Sub Main()
	Dim oDoc As Document
	oDoc = ThisApplication.ActiveDocument
	
	If oDoc.ReferencedOLEFileDescriptors.Count > 0
		For Each oOLEFileRef In oDoc.ReferencedOLEFileDescriptors
			oOLEFileRef.BrowserVisible = True
		Next
	End If
	
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
0 Likes
Message 3 of 5

GosponZ
Collaborator
Collaborator

Can this code be adjusted to run from assembly?

Public Sub DeleteOLEReference()
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument

    If oDoc.ReferencedOLEFileDescriptors.Count = 0 Then
        MsgBox "There aren't any OLE references in this document."
        Exit Sub
    End If

    Dim aOLERefs() As ReferencedOLEFileDescriptor
    ReDim aOLERefs(oDoc.ReferencedOLEFileDescriptors.Count - 1)

    Dim iRefCount As Integer
    iRefCount = oDoc.ReferencedOLEFileDescriptors.Count
    Dim i As Integer
    For i = 1 To iRefCount
        Set aOLERefs(i - 1) = oDoc.ReferencedOLEFileDescriptors.Item(i)
    Next

    For i = 1 To iRefCount
        If MsgBox("Delete """ & aOLERefs(i - 1).FullFileName & """?", vbQuestion + vbYesNo) = vbYes Then
            aOLERefs(i - 1).Delete
        End If
    Next
End Sub

0 Likes
Message 4 of 5

MechMachineMan
Advisor
Advisor
Accepted solution

1. Please properly nest code and use the code wrapper, so it's easier to read and copy.

 

2. That code works of the active document as it is, so it works on assembly, parts, drawings. If by "work from assembly" you mean have it traverse through all of the parts and sub-assemblies of that main assembly, then yes, this is also possible as well.

 

 

Sub Main()
    Dim oDoc As Document

    'vba:
    Set oDoc = ThisApplication.ActiveDocument

    'vb.net:
    'oDoc = ThisDoc.Document

    Dim oLog As String

    For Each oSubDoc in oDoc.AllReferencedDocuments
        If oSubDoc.IsModifiable = True Then
            Call RemoveOLEsFromDoc(oSubDoc, oLog)
        End if
     Next

    Call MsgBox("Rule Complete!" & vblf & vblf & _
                  "OLEs Removed From: " & vblf & oLog)
End Sub


Sub RemoveOLEsFromDoc(ByVal oDoc As Document, ByRef oLogStr As String)
	
	If oDoc.ReferencedOLEFileDescriptors.Count > 0
		For Each oOLEFileRef In oDoc.ReferencedOLEFileDescriptors
			'oOLEFileRef.BrowserVisible = True
                         oOLEFileRef.Delete
		Next
                oLogStr = oLogStr & oDoc.DisplayName
	End If
	
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
Message 5 of 5

GosponZ
Collaborator
Collaborator

Cool thanks a lot. I run in assembly and remove all of them.

Thanks again

0 Likes