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).Refer
encedDocumentDescriptor.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.Ful lDocumentName 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
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:
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
Then inside your current function you could call it like:
Dim dd As DocumentDescriptor
Set dd = GetDescriptor(oFullFileName, AllRef)
oSupBool = dd.ReferenceSuppressed
I hope this helps.
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
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).Refer
encedDocumentDescriptor.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(oCu rrentDoc) If OccEnum.Count > 0 Then oDrawingView.Suppressed = False Else oDrawingView.Suppressed = True End If End If Next End If Next End Sub
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.
Access a broad range of knowledge to help get the most out of your products and services.