Inventor Customization

Inventor Customization

Reply
Valued Mentor
286 Posts
187 Kudos
Registered: ‎01-26-2011
Post 1 of 4

Question about DocumentDescriptorEnumeration

176 Views, 3 Replies
07-20-2012 01:54 PM

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 seems to remedy your problem, please press the Accept Solution button, -
as it increases my power levels and will eventually help to elevate me towards outer space.

Check out my iLogic injection tool here : http://goo.gl/ce1Qg
--------------------------------------------------------------------------------------
ADN Support Specialist
637 Posts
103 Kudos
Registered: ‎03-26-2007
Post 2 of 4

Re: Question about DocumentDescriptorEnumeration

08-08-2012 05:42 AM 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
Developer Technical Services
Autodesk Developer Network
Valued Mentor
286 Posts
187 Kudos
Registered: ‎01-26-2011
Post 3 of 4

Re: Question about DocumentDescriptorEnumeration

08-09-2012 04:20 AM 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 seems to remedy your problem, please press the Accept Solution button, -
as it increases my power levels and will eventually help to elevate me towards outer space.

Check out my iLogic injection tool here : http://goo.gl/ce1Qg
--------------------------------------------------------------------------------------
ADN Support Specialist
637 Posts
103 Kudos
Registered: ‎03-26-2007
Post 4 of 4

Re: Question about DocumentDescriptorEnumeration

08-15-2012 01:33 AM 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 :smileyhappy:

 

 

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. :smileyhappy:

 

 



Adam Nagy
Developer Technical Services
Autodesk Developer Network
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post