Clear Assembly

Clear Assembly

colehodge
Observer Observer
497 Views
2 Replies
Message 1 of 3

Clear Assembly

colehodge
Observer
Observer

I am trying to delete all parts from an assembly using ilogic. The assembly is for automating a commonly made structure with customizable length, width, and height.

 

The assembly currently creates parts from the content center and renames and saves them with a uniform style (ex. 99-9999-999-99-001). Only content center parts are used, but the same part may have several occurrences.

 

I have a form that changes the critical parameters and part name. Each time the name is changed the assembly creates new parts but leaves the old parts.

 

I would like to clear the assembly upon opening the assembly and/or after it saves the generated assembly as a new document for ease of use. This should make it so only the correct parts make it into the new assembly.

 

In case needed, here is the method I am using to name new parts:

'for all parts
'store path of this assembly for saving part
Dim Path As String = ThisDoc.Path 'store job number from form for naming Dim PartName As String = JN 'part001 'create and store part document name Dim FN1 As String = PartName & "-" & "001" & ".ipt" 'store document location Dim FL1 As String = Path & "\" & FN1 'store part name Dim part1Name As String = PartName & "-" & "001"

Thank you for any replies.

 

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

WCrihfield
Mentor
Mentor
Accepted solution

Hi @colehodge.  Your routine sounds complicated, but if you are just looking for an iLogic rule that will delete all of the components out of an assembly, which sounds overly simple, then the below iLogic code may work for you.  As for triggering this rule to run when certain events happen, you may be able to put this rule under an available event in the Event Triggers dialog, which can be found in the Manage tab > iLogic panel.

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 oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs
	Try
		oOcc.Delete2(False) 'False = skip saving source doc
	Catch
		Logger.Error("Error deleting component named:  " & oOcc.Name)
	End Try
Next

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

colehodge
Observer
Observer

Yes, thank you! I was trying to make something in the same rule, but this works perfect when placed under the "After Open Document" event trigger.

0 Likes