Deletion of linked spreadsheet

Deletion of linked spreadsheet

AlexFielder
Advisor Advisor
1,027 Views
7 Replies
Message 1 of 8

Deletion of linked spreadsheet

AlexFielder
Advisor
Advisor

Hi all,

 

I have a customer assembly that has a couple of linked spreadsheets which are no longer required.

 

I cannot share the assembly before anyone asks, but here is where the linked files appear in the parameter dialogue:

 

Parameters_showing_unused_spreadsheets.PNG

NOTE: Path obscured by me

 

Having tried this:

 

'Delete unwanted OLE references
Sub Main()
	DeleteOLEReference()
End Sub

Public Sub DeleteOLEReference()
    Dim oDoc As Document
    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
        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 

I am still stuck with the unecessary linked files.

 

The "Links" command on the tools tab does nothing, so is there some other API method I can tap into that will allow me to remove these linked files?

 

I even tried readding those exact same excel files at the original path but that results in a "duplicate to an existing link" message.

 

The last resort I suppose would be to create a new blank assembly, export the parameters from this assembly into it using the Export/Import Parameter tools and then copy/paste the contents of the current assembly into it.

 

Thoughts?

0 Likes
1,028 Views
7 Replies
Replies (7)
Message 2 of 8

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

The code you are using deletes the reference document only (the corresponding node in browserpane '3rd party'), instead of that parameter table. To delete the table, you can use the code below

 

Sub test()

Dim oDoc As PartDocument
 Set oDoc = ThisApplication.ActiveDocument
 
'assume we want to delete the first table
 Dim oPTB As ParameterTable
 Set oPTB = oDoc.ComponentDefinition.Parameters.ParameterTables(1)
 
 oPTB.Delete
End Sub
0 Likes
Message 3 of 8

AlexFielder
Advisor
Advisor

Hi @xiaodong_liang that's a great start and with your code I can do this:

 

Sub Main()
	'DeleteLinkedParameterTablesAutodesk()
	DeleteLinkedParameterTables()
End Sub

Public Sub DeleteLinkedParameterTables()
    Dim oDoc As Document
    oDoc = ThisApplication.ActiveDocument
    If oDoc.ComponentDefinition.Parameters.ParameterTables.Count = 0 Then
        MsgBox ("There aren't any linked parameter tables in this document.")
        Exit Sub
	Else
		MsgBox ("Proceeding to selection of parameter tables")
		For i = 1 To oDoc.ComponentDefinition.Parameters.ParameterTables.Count
			If MsgBox("Delete """ & oDoc.ComponentDefinition.Parameters.ParameterTables(i).FileName & """?", vbQuestion + vbYesNo) = vbYes Then
            	oDoc.ComponentDefinition.Parameters.ParameterTables(i).Delete
        	End If
		Next
    End If
End Sub 

The problem I have is that if select Yes from the resultant messagebox I am presented with this:

 

parametertable delete error.PNG

 

With this in the "More info" tab:

 

parametertable delete error- more info.PNG

 

This file isn't read only, so I am all out of ideas.

 

Thoughts?

0 Likes
Message 4 of 8

adam.nagy
Autodesk Support
Autodesk Support

Hi Alex,

 

The For loop is wrong.

When you delete the first item of the two then i's value will be increased to 2 but there will remain only a single item in the collection so  oDoc.ComponentDefinition.Parameters.ParameterTables(i[=2]).Delete is incorrect. 

 

You could try to do a For Each loop instead:

Dim pt As ParameterTable
For Each pt In cd.Parameters.ParameterTables

Does that error happen for the first item as well though? - works for me.

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 5 of 8

AlexFielder
Advisor
Advisor

Hi @adam.nagy, thanks for the headsup. Of course looking at my original attempt now it obviously would never have worked!

 

I subsequently modified my iLogic to the following:

 

 

Sub Main()
	DeleteLinkedParameterTables()
End Sub

Public Sub DeleteLinkedParameterTables()
    Dim oDoc As Document
    oDoc = ThisApplication.ActiveDocument
    If oDoc.ComponentDefinition.Parameters.ParameterTables.Count = 0 Then
        MsgBox ("There aren't any linked parameter tables in this document.")
        Exit Sub
    Else
	MsgBox ("Proceeding to selection of parameter tables")
	Dim pt As ParameterTable
	For Each pt In oDoc.ComponentDefinition.Parameters.ParameterTables
	    If MsgBox("Delete """ & pt.FileName & """?", vbQuestion + vbYesNo) = vbYes Then
                  pt.Delete
            End If
	Next
    End If
End Sub 

But I then get a slightly different error:

 

 

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.ParameterTable.Delete()
   at LmiRuleScript.DeleteLinkedParameterTables()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

Ideas/Thoughts?

 

0 Likes
Message 6 of 8

xiaodong_liang
Autodesk Support
Autodesk Support
Hi Alex,

because when I tested at my side in message 2, the code can work, I doubt it looks this problem happened with specific document. If yes, could you provide such demo file and the excel files? Thank you.
0 Likes
Message 7 of 8

AlexFielder
Advisor
Advisor

Hi @xiaodong_liang the problem is with this specific file, yes.

 

I don't however have permission from the customer to share the Assembly file with you.

 

I don't believe having the Excel files matters either way as the error inside of iLogic occurs whether or not there is an Excel file of the correct name in the path defined inside of the parameter dialogue.

 

I guess what I am asking for is whether there is the ability to "Force-remove" these otherwise broken ParameterTables inside of the Inventor API? If this means I need to do so inside of an Inventor .NET addin I am happy to do so to avoid having to recreate this assembly.

 

 

0 Likes
Message 8 of 8

xiaodong_liang
Autodesk Support
Autodesk Support
Hi Alex,

sorry I was on other commitments.

So, iLogic is based on Inventor API. It runs within Inventor process. the iLogic ode I shared in message 2 is exactly copied from Inventor API, which can run in VBA or VB.NET. So it is not a problem that the API cannot work with iLogic, but as you said it is caused by the specific file.

Then it is necessary to have a reproducible sample. While I did not mean to get all content of the file. You can isolate (such as removing all parts/sub assemblies) with the parameters + excel table only.
0 Likes