Referenced File Descriptor Fails

Referenced File Descriptor Fails

dbrblg
Collaborator Collaborator
1,154 Views
5 Replies
Message 1 of 6

Referenced File Descriptor Fails

dbrblg
Collaborator
Collaborator

I am using the following code to traverse an assembly and print out the parts within it:

Public Sub TraverseAssemblySample()
    ' Get the active assembly.
    Dim fso As New FileSystemObject

    Dim OApp As Inventor.Application
    Set OApp = GetObject(, "Inventor.Application")

    Dim oAsmDoc As Inventor.AssemblyDocument
    Set oAsmDoc = OApp.ActiveDocument

    Debug.Print oAsmDoc.DisplayName


    ' Call the function that does the recursion.
    Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1)

End Sub

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer)
    ' Iterate through all of the occurrence in this collection.  This
    ' represents the occurrences at the top level of an assembly.
    Dim oOcc As ComponentOccurrence

    For Each oOcc In Occurrences
        ' Print the name of the current occurrence.
        Debug.Print Space(Level * 3) & oOcc.DefinitionReference.ReferencedFileDescriptor.DisplayName
        
        ' Check to see if this occurrence represents a subassembly
        ' and recursively call this function to traverse through it.
        If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
            Call TraverseAssembly(oOcc.SubOccurrences, Level + 1)
        End If
    Next

End Sub

 The problem I have is the ReferencedFileDescriptor fails with the following message:

Error Message.jpg

This error occurs here:

Debug.Print Space(Level * 3) & oOcc.DefinitionReference.ReferencedFileDescriptor.DisplayName

 

This is code which is from the Autodesk site but the worrying thing is this issue is completely random.  It will work without issues on an assembly then another time I will get this error.  Each time I get the error, it is with a different part file!!  I get the error on different parts on different assemblies at different times.

 

Has anyone encountered this?

 

Thanks

0 Likes
1,155 Views
5 Replies
Replies (5)
Message 2 of 6

MechMachineMan
Advisor
Advisor
The way you are accessing referenced file descriptor is wrong according to the Programming Help.

--------------------------------------
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 6

dbrblg
Collaborator
Collaborator

Ah, that's interesting....I got this sample from the Autodesk website Smiley Indifferent

 

I don't have any samples for use; which programming help is to which you refer?  I would like to understand its correct use.

 

Thanks

0 Likes
Message 4 of 6

MechMachineMan
Advisor
Advisor
C:\Program Files\Autodesk\Inventor 2014\Local Help\admapi_18_0.chm

or the one found by clicking the question mark in the top right of inventor and selecting "Programming Help"

--------------------------------------
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 5 of 6

dbrblg
Collaborator
Collaborator

I've looked in the help files, as suggested however the FileReferenceSampe also does not work.  This time with this error:

Untitled.png

0 Likes
Message 6 of 6

MechMachineMan
Advisor
Advisor

oModelName = oSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.FullDocumentName

 

Just change oSheet.DrawingViews.Item(1) to be the occurrence object instead.

 

This is a working chunk from one of my programs that I have written.


--------------------------------------
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