iLogic - Delete Suppressed Rectangular & Circular Patterns

iLogic - Delete Suppressed Rectangular & Circular Patterns

josh_cooney
Participant Participant
1,054 Views
9 Replies
Message 1 of 10

iLogic - Delete Suppressed Rectangular & Circular Patterns

josh_cooney
Participant
Participant

I have found how others have deleted suppressed patterns that are rectangular OR circular, but not both.

 

Here is what I'm using, which works great unless a suppressed RectangularOccurrencePattern also exist, then I get an error.  Please help.

 

 

SyntaxEditor Code Snippet

  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 oCPattern As CircularOccurrencePattern = oOcc.PatternElement.Parent
        oCPattern.Delete
            Goto RunAgain
      End If
    End If
  Next

 

0 Likes
Accepted solutions (1)
1,055 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Hi Josh,

 

I have a VBA code that might fulfill your requirement

 

Code Snippet

 

 Dim oAsmDoc As AssemblyDocument
  Set oAsmDoc = ThisApplication.ActiveDocument
  Dim oAsmDef As AssemblyComponentDefinition
  Set oAsmDef = oAsmDoc.ComponentDefinition
    
RunAgain:
  oAsmDoc.Update
  Dim oOccs As ComponentOccurrences
  Set oOccs = oAsmDef.Occurrences
  Dim oOcc As ComponentOccurrence
  For Each oOcc In oOccs.AllLeafOccurrences
        Dim oCPatternFeatures As CircularPatternFeatures
        Set oCPatternFeatures = oOcc.Definition.Features.CircularPatternFeatures
        Dim oCPattern As CircularPatternFeature
        For Each oCPattern In oCPatternFeatures
            If oCPattern.Suppressed = True Then
                oCPattern.Delete
            End If
        Next
      
  Next

 

If you find this was helpful please accept this as a solution / kudos.

0 Likes
Message 3 of 10

josh_cooney
Participant
Participant

Thank you for the attempt, but if I convert this from VBA, it's going to try to delete the Circular Pattern, which my iLogic code was already doing.  I'm trying to delete a suppressed pattern whether it's Rectangular and/or Circular.  Thanks again.

0 Likes
Message 4 of 10

Anonymous
Not applicable

I have modified the code. Hope this is going to help you

 

 Dim oAsmDoc As AssemblyDocument
  Set oAsmDoc = ThisApplication.ActiveDocument
  Dim oAsmDef As AssemblyComponentDefinition
  Set oAsmDef = oAsmDoc.ComponentDefinition
    
RunAgain:
  oAsmDoc.Update
  Dim oOccs As ComponentOccurrences
  Set oOccs = oAsmDef.Occurrences
  Dim oOcc As ComponentOccurrence
  For Each oOcc In oOccs.AllLeafOccurrences
        Dim oCPatternFeatures As CircularPatternFeatures
        Set oCPatternFeatures = oOcc.Definition.Features.CircularPatternFeatures
        Dim oCPattern As CircularPatternFeature
        For Each oCPattern In oCPatternFeatures
            If oCPattern.Suppressed = True Then
                oCPattern.Delete
            End If
        Next
        Dim oRPatternFeatures As RectangularPatternFeatures
        Set oRPatternFeatures = oOcc.Definition.Features.RectangularPatternFeatures
   
         Dim oRPattern As RectangularPatternFeature
        For Each oRPattern In oRPatternFeatures
            If oRPattern.Suppressed = True Then
                oRPattern.Delete
            End If
        Next
  Next

If you find this was helpful please accept this as a solution / kudos.Smiley Wink

0 Likes
Message 5 of 10

josh_cooney
Participant
Participant

Thanks for the update.  I don't know VBA very well, so I'm working on converting your VBA into iLogic, but I'm not having success yet.  Give me a few more days and I'll respond again hopefully with solved.

0 Likes
Message 6 of 10

Anonymous
Not applicable

I have created a ilogic rule for you it works for me. Hope it is gonna work for you to.

 

Dim oAsmDoc As AssemblyDocument
   oAsmDoc = ThisApplication.ActiveDocument
  Dim oAsmDef As AssemblyComponentDefinition
   oAsmDef = oAsmDoc.ComponentDefinition
    
RunAgain:
  oAsmDoc.Update
  Dim oOccs As ComponentOccurrences
   oOccs = oAsmDef.Occurrences
  Dim oOcc As ComponentOccurrence
  For Each oOcc In oOccs.AllLeafOccurrences
        Dim oCPatternFeatures As CircularPatternFeatures
         oCPatternFeatures = oOcc.Definition.Features.CircularPatternFeatures
        Dim oCPattern As CircularPatternFeature
        For Each oCPattern In oCPatternFeatures
            If oCPattern.Suppressed = True Then
                oCPattern.Delete
            End If
        Next
        Dim oRPatternFeatures As RectangularPatternFeatures
         oRPatternFeatures = oOcc.Definition.Features.RectangularPatternFeatures
   
         Dim oRPattern As RectangularPatternFeature
        For Each oRPattern In oRPatternFeatures
            If oRPattern.Suppressed = True Then
                oRPattern.Delete
            End If
        Next
		
  Next

If you find this was helpful please accept this as a solution / kudos.Smiley Wink

0 Likes
Message 7 of 10

josh_cooney
Participant
Participant

Sorry, but I can't get this to work for me.  I'm using Inventor 2016 Professional if that matters?  What version are you using?  I know Autodesk changes things and what works for one version may not work for another.  If anyone else has an idea using 2016, please let me know.  Thanks for trying, Josh.

0 Likes
Message 8 of 10

adam.nagy
Autodesk Support
Autodesk Support
Accepted solution

Hi Josh,

 

I'll go back to your original code because it sounds like you just need to make it generic.

I guess this is the error you were getting with it - in the future could you please point out the error you are getting? 🙂

SuppressedPattern.png

 

It's because of this line where you are trying to treat the Parent as a CircularOccurrencePattern, but it is a RectangularOccurrencePattern >> ERROR:

Dim oCPattern As CircularOccurrencePattern = oOcc.PatternElement.Parent

Just make the line generic by not declaring its type or declaring it as Object:

Dim oCPattern As Object = oOcc.PatternElement.Parent

Cheers,



Adam Nagy
Autodesk Platform Services
Message 9 of 10

josh_cooney
Participant
Participant

Thank you very much Adam!  Just one small change is all it took.....

 

On a personal note, what is the best method for learning advanced iLogic?

 

Thanks again,

Josh

0 Likes
Message 10 of 10

adam.nagy
Autodesk Support
Autodesk Support

"Advanced iLogic" simple means "using Inventor API" (iLogic is built on top of it as well)

 

You could go to http://autodesk.com/developinventor

That has links to the blogs, training materials and "My First Inventor Add-In" tutorial.

 

I hope this helps.



Adam Nagy
Autodesk Platform Services
0 Likes