ilogic code to delete unused sketches in parts

ilogic code to delete unused sketches in parts

BasVanVelsen5347
Explorer Explorer
286 Views
2 Replies
Message 1 of 3

ilogic code to delete unused sketches in parts

BasVanVelsen5347
Explorer
Explorer

Hello,

I have attached an assembly consisting out of parts and a subassembly.
All the parts that are used have an unused sketch that I want to delete.

Preferably I want to run an ilogic code from the toplevel assembly. 

 

I managed to create this ilogic code from some examples in this forum that works when started on a part level.
Hope you can help.
Thanks,
Bas

Sub Main()

    Dim oDoc As Document = ThisApplication.ActiveDocument
    Dim oCD As ComponentDefinition= oDoc.ComponentDefinition

    Dim oSketch As PlanarSketch
    For Each oSketch In oCD.Sketches
        oSketch.Delete
    Next

End Sub

 

0 Likes
Accepted solutions (1)
287 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @BasVanVelsen5347.  You can try this iLogic code if you want. 

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
For Each oRefDoc As Document In oRefDocs
	If Not oRefDoc.IsModifiable Then Continue For
	Dim oSketches As PlanarSketches = oRefDoc.ComponentDefinition.Sketches
	For Each oSketch As PlanarSketch In oSketches
		If oSketch.Consumed = False Then
			Try
				oSketch.Delete
			Catch
				MsgBox("Could not delete sketch named " & oSketch.Name & vbCrLf & _
				"within the following document" & vbCrLf & oRefDoc.FullDocumentName,,"")
			End Try
		End If
	Next 'oSketch
Next 'oRefDoc
oADoc.Update

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)

Message 3 of 3

BasVanVelsen5347
Explorer
Explorer

Hi WCrihfield, your code is working perfect.
Thanks for the quick reply.
Bas

0 Likes