Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Question about DocumentDescriptorEnumeration

3 REPLIES 3
Reply
Message 1 of 4
MegaJerk
373 Views, 3 Replies

Question about DocumentDescriptorEnumeration

Yesterday I tried to write some code that would control the suppression of flat pattern drawing views so that they would match the suppression states of their counterparts in the main assembly (which had things suppressed via LOD).

This led to several hoops and approaches (IE: Failures), with little hope of ever linking the list of occurrences, which contain the suppression state information, but can only be iterated through by way of browser occurrence name or number & the document files that the drawing views would resolve to that only gave me the document with nothing that could help in getting those occurrence names forthcoming.

Eventually I started looking for a means of iterating through a list of referenced documents by name, rather than long, and ended up seeing that the DocumentDescriptorEnumerator was just the thing. In fact, document descriptors seemed to hold the information that I needed to tell which suppression state the document was in! Setting up some code I quickly found that any time I would query the enumerator list with a name of a part that had been suppressed, it would result in an error.

This leads to the question I’m about to ask. The following code will do what I want it to. Because it causes an error, I am able to rely on that to be the flag that I need to suppress the drawing view, but that seems rather dangerous as that could lead to false positives. Is there a better way to go about doing what I’m trying to do?

Also, why can a document be clearly listed inside of the Descriptor Enumerator, but not be accessed?

Any answers would be keen! Thanks!

----------------

 



Option Explicit

Public Sub Main()
            
            If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then  Return 

    Dim oDrawDoc As DrawingDocument
    Dim oDrawingViews As DrawingViews
    Dim oDrawingView As Inventor.DrawingView
    Dim oSheets As Sheets
    Dim oSheet As Sheet
    Dim oAssDoc As AssemblyDocument   
    Dim oFullFileName As String
    Dim AllRef As DocumentDescriptorsEnumerator
    Dim oSupBool As Boolean
            
    oDrawDoc = ThisApplication.ActiveDocument
    oSheets = oDrawDoc.Sheets
    oAssDoc = oDrawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument

    For Each oSheet In oSheets
        If oSheet.ExcludeFromCount = False Then
            oDrawingViews = oSheet.DrawingViews
            For Each oDrawingView In oDrawingViews
                If oDrawingView.IsFlatPatternView = True Then
                    
                    AllRef = oAssDoc.ReferencedDocumentDescriptors
                    oFullFileName = oDrawingView.ReferencedFile.DocumentDescriptor.FullDocumentName
                    
                    Try
                        oSupBool = AllRef.Item(oFullFileName).ReferenceSuppressed
                        oDrawingView.Suppressed = oSupBool
                                    Catch
                                    oSupBool = True
                        oDrawingView.Suppressed = oSupBool
                    End Try 
                End If
            Next
        End If
    Next
   
End Sub

 




If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
3 REPLIES 3
Message 2 of 4
adam.nagy
in reply to: MegaJerk

Hi there,

 

Did a quick test and yes it seems that in case of a suppressed document the Item(fileName) does not work - as you mentioned it as well.

 

But you also mention that the item is still there in the list, which seems to be correct too.

 

So why don't you just iterate through the items and find the one you need. In VBA it would be:

<code>

Function GetDescriptor(ByVal fileName As String, ByVal descs As DocumentDescriptorsEnumerator)
  Dim desc As DocumentDescriptor
  For Each desc In descs
    If desc.FullDocumentName = fileName Then
      Set GetDescriptor = desc
      Exit Function
    End If
  Next desc
End Function

</code>

 

Then inside your current function you could call it like:

<code>

Dim dd As DocumentDescriptor
Set dd = GetDescriptor(oFullFileName, AllRef) 
oSupBool = dd.ReferenceSuppressed

</code>

 

I hope this helps.

 

______________________________________________________________

If my post answers your question, please click the "Accept as Solution"

button. This helps everyone find answers more quickly!



Adam Nagy
Autodesk Platform Services
Message 3 of 4
MegaJerk
in reply to: MegaJerk

I nearly forgot about this thread! I had an idea a few days ago that has been working so far, and doesn't require extra iterations. Originally after posting, I was thinking of doing something similar to what you were doing, but wanted to see if I could narrow it down to not having to do my own indexing / searching / iterations through things (for miniscule maximum speed!). Though I haven't ran into any problems with the code below, perhaps you could tell me if there are any traps to now doing it this way. 



Option Explicit

Public Sub Main()

Dim oCurrentDoc As Inventor.Document
Dim oDrawDoc As DrawingDocument
Dim oDrawingViews As DrawingViews
Dim oDrawingView As Inventor.DrawingView
Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oAssDoc As AssemblyDocument
Dim oACompDef As AssemblyComponentDefinition
Dim OccEnum As ComponentOccurrencesEnumerator


oDrawDoc = ThisApplication.ActiveDocument
oSheets = oDrawDoc.Sheets
oAssDoc = oDrawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument
oACompDef = oAssDoc.ComponentDefinition

For Each oSheet In oSheets
    If oSheet.ExcludeFromCount = False Then
        oDrawingViews = oSheet.DrawingViews
        For Each oDrawingView In oDrawingViews
            If oDrawingView.IsFlatPatternView = True Then
                oCurrentDoc = oDrawingView.ReferencedFile.ReferencedDocument
                OccEnum = oACompDef.Occurrences.AllReferencedOccurrences(oCurrentDoc)
                If OccEnum.Count > 0 Then
                    oDrawingView.Suppressed = False
                    Else
                    oDrawingView.Suppressed = True
                End If
            End If
        Next
    End If
Next

End Sub

 

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 4 of 4
adam.nagy
in reply to: MegaJerk

Hi there,

 

I don't know to be honest if there are any traps in your current implementation.

If it works, then great 🙂

 

 

The only thing you can do to verify that your function works the way you intended it, is to test, test and then test some more. 🙂

 

 



Adam Nagy
Autodesk Platform Services

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report