Deleting Sub-assemblies using ilogic

Deleting Sub-assemblies using ilogic

Anonymous
Not applicable
943 Views
10 Replies
Message 1 of 11

Deleting Sub-assemblies using ilogic

Anonymous
Not applicable

I am needing help writing some code to delete sub-assemblies using ilogic based on excel parameters. I have been able to write code to delete features and components out of sheet metal parts but can't seem to figure out how to do it in an assembly. I figured out how to suppress a sub-assembly but that doesn't really do me much good. I am very new to ilogic and any help would be very much appreciated. 

0 Likes
944 Views
10 Replies
Replies (10)
Message 2 of 11

FINET_Laurent
Advisor
Advisor

Can you give few more dedails regarding the actual iussue and the goal ?

It is a bit confusing (in my opinion)..

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 11

Anonymous
Not applicable

I guess basically I have an assembly within an assembly and am trying to delete it using an if/else statement in iLogic.

0 Likes
Message 4 of 11

FINET_Laurent
Advisor
Advisor
If "Magic" = True Then	 
	
	Dim CompOcc As ComponentOccurrence = Component.InventorComponent("Sub assembly:1")
		CompOcc.Delete
		
End If

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 5 of 11

Anonymous
Not applicable

Thanks for the help. I tried the code but I keep getting an error with it saying "The parameter is incorrect". I did try the exact same code but changed CompOcc.Delete to CompOcc.Suppress and it suppress the sub-assembly. For some reason .Delete doesn't delete them.

Message 6 of 11

FINET_Laurent
Advisor
Advisor

Weird.. =)I'm using Inventor 2019 and it works fine with delete.

 

Anyway, glad I could help.

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 7 of 11

J-Camper
Advisor
Advisor

Here is a way to do it by letting the user pick.  It could be modified to look for a particular name to automatically delete if you want:

Dim ocList As New List(Of String)
For Each oc As ComponentOccurrence In ThisApplication.ActiveDocument.ComponentDefinition.Occurrences
	If oc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then ocList.Add(oc.Name)
Next
Dim Selection As String = InputListBox("", ocList, ocList.Item(0), Title := "Item to Remove", ListName := "Sub Assemblies")
If IsNothing(Selection) Then Exit Sub 'No selection made
ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.ItemByName(Selection).Delete

Let me know if you have any questions, or if it is not working as intended

 

0 Likes
Message 8 of 11

Anonymous
Not applicable

I tried it out, but it gave me a"Member Not Found" error. I also would need to modify it to run off an if/else statement, because the people using the program wouldn't know what to do. I appreciate your help.

0 Likes
Message 9 of 11

Anonymous
Not applicable

Hello @Anonymous . What would be the basis or th condition of deleting the sub-assembly? Is it going to be based on filename, iproperties, etc. 

 

Here is the rule that will delete sub-assembly if the filename contains certain string.

 

Dim asmDoc As AssemblyDocument
asmDoc = ThisApplication.ActiveDocument

Key = InputBox("DELETE SUB-ASSEMBLY WITH THE FILENAME THAT CONTAINS", "DELETE SUB-ASSEMBLY WITH THE FILENAME THAT CONTAINS", " ").ToLower


Dim asmDef = asmDoc.ComponentDefinition
For Each occ As ComponentOccurrence In asmDef.Occurrences
	occName = occ.Name.ToLower
	If occName.Contains(Key)Then
		occ.Delete
	End If
Next
 

 

0 Likes
Message 10 of 11

Anonymous
Not applicable

The way i was seeing it would be like:

If option1 = 1 then  delete "TLHO3" and it's Patterns

Screenshot 2020-10-29 162246.jpg

Thanks

0 Likes
Message 11 of 11

J-Camper
Advisor
Advisor

I see, so you want to delete the Patterns of a particular PatternElement Occurrence?  There is a lot to consider at each step, will there be multiple occurrences per PatternElement or does each occurrence that gets patterned have it's own set of Patterns?

 

The Code below will collect all parent patterns of a selected occurrence and deletes them [It does not check to see if multiple occurrences were patterned in the same ComponentPattern]:

Sub Main
Dim ocList As New List(Of String)
For Each oc As ComponentOccurrence In ThisApplication.ActiveDocument.ComponentDefinition.Occurrences
	If oc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then ocList.Add(oc.Name)
Next
Dim Selection As String = InputListBox("", ocList, ocList.Item(0), Title := "Item to Remove", ListName := "Sub Assemblies")
If IsNothing(Selection) Then Exit Sub 'No selection made
	
'Use from here down with your desired Occurrence:	
	
Dim selOcc As ComponentOccurrence = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.ItemByName(Selection)
Dim pFeature As Object = selOcc.PatternElement.Parent

If selOcc.IsPatternElement
	Dim Col As ObjectCollection = FindTopMostParent(selOcc)
	Dim i As Integer = Col.Count
	While i > 0
		Col.Item(i).Delete
		i = i-1
	End While
End If

selOcc.Delete

End Sub

Function FindTopMostParent(Oc As ComponentOccurrence) As ObjectCollection
	Dim Result As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	Dim level1 As OccurrencePattern = Oc.PatternElement.Parent
LoopHere :
	Result.Add(level1)
	If level1.IsPatternElement
		level1 = level1.PatternElement.Parent
		GoTo LoopHere
	End If
	Return Result
End Function

Let me know if you have any questions, or if it is not working as intended

0 Likes