- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Sorry to hear about your Excel code related issues. Maybe when changing the Excel Application object to be an 'Object' type variable, the WorkBook, WorkSheet, and other Excel related objects would also need to be identified as Object, in an attempt to avoid all Type conversion issues. Some folks do it that way, and do not even include those first 3 lines of code that automatically go into the 'Header' of the rule, to help with Excel API object recognition, but since I do not seem to have any troubles in that area, I have used them for years now. I am using Windows 10 Enterprise 64 bit, and Office 365, on a Dell Desktop Work PC. The iLogic 'GoExcel' stuff may work better for you, if the direct Excel API code route does not, but you can not start a new Excel file with the 'GoExcel' tools...that I can recall. You would have to Open an already existing file, and work with an already existing Sheet within that file.
Text file:
This example below just writes the list of sub-assembly file names to a new text file. The new text file will have the same path and file name as the main assembly, but with the ".txt" file extension. I also added list header line "SUB-ASSEMBLY FILE NAMES:" as the first line of text at the top of the text file, but of course you can change that however you want. The main rule is exactly the same, except for a few minor changes in the last 3 lines. The variable name and file extension was changed in Line 17. The name of the custom routine changed, and the new variable from Line 17 was used in Line 18. Then I added a line to launch the newly created Text file, so you can immediately review it, after it gets created, but if that is not needed, you can always comment that line out, or delete it.
I also tested this in a small multi-level assembly, and it seemed to work just fine for me. Hopefully it will work OK for you too.
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Return
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
Dim oList As New List(Of String)
Dim iCount As Integer = 0
For Each oRefDoc As Inventor.Document In oRefDocs
If oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
If oList.Contains(oRefDoc.FullFileName) = False Then
oList.Add(oRefDoc.FullFileName)
iCount = iCount + 1
End If
End If
Next
MsgBox("There are " & iCount & " unique sub assemblies in this assembly.", vbInformation, "iLogic")
'same path and file name as this assembly, but with ".xlsx" file extension
Dim sTextFile As String = System.IO.Path.ChangeExtension(oADoc.FullFileName, ".txt")
WriteListToTextFile(oList, sTextFile)
ThisDoc.Launch(sTextFile)
End Sub
Sub WriteListToTextFile(oList As List(Of String), sNewFullFileName As String)
If oList Is Nothing OrElse oList.Count = 0 Then Return
Using oWriter As System.IO.StreamWriter = System.IO.File.CreateText(sNewFullFileName)
oWriter.WriteLine("SUB-ASSEMBLY FILE NAMES:")
For Each oEntry In oList
'oEntry contains FullFileName (path, file name, and file extension), so we must isolate just file name
oWriter.WriteLine(System.IO.Path.GetFileNameWithoutExtension(oEntry))
Next
oWriter.Close
End Using
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS)
.
Wesley Crihfield
(Not an Autodesk Employee)