doubt in delete patterns of suppressed parts

doubt in delete patterns of suppressed parts

vdcrocks7
Contributor Contributor
452 Views
6 Replies
Message 1 of 7

doubt in delete patterns of suppressed parts

vdcrocks7
Contributor
Contributor

one doubt in delete patterns of suppressed parts, but if in pattern, pattern is Rectangular itself and its first instance is Circular pattern then my below code is not working.

 

' Delete suppressed patterns as well as suppressed parts

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 Object = oOcc.PatternElement.Parent
            If TypeOf oPattern Is CircularOccurrencePattern Or TypeOf oPattern Is RectangularOccurrencePattern Then
                oPattern.Delete
                GoTo RunAgain
            End If
        End If
    End If
Next

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



Can anyone help me on this: Thank you ion advance :)
0 Likes
453 Views
6 Replies
Replies (6)
Message 2 of 7

vdcrocks7
Contributor
Contributor

or vice versa pattern is Circular itself and its first instance is rectangular pattern then my code is not working.@WCrihfield , please help me on this 

0 Likes
Message 3 of 7

WCrihfield
Mentor
Mentor

Hi @vdcrocks7.  Multi-level patterns, which may contain other patterns within them can get pretty complicated to navigate and deal with by code.  They often require a recursive Sub routine to get to the top or bottom of, especially when not sure how many levels it may have (like me).  The purpose of a climbing recursive routine would be to keep checking 'parent' type properties, and if any are found, run the routine again on that parent, until no more parents are found, which indicates that you are at the top.  In this case, the RectangularOccurrencePattern.Parent property will always return the AssemblyComponentDefinition, so that will not be useful.  However, we can use the RectangularOccurrencePattern.ParentComponents property, which will give us an ObjectCollection with the 'input' components in it (the components that are being copied by the pattern).  Then, as we iterate through that collection, each item should be a ComponentOccurrence, so we can then use its ComponentOccurrence.IsPatternElement property And/Or its ComponentOccurrence.PatternElement property to get access to the OccurrencePatternElement object.  Then we can use its OccurrencePatternElement.Parent property, which says it returns an Object Type, but we can substitute the OccurrencePattern Type in there, if we want.  That is the base/common Type for all of the more specific component pattern Types (CircularOccurrencePattern, FeatureBasedOccurrencePattern, RectangularOccurrencePattern), because it could be any of those types.  That brings us full circle.

 

Edit:  Oh, I almost forgot to mention perhaps the most important (and troublesome) detail about this process...we can not delete the 'first' (input) element in any pattern, because that is what is being used as the basis for copying all the other elements in the pattern from.  Trying to do so will throw an error.  So, you can delete the other elements after the first one, but not the first element in the pattern.  If you need to delete that one, then you would either need to redefine the pattern to be based on a different component, or delete its whole parent pattern.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 7

vdcrocks7
Contributor
Contributor

Thnk you for your r

quick replay @WCrihfield . Yes you are correct , we can't delete first instance of pattern , is there any ilogic code that if my pattern is suppressed in assembly then it's directly delete pattern , and once this code run then if pattern of my first instance is pattern then our code will delete again pattern (that will run after delete main pattern ) and it'll run until we reached to single part / assembly . Once we reached to supreesed part or assembly then I've seprate code to delete that. And for delete pattern in assembly , can we identify assembly feature state and then delete that pattern ?  I don't know , this will possible or not.

0 Likes
Message 5 of 7

vdcrocks7
Contributor
Contributor

My main intension is to delete supressed pattern from my Inventor model browser list.

0 Likes
Message 6 of 7

_dscholtes_
Advocate
Advocate

@vdcrocks7 wrote:

 

<SNIP>

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 Object = oOcc.PatternElement.Parent
            If TypeOf oPattern Is CircularOccurrencePattern Or TypeOf oPattern Is RectangularOccurrencePattern Then
                oPattern.Delete
                GoTo RunAgain
            End If
        End If
    End If
Next
<SNIP>

Side-note: You don't need the 'Goto RunAgain' statement. I'm not sure how to explain it correctly, but when you use a 'For each <object> in <object list>' (e.g. oOcc In oOccs), the <object list> is treated like a dynamic collection in which you can add or delete <objects> without having to worry about the amount of <objects> in it.

Each iteration of the loop it will check if there are any <objects> in the <object list> and either continue or stop looping.

 

Also it's not preferred to hard exit a 'for each'-loop like this. You can use the 'exit for' command to nicely break out of the 'for each'-loop. After exitting the loop, you can check if you need to do the looping again. I'd recommend putting (nesting) your 'for each'-loop in a second loop (e.g. do-loop / while-wend) which runs as long as there are any suppressed occurrences in a pattern in your assembly.

0 Likes
Message 7 of 7

vdcrocks7
Contributor
Contributor

Hi @WCrihfield , thank you for explaining stuff how it works for multi-level pattern delete. But I'm not that much expert in ilogic, but Does solution available this kind of Problem/situation? If yes, could you please provide ilogic code, that will much appreciated!!

0 Likes