Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
philip1009
in reply to: CAD-One

No, not too difficult, just a check at the beginning to see if the view already exists, then at the end create the view if it doesn't exist, if a view named Extra Parts already exists, then it will update that view:

 

objApp = ThisApplication
objTN = objApp.TransactionManager.StartTransaction(ThisDoc.Document, "Unused Parts")
objApp.ScreenUpdating = False
objApp.SilentOperation = True
objDef = ThisDoc.Document.ComponentDefinition
Dim objComp As ComponentOccurrence
colOccs = objDef.Occurrences
Dim lisOccs As New ArrayList
For Each objComp In colOccs
	lisOccs.Add(objComp)
Next
Dim objView As DesignViewRepresentation
colViews = objDef.RepresentationsManager.DesignViewRepresentations
On Error Resume Next
i = 1
blnViewCheck = False
For Each objView In colViews
	If objView.Name = "Extra Parts" Then blnViewCheck = True
Next
Dim intViewCount As Long = colViews.Count - 1
If blnViewCheck = True Then intViewCount -= 1
objProgBar = objApp.CreateProgressBar(False, intViewCount, "Unused Parts")
For Each objView In colViews
	strViewName = objView.Name
	If strViewName <> "Master" And strViewName <> "Extra Parts" Then
		objProgBar.Message = "Scanning " + strViewName + " for Unused Parts.  (View " + CStr(i) + " of " + CStr(intViewCount) + ")"
		objProgBar.UpdateProgress
		objView.Activate
		For Each objComp In colOccs
			If Component.Visible(objComp.Name) = True Then lisOccs.Remove(objComp)
		Next
		i += 1
	End If
Next
objProgBar.Close
If blnViewCheck = False Then
	objExtraPartsView = colViews.Add("Extra Parts")
Else
	objExtraPartsView = colViews.Item("Extra Parts")
End If
objExtraPartsView.Activate
If objExtraPartsView.Locked = True Then objExtraPartsView.Locked = False
objExtraPartsView.HideAll
For Each objComp In lisOccs
	Component.Visible(objComp.Name) = True
Next
objApp.ScreenUpdating = True
objApp.SilentOperation = False
InventorVb.DocumentUpdate()
objTN.End