iLogic - delete a suppressed component pattern

iLogic - delete a suppressed component pattern

Anonymous
Not applicable
2,893 Views
7 Replies
Message 1 of 8

iLogic - delete a suppressed component pattern

Anonymous
Not applicable

Hello guys!

 

Curious if anyone knows how to modify the code below to delete suppressed parts in a pattern (entire pattern)?

	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

 Code works fine if there are single instances of the part. It throws a error when you have a suppressed pattern.

 

Thank you in advance.

Alex.

0 Likes
Accepted solutions (1)
2,894 Views
7 Replies
Replies (7)
Message 2 of 8

Vladimir.Ananyev
Alumni
Alumni
Accepted solution

If occurrence is a pattern element you have to delete its pattern object. Could you test the following sample iLogic rule.  It  deletes all suppressed rectangular patterns in the active assembly document.

 

  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

Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 8

Anonymous
Not applicable

Vladimir!

Thanks a lot. I have to use both codes together (your code 1st, my code in original posting 2nd) to be able to delete suppressed pattern and then suppressed parts.

 

Alex

0 Likes
Message 4 of 8

Anonymous
Not applicable

do you know hoy to delete a derived part in inventor using ilogic ?

0 Likes
Message 5 of 8

Anonymous
Not applicable

 

Try this:

doc = ThisDoc.Document
Dim compOcc As ComponentOccurrence =Component.InventorComponent("PartA:1")
compOcc.Delete()

 

doc = ThisDoc.Document
Dim compOcc As ComponentOccurrence = Component.InventorComponent("PartA:1")
compOcc.Delete()

0 Likes
Message 6 of 8

Anonymous
Not applicable

but ,  isnt an assembly , just derived part in the simple model

0 Likes
Message 7 of 8

Vladimir.Ananyev
Alumni
Alumni

You have to break link and then delete derived component.

Here is a quick test:

Private Sub DerivedComponent_SuppressLink()
  Dim oPartDoc As PartDocument
  Set oPartDoc = ThisApplication.ActiveDocument
  Dim oPartDef As PartComponentDefinition
  Set oPartDef = oPartDoc.ComponentDefinition
  Dim oDerivedComponent As DerivedPartComponent
  Set oDerivedComponent = oPartDef.ReferenceComponents _
        .DerivedPartComponents.Item(1)
  ' break link to file and delete derived component
  Call oDerivedComponent.BreakLinkToFile
  Call oDerivedComponent.Delete
End Sub

 Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 8 of 8

Anonymous
Not applicable

sorry im new , i have some error ,  this is my model attached , could you help me to resolve it  ?

0 Likes