Deleting parts in a subassembly from a top level Ilogic Rule

Deleting parts in a subassembly from a top level Ilogic Rule

JamesMeBoi
Enthusiast Enthusiast
1,353 Views
5 Replies
Message 1 of 6

Deleting parts in a subassembly from a top level Ilogic Rule

JamesMeBoi
Enthusiast
Enthusiast

Does anyone have any Idea how to delete parts from a subassembly through a rule written in the top level?

 

I have tried already

Components.Delete("P00022235:5")

 

Accepted solutions (2)
1,354 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Have you tried incorporating the MakePath iLogic snippet into that line, like what is shown within the iLogic snippet called "IsActive(MakePath)" (under the "Components (classic)" group, within the System snippets?  That should allow you to specify the sub assembly name, then the sub component's name.

Components.Delete(MakePath("SubAssem1:1", "Part2:1"))

 

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor
Accepted solution

If you don't think that iLogic snippet will work for you needs, there are multiple other ways to delete a component from within a sub assembly, from the main assembly.  If you don't want to have to specify the sub assembly's browser node name, and/or don't want to have to specify the component's browser node name, we may be able to identify them in other ways too.  Just let us know how you would like to find/identify the component.

Here is another fairly simple iLogic rule code you could use, that also allows you to identify them by their browser node names.

Dim oADoc As AssemblyDocument = ThisDoc.Document
oOccs = oADoc.ComponentDefinition.Occurrences
'<<< specify the name of the sub assembly that your part is within >>>
'the name shown in the 'Model Browser' of the main assembly for it
oSubAsmOcc = oOccs.ItemByName("SubAssem1:1")
'<<< specify the name of the component within that sub assembly >>>
'the name shown in the 'Model Browser' of the main assembly for it
oSubOcc = oSubAsmOcc.Definition.Occurrences.ItemByName("P00022235:5")
Try
	oSubOcc.Delete
	'oSubOcc.Delete2(True)
Catch oEx As Exception
	MsgBox("Component Deletion Failed." & vbCrLf & _
	oEx.Message & vbCrLf & oEx.StackTrace,vbExclamation,"iLogic")
End Try
Dim oSubAsmDoc As Document = oSubAsmOcc.Definition.Document
oSubAsmDoc.Update 'or oSubAsmDoc.Update2(True)
oADoc.Update 'or oADoc.Update2(True)

Keep in mind that the component you are trying to delete is in another assembly document, and there may be constraints, representations, model states, or other types of dependencies on, or references to that component within that other assembly that might complicate your ability to delete it.

 

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 6

JamesMeBoi
Enthusiast
Enthusiast
Thank you my friend
Message 5 of 6

jef.clissen
Contributor
Contributor

We've used this ilogic snippet for a while but this no longers seems to work in IV2023. 

Can anyone else confirm this behavior?

 

Thanks

 

0 Likes
Message 6 of 6

Curtis_Waguespack
Consultant
Consultant
Accepted solution

For Lisa:

Delete Component In Subassemblies 2022.zip

 

 

Sub Main
	iLogicVb.UpdateWhenDone = True

	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences

	Call TraverseAssembly(oOccs)

End Sub

Function TraverseAssembly(oOccs As ComponentOccurrences)

	Dim oOcc As ComponentOccurrence
	For Each oOcc In oOccs
		
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			If oOcc.Name.Contains("Shaft Assembly") Then
				Dim iDoc As AssemblyDocument
				iDoc = ThisApplication.Documents.Open(oOcc.Definition.Document.fullfilename, false)
				For Each iOcc In iDoc.ComponentDefinition.Occurrences
					If iOcc.Name.Contains("Thing 3") Then
						iOcc.Delete
					End If
				Next
				iDoc.Close(False)					
			End If	
		End If
	Next
End Function

EESignature