John,
I have revised the code to be a little better for your situation, and a little better in general. The view does not need to be on the activesheet for this to work.
-SheetName is the name of the sheet seen in the model browser.
-ViewNumber is the index of the view on any (1) sheet.
IE: We have set oSheet to the sheet named "MySheet:1".
This Sheet only contains "View3" and "View4".
The index of "View3" is 1
The index of "View4" is 2
-PartName should be the name of the part that is shown in the model browser in your assembly.
'Set our application and active document
Dim oApp As Application = ThisApplication
Dim oDwgDoc As DrawingDocument = oApp.ActiveDocument
'Declare objects to use
Dim oSubDoc As ComponentOccurrence
Dim oSheet As Sheet
Dim oView As DrawingView
Dim oViewDoc As AssemblyDocument
Dim oOccs As ComponentOccurrences
'Variables to control selection of view, assemblydoc, and sub part
SheetName = "MySheet:1" 'the name of the sheet seen in the model browser.
ViewNumber = 1 'the index of the view on any (1) sheet.
PartName = "MyPart" 'the name of the part that is shown in the model browser in your assembly.
'Set the sheet to control
oSheet = oDwgDoc.Sheets.Item(SheetName)
'Set our view to control
oView = oSheet.DrawingViews.Item(1)
'Set the document contained in our view
oViewDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
'Set the list of occurrences from our referenced assembly
oOccs = oViewDoc.ComponentDefinition.Occurrences
'Select and set the partDoc
oSubDoc = oOccs.ItemByName(PartName)
'Perform our suppression action based on the
If oSubDoc.Suppressed Then
oView.Suppressed = True
Else
oView.Suppressed = False
End If
I removed the generic Reference doc code, and instead grabbed the document that is consumed by the view we selected. Both work, but this is a better solution because we always want to referencing the assembly document in the selected view.
I know this can be confusing. I would suggest learning how to use the vba editor to see the architecture of the objects. It will make understanding all of this a lot easier. There are plenty of tutorials on creating macros.
Let me know if you would like more explanation.
Best Regards,
Tyler Boni
Please Mark as Solution if this is your answer!