ghost parts

ghost parts

GosponZ
Collaborator Collaborator
249 Views
2 Replies
Message 1 of 3

ghost parts

GosponZ
Collaborator
Collaborator

After copy design, removed few parts from assembly. They are still in idw without any sign that is not belong there. It is hard to catch. Parts are similar shape. My question is is it possible to check for parts that are not part of assembly in idw and after recognize them easy delete them from idw browser tree.

 

0 Likes
250 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @GosponZ.  Here is some untested code you can review to see if it makes sense to you.  When there are multiple different models referenced by one drawing, it can really get confusing, and determining which one is the 'main' reference (if there is such a thing) can be challenging too.  So, in this example, I am simply using the iLogic shortcut snippet to specify which 'model' is the main one (the main assembly).  This may not be the most intuitive way to do it, but the main idea is the code following that point.  If any view is referencing a 'model' document that can not be found within the 'AllReferencedDocuments' collection of the 'main' model, then delete that view, which should get rid of any unwanted references in the drawing...after an update/rebuild or two.

Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oModelDoc As Document = ThisDoc.ModelDocument
Dim oModelRefs As DocumentsEnumerator = oModelDoc.AllReferencedDocuments
For Each oSheet As Sheet In oDDoc.Sheets
	For Each oView As DrawingView In oSheet.DrawingViews
		Dim oViewDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		If oViewDoc Is oModelDoc Then Continue For
		Dim oMatch As Boolean = False
		For Each oModelRef As Document In oModelRefs
			If oModelRef Is oViewDoc Then oMatch = True
		Next
		If oMatch = False Then oView.Delete
	Next
Next
If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
If oDDoc.Dirty Then oDDoc.Save2()

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

The deletion part of the code may also need to be a bit more complex too, because the view may be a 'parent' view that has 'child' views, such as a base view, which has other views projected from it, or a view that has a section or detail views based on it.  If that were the case, deleting the view may cause an error, because it doesn't know what to do about the 'child' or dependent views when you delete it.  The view may also have sketches, breaks, break outs, slices, crops, and such dependent on it.  Some of that stuff you can check for, but you can also use a Try...Catch block around the actual deletion line, to help avoid the potential errors.  I don't know if running it multiple times on the drawing may be necessary either, in case of the extra referenced document being an assembly, instead of just a simple part, that has its own set of referenced documents.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes