error - Method 'Visible' of object 'ComponentOccurrence' failed

error - Method 'Visible' of object 'ComponentOccurrence' failed

rip2A4H8
Enthusiast Enthusiast
773 Views
4 Replies
Message 1 of 5

error - Method 'Visible' of object 'ComponentOccurrence' failed

rip2A4H8
Enthusiast
Enthusiast

I'm only a few months into Inventor, and I'm finding macros to help with reducing mouse clicks enabling "hidden" functionality.  That said, I really want a way to show all components within an assembly with one click (or hotkey).  I found a good solution on another post that works great most of the time, but it's having trouble with one of my assemblies, specifically when a particular View Representation is active.  I get the following error:  Method 'Visible' of object 'ComponentOccurrence' failed.

 

How do I resolve this error?

 

Here is my code (mostly borrowed from someone else here):

 

 

 

Sub ShowAllComponents()

' Get the active assembly.
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument

' Get the assembly component definition.
Dim oAsmDef As AssemblyComponentDefinition
Set oAsmDef = oAsmDoc.ComponentDefinition

' Get all of the leaf occurrences of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences

Dim oOcc As ComponentOccurrence

For Each oOcc In oLeafOccs

If oOcc.Visible = False Then
oOcc.Visible = True

End If

Next

End Sub
0 Likes
774 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

A long shot but is the view rep locked? Can you make the same parts visible by manually selecting them? 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 5

rip2A4H8
Enthusiast
Enthusiast

Hey Alan - 

 

No, the view rep isn't locked.  I tried the macro above with the locked and unlocked view reps of two different assemblies; it works for all view reps in one assembly, but only two of the three view reps in the other assembly.  For the latter, one view rep is locked, and the other isn't, so it appears that that's not a factor.

Yes, I can make the same parts visible by manually selecting them in any of the above cases.

0 Likes
Message 4 of 5

A.Acheson
Mentor
Mentor

Perhaps you can print the occurrence name and determine if a particular occurrence brings up the error. It is a bit strange. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 5

rip2A4H8
Enthusiast
Enthusiast

Thanks for the suggestion.  I haven't been able to reproduce the error to see if it corresponds to a particular occurrence, but I will check for that next time it happens.

0 Likes