Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete all supressed in subassembly

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
992 Views, 9 Replies

Delete all supressed in subassembly

I have a assembly with al lot of subassemblies and parts. 

Different parts, subassemblies are supressed.

Also varies parts in the subassemblies have supressed parts in it.

 

Now i want to delete all the supressed parts in the top-assembly, but also in the subassemblies.

 

I have a rule wich can delete the patterns and the supressed parts.

But the problem is that this rule will only work on the top-assembly.

 

How can i delete all the supressed parts in the subassemblies?

 

This is my rule so far:

 

'Delete all supressed patterns
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oAsmDef As AssemblyComponentDefinition _
= oAsmDoc.ComponentDefinition

RunAgain:
oAsmDoc.Update
Dim oOccs As ComponentOccurrences = oAsmDef.Occurrences

For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then
If oOcc.IsPatternElement Then
Dim oPattern As RectangularOccurrencePattern _
= oOcc.PatternElement.Parent
oPattern.Delete
Goto RunAgain
End If
End If
Next

'Delete all supressed parts
Dim oComp As ComponentOccurrence
Dim oComps As ComponentOccurrences

oComps = ThisDoc.Document.ComponentDefinition.Occurrences

For Each oComp In oComps
If Component.IsActive(oComp.Name) = False Then oComp.Delete
Next

9 REPLIES 9
Message 2 of 10
humbertogo
in reply to: Anonymous

look at the TraverseAssemblySample

 

Accessing Assembly Components

Message 3 of 10
Anonymous
in reply to: Anonymous

Thank you for your reply, but the method from the TraverseAssemblySample isn't working when a part or assembly is suppressed, and the assembly has a Level Of Detail. 

 

Is there another way or workaround to delete the suppressed parts in a subassembly?

Message 4 of 10
Anonymous
in reply to: Anonymous

i would try this one, from the same site:

 

Public Sub GetPartOccurrences() 
    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
    Set oAsmDoc = ThisApplication.ActiveDocument 

    ' Get the assembly component definition. 
    Dim oAsmDef As AssemblyComponentDefinition 
    Set oAsmDef = oAsmDoc.ComponentDefinition 

    ' Get all of the leaf occurrences of the assembly. 
    Dim oLeafOccs As ComponentOccurrencesEnumerator 
    Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences 

    ' Iterate through the occurrences and print the name. 
    Dim oOcc As ComponentOccurrence 
    For Each oOcc In oLeafOccs 
        Debug.Print oOcc.Name 
    Next 
End Sub

 

Message 5 of 10
adam.nagy
in reply to: Anonymous

Hi,

 

If I understand the question correctly, then it is the traversing function pointed out that could be the solution. You'd just have to watch out for suppressed components when traversing:

http://adndevblog.typepad.com/manufacturing/2014/02/delete-suppressed-components.html

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 6 of 10
Anonymous
in reply to: adam.nagy

Thank you all for your replies.

 

Adam, your method does work, only when the assembly and/or subassembly have patterns with suppressed parts in it,

or the complete pattern is suppressed, the code will not work and gives an error.

 

Is there a way to delete the suppressed patterns and the suppressed parts in the patterns?

Thanks in advance.

Message 7 of 10
adam.nagy
in reply to: Anonymous

Could you attach a non-confidential set of documents that can be used to reproduce the issue?

 

One thing to watch out for is that an occurrence pattern (or probably other features as well) may rely on a suppressed component - e.g. for the directions of the rectangular pattern.

 

What is the actual reason that you are trying to delete the suppressed components? 

 



Adam Nagy
Autodesk Platform Services
Message 8 of 10
Anonymous
in reply to: adam.nagy

Sorry for the late reaction, but here is an attachment with an assembly which can occur in my situation.
I have added a rule with Adam's VBA rule in it.
This rule must be added in VBA, otherwise it won't work.

 

We always use the origin Axes for the direction of the patterns, so that isn’t the problem.


Some background info:
We have an full option conveyor which is ruled by iLogic.
We can change the length, width and height fully automatic.
So different parts and assemblies will be suppressed at the end.
If the engineer made his choice, we want to delete all the suppressed parts, to make the assembly definitive.

The reason that we want to delete the suppressed parts is that some
colleagues don't want work with LOD's, but that's an internal problem 😉
Until then we delete the suppressed parts.

The question now is how can we do this automatically?

It would be nice to have an external rule or VBA code, that we can use with new, but also with existing assemblies also.

 

Message 9 of 10
adam.nagy
in reply to: Anonymous

Hi,

 

I modified the code. It checks for the occurrence being used by patterns, but they could also be used by other featrues. So actually the best thing might be if instead of just checking if the occurrence is part of a pattern, you would place the occ.Delete inside a Try/Catch (in VBA On Error Resume Next / On Error GoTo 0) block, so if you cannot delete the occurrence for some reason then you just ignore it - nothing you can do anyway.

Sub DeleteSuppressedPatterns(cd As ComponentDefinition)
  If Not TypeOf cd Is AssemblyComponentDefinition Then
    Exit Sub
  End If
  
  Dim acd As AssemblyComponentDefinition
  Set acd = cd
  
  Dim op As OccurrencePattern
  For Each op In acd.OccurrencePatterns
    Debug.Print "Checking pattern " + op.name
    Dim allSuppressed As Boolean
    allSuppressed = True
    Dim ope As OccurrencePatternElement
    For Each ope In op.OccurrencePatternElements
      ' ope.Suppressed does not seem to give
      ' the correct value. Seems like we have to
      ' check all occurrences inside it instead
      Dim co As ComponentOccurrence
      For Each co In ope.Occurrences
        If Not co.Suppressed Then
          allSuppressed = False
          Exit For
        End If
      Next
      If Not allSuppressed Then
        Exit For
      End If
    Next
    
    If allSuppressed Then
      op.Delete
    End If
  Next
End Sub

Sub DeleteSuppressedComponent(occs As ComponentOccurrences, cd As ComponentDefinition)
  ' First delete the patterns, because
  ' if you try to delete an occurrence that is being used by a pattern
  ' then it will throw an error
  Debug.Print "Before Calling DeleteSuppressedPatterns: " + cd.Document.FullDocumentName
  Call DeleteSuppressedPatterns(cd)
  Debug.Print "After Calling DeleteSuppressedPatterns"
  
  Dim occ As ComponentOccurrence
  For Each occ In occs
    Debug.Print "Chekcing occurrence " + occ.name
    If occ.Suppressed Then
      ' If all the elements of a pattern were suppressed
      ' we deleted it by now. So if PatternElement is not
      ' Nothing, then this occurrence is part of a
      ' pattern where not all occurrences are suppressed
      ' and so we cannot delete it
      If occ.PatternElement Is Nothing Then
        occ.Delete
      End If
    Else
      Debug.Print "Before Calling DeleteSuppressedComponent: " + occ.name
      Call DeleteSuppressedComponent(occ.SubOccurrences, occ.Definition)
      Debug.Print "After Calling DeleteSuppressedComponent: "
    End If
  Next
End Sub

Sub DeleteSuppressedComponents()
    Dim doc As AssemblyDocument
    Set doc = ThisApplication.ActiveDocument
    
    Dim acd As AssemblyComponentDefinition
    Set acd = doc.ComponentDefinition
    
    Call DeleteSuppressedComponent(acd.Occurrences, acd)
End Sub

Cheers,



Adam Nagy
Autodesk Platform Services
Message 10 of 10
Anonymous
in reply to: adam.nagy

That is absolutly perfect. Great work Adam.

 

The final step in this case would be to set the LOD to Master, and delete all the LOD's named iLogic in de main- and subassemblies.

 

And then at the end delete all the existing rules in main and subassemblies.

I don't want to use the "Delete All Rules" button but run it straight from VBA in one code.

 

Is this possible in VBA and how would it look like?

Thanks in advance.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report