delete all suppressed parts in assembly (and sub assembly)

delete all suppressed parts in assembly (and sub assembly)

robbeRtek
Advocate Advocate
1,138 Views
4 Replies
Message 1 of 5

delete all suppressed parts in assembly (and sub assembly)

robbeRtek
Advocate
Advocate
Hello,

I need a script to delete all suppressed parts.

i've try to write the code (ilogic) :

Public
Function DeletesuppressedParts() Dim OAsmDoc As AssemblyDocument OAsmDoc = ThisApplication.ActiveDocument Dim oAsmDef As ComponentDefinition = OAsmDoc.ComponentDefinition oAsmDef.RepresentationsManager.LevelOfDetailRepresentations.Item("configuratie").Activate(True) For Each oOcc As ComponentOccurrence In OAsmDoc.ComponentDefinition.Occurrences If oOcc.Suppressed Then oOcc.Delete() Else Dim osubOcc As ComponentOccurrence If oOcc.SubOccurrences.Count > 0 Then For Each osubOcc In oOcc.SubOccurrences If osubOcc.Suppressed Then osubOcc.Delete() End If Next End If End If Next oAsmDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master").Activate(True) End Function

The line : osubOcc.Delete() do nothing, here i need to delete a suppressed part in a sub assembly
(I am unable to remove parts in a sub assembly)
 
 

does anyone know a solution for this?
 
 
0 Likes
Accepted solutions (1)
1,139 Views
4 Replies
Replies (4)
Message 2 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

Try to iterate through all assembly levels using a recursive call:

 

 

Option Explicit on

Private Sub Main()
	Dim oAssDoc As AssemblyDocument = ThisDoc.Document
	Dim oAsmDef As ComponentDefinition = OAssDoc.ComponentDefinition
	oAsmDef.RepresentationsManager.LevelOfDetailRepresentations.Item("configuratie").Activate(True)
	DelSuppressedOccs(oAssDoc.ComponentDefinition.Occurrences)
	oAsmDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master").Activate(True)
End Sub

Private Sub DelSuppressedOccs(ByVal oOccs As ComponentOccurrences)
    Dim oOcc As ComponentOccurrence
    For Each oOcc In oOccs
        If oOcc.Suppressed = True Then
            oOcc.Delete
        Else
            If oOcc.SubOccurrences.Count > 0 Then
                DelSuppressedOccs(oOcc.SubOccurrences)
            End If
        End If
    Next
End Sub

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 5

robbeRtek
Advocate
Advocate

Thanks,

the idea is good, but it doen't work for parts in a sub assembly

i've found simialar code,  if i create a new rule and paste this code, the code works. it delete also the parts in the sub assembly

Sub Main()
  Dim doc As AssemblyDocument
  doc = ThisApplication.ActiveDocument

  Dim acd As AssemblyComponentDefinition
  acd = doc.ComponentDefinition

  Call DeleteSuppressedComponent(acd.Occurrences)
 ' MessageBox.Show("Message", "Title")

End Sub

Sub DeleteSuppressedComponent(occs As ComponentOccurrences)
  Dim occ As ComponentOccurrence
  For Each occ In occs
     If occ.Suppressed Then
         occ.Delete
     Else
         Call DeleteSuppressedComponent(occ.SubOccurrences)
     End If
   Next
End Sub

at this point i'll add the rule to the main code : 

 

Sub main
	If RunRule = True Then
		Dim oTopAsmDoc As AssemblyDocument
		Try
			oTopAsmDoc = ThisApplication.ActiveDocument
			oTopAsmDoc.Save
		Catch
			MessageBox.Show("only assembly", "only assembly")
			Exit Sub
		End Try
		
		
		iLogicVb.RunRule("delete parts")

'		other functions

''		CopyComponents(ThisDoc.Path, ThisDoc.Document.DisplayName, "deuren")

''		iLogicVb.RunRule("Layout update")
'....

		MessageBox.Show("end", "end code")
	End If
	RunRule = False

End Sub

'functions ...

 

the change of the parameter 'runrule', starts a other rule to delete all code and parameters when the main code is finish

If RunRule = False Then
	Dim OAsmDoc As AssemblyDocument
	OAsmDoc = ThisApplication.ActiveDocument
	Dim oAsmDef As ComponentDefinition = OAsmDoc.ComponentDefinition
	oAsmDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master").Activate(True)
	oAsmDef.RepresentationsManager.LevelOfDetailRepresentations.Item("configuratie").delete
	iLogicVb.Automation.DeleteAllRulesInDocument(OAsmDoc)
'delete parameters...
End If

now i thought i was done , but after run the main code, the Suppressed parts in the sub assembly are still there, in the main they're gone....

 

'ive try to figure out why but i don't find the answer :

- i've delete al the functions so the only code left is the code in this post.

-if i suppress the (last)rule to 'delete code/parameters' and run the main code  (with only the funtion 'delete parts'), the code works, the suppressed parts in the sub assembly are gone (ok)

-now i unsuppesses the code to delete the rules (last rule)  and run again

the suppressed parts in the sub assembly are not gone ( not ok)

 

why??

 

0 Likes
Message 4 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

I've tested my code multiple times and it works as expected all time. Comparing your code there's no difference in function.

If you have a suppressed subassembly and suppressed parts within and want to delete both, you better switch the order in recursion. You first need to dive into and delete subassembly afterwards.

Option Explicit on

Private Sub Main()
	Dim oAssDoc As AssemblyDocument = ThisDoc.Document
	Dim oAsmDef As ComponentDefinition = OAssDoc.ComponentDefinition
	oAsmDef.RepresentationsManager.LevelOfDetailRepresentations.Item("configuratie").Activate(True)
	DelSuppressedOccs(oAssDoc.ComponentDefinition.Occurrences)
	oAsmDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master").Activate(True)
End Sub

Private Sub DelSuppressedOccs(ByVal oOccs As ComponentOccurrences)
    Dim oOcc As ComponentOccurrence
    For Each oOcc In oOccs
        If oOcc.SubOccurrences.Count > 0 Then
            DelSuppressedOccs(oOcc.SubOccurrences)
        End If
        If oOcc.Suppressed = True Then
            oOcc.Delete
        End If
    Next
End Sub

 

 

Is the last rule, deleting all rules an internal rule? If so, deleting a running rule...find the error. If the last rule is an external rule, I can think of changing the parameter triggers the last rule to run. As an event triggered rule, the rule changing the parameter is stopped right at the point of changing parameter run rule and waiting for last rule to finish. If so, a running rule could not be deleted.

That doesn't explain why suppressed parts in subassembly are still there. Is the deleteparts function embraced in a try catch statement catching errors silently?

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 5 of 5

robbeRtek
Advocate
Advocate
Accepted solution

 

we work still in inventor2019.

 

the reason of all the proplems is de lod,

delete a part or component with code, and then change the lod to master in the same run doesn't work correct, (the suppressed parts  in a sub assembly are still there or back again)

the solution is to save before change the lod to master. 

but i'dont want to save that assembly again befor there is a copy (with other name). (similiar to ilogic design copy)

(i don't want change the origial assembly (delete some parts))

so first i need to copy  the hole assembly and then delete the parts, save, and change the lod to master and then delete al rules, lod, parameters...

 

0 Likes