Hi @m_send. Here is a very similar example you can try, in which it incorporates a couple of those Try...Catch statements to help avoid potential errors. In this example, instead of using an ObjectCollection and a 'While' loop, it is using the old 'GoTo' keyword. But in both examples, you can just use your 'Esc' keyboard key when it asks you to select a component, which will let the code resume without anything being selected, and when nothing has been selected, that will cause it to exit the loop. It is using a Try...Catch statement where it attempts to access the WorkPlanes collection of the component, because accessing the 'Definition' property of a component that is currently suppressed will throw an error. You may never select a suppressed component, but if you do, it will avoid that error, and just exit the routine. Then this example, the line of code that attempts to change the visibility of a WorkPlane is enclosed within a Try...Catch statement, to avoid that potential error, because that will fail if the document the component references is ReadOnly, like content center files and such. The 'GoTo' term just tells the rule to go to where the following term is found, which in this case is just before the line of code for picking another component. You could also ask the user a simple question at that point, like "Go again?", and then only loop again if they answer Yes. I have used that technique many times before to avoid endless loops in basic code routines. It just involves an extra mouse click each time to continue.
Dim oOcc As ComponentOccurrence, oWPlanes As WorkPlanes, oWPlane As WorkPlane
Dim sPrompt As String = "Select a component." & vbCrLf & "Or tap ESC key to exit loop."
PickAgain :
oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, sPrompt)
If oOcc Is Nothing Then Return
Try 'this will fail if the component is suppressed, also maybe if it is a virtual component
oWPlanes = oOcc.Definition.WorkPlanes
Catch
Return 'exit this routine, because it could not access the WorkPlanes
End Try
For Each oWPlane In oWPlanes
If oWPlane.IsCoordinateSystemElement Then
If oWPlane.Visible = True Then
Try 'this will fail if the referenced document is ReadOnly (content center, library, etc)
oWPlane.Visible = False
Catch
'what to do if it fails here
End Try
End If
End If
Next
'If MsgBox("Pick again?", vbYesNo+vbQuestion, "Again?") = vbNo Then Return
GoTo PickAgain 'go to where this term is found
Wesley Crihfield

(Not an Autodesk Employee)