Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic to read if part is used in view representation

CAD-One
Collaborator

iLogic to read if part is used in view representation

CAD-One
Collaborator
Collaborator

I have a huge assembly of about 200 parts. There are several view representations.

 

There are several parts those are never used in any view rep ( never visible on any view rep). 

 

Is is there a way I can know a list of them. Or better yet, a way to create a new view rep and make them visible in this new view rep. This way we will know which parts needs to be deleted. 

 

Reasoning : This is a way To clean parts before finalizing assembly.  

C1
Inventor Professional 2020
Vault Professional 2020
AutoCAD 2020
0 Likes
Reply
Accepted solutions (1)
803 Views
6 Replies
Replies (6)

philip1009
Advisor
Advisor

Do you use balloons to call out all the parts in your drawings?  You can just open the BOM editor in the drawing and see the parts that don't have a balloon attached.

 

Other than that there are 2 ways to get the code written.  Either you go through each view representation at a time and generate a list of invisible parts and then filter through each list to find the parts in every one.  Or you can go through each part at a time and see if it's invisible in every view rep.  I think the former method would be faster unless you have hundreds of view reps, I'll come up with a code example at some point today that should work.

0 Likes

CAD-One
Collaborator
Collaborator

I like your idea of using the balloon method to identify. I would try this method.

 

On the side note, I would be curious to see how in iLogic you would access view reps and check visibility. Thanks for the effort.

 

 

C1
Inventor Professional 2020
Vault Professional 2020
AutoCAD 2020
0 Likes

philip1009
Advisor
Advisor
Accepted solution

Alright, here's an example that's worked on my assemblies so far, the only concern is if you have individual members of a pattern invisible or not, those won't get deleted since you can't delete individual pattern members.  If you think there are entire patterns that could be invisible in every view and need to be deleted, let me know and I'll figure out how to add that to the code.

 

Other than that, here's the example:

objApp = ThisApplication
objTN = objApp.TransactionManager.StartTransaction(ThisDoc.Document, "Delete 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
Dim intViewCount As Long = colViews.Count - 1
objProgBar = objApp.CreateProgressBar(False, intViewCount, "Delete Unused Parts")
For Each objView In colViews
	If objView.Name <> "Master" Then
		objProgBar.Message = "Scanning " + objView.Name + " 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
For Each objComp In lisOccs
	objComp.Delete
Next
objApp.ScreenUpdating = True
objApp.SilentOperation = False
InventorVb.DocumentUpdate()
objTN.End

Screen Updating is turned off so the computer doesn't waste time generating each view as it gets activated, this speeds up the code significantly.  Silent Operation is turned to eliminate any pop-ups the regular Inventor software uses, if there are any add-ins like the Vault that are still popping up, let me know and I'll see if it's possible to deactivate those add-ins, the Vault can be turned on and off without issue, others I'm not so sure.  Basically a list of all Occurrences (Parts and Assemblies)  in the document is created.  Then for each view rep, if an occurrence is visible, it's removed from the list, leaving you with a list of parts that gets deleted at the end.

 

While looking through each view rep, there's a progress bar that will pop up informing you of the progress so far.  The whole code is also wrapped in a single transaction in the change processor.  So if the code does something you don't want, just click Undo once and it will take you back to before the code was run.

CAD-One
Collaborator
Collaborator

This is incredible. Especially when its working silently. Never seen one like this.

 

one request. Instead of deleting them, would it too hard to created new view rep called "extra parts" and add them to it.

C1
Inventor Professional 2020
Vault Professional 2020
AutoCAD 2020
0 Likes

philip1009
Advisor
Advisor

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

CAD-One
Collaborator
Collaborator

You are great help, Philip. Thanks a lot. I will have to take my time to interpret this code. But, it does it for sure.

Smiley Happy

C1
Inventor Professional 2020
Vault Professional 2020
AutoCAD 2020
0 Likes