Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have an object collection obtained from the first Element of a pattern. I'd like to remove one object occurrence from that object collection, but I get a syntax error whatever I try. Here's the code:
Dim i As Integer Dim sCell as String Dim oDoc = ThisDoc.Document Dim oDef As AssemblyComponentDefinition oDef = oDoc.ComponentDefinition Dim oPattern As RectangularOccurrencePattern oPattern = oDef.OccurrencePatterns.Item("NomePattern") Dim oCompOcc As ComponentOccurrence Dim Elements as OccurrencePatternElements Elements = oPattern.OccurrencePatternElements() Trace.WriteLine("the pattern has " + Str(Elements.Count) + " elements" ) ' 1,1 is the first set of objects in the pattern Dim OPT as OccurrencePatternElement OPT = oPattern.OccurrencePatternElement(1,1) Dim Components As ObjectsEnumerator ' ObjectCollection Dim CompOcc As ComponentOccurrence Dim CompDef As PartComponentDefinition Dim sToDelete As String Dim sOccName As String Dim iColonPos As Integer Dim sInstanceName As String Components = OPT.Components() sToDelete = "30295480" ' Look at each occurrence and remove that with the sToDelete name For Each CompOcc in Components ' For i = 1 To Components.Count 'CompOcc = Components.Item (i) CompDef = CompOcc.Definition() sOccName = CompDef.Document.FullFileName() sInstanceName = CompOcc.Name () iColonPos = InStrRev (sInstanceName,":") ' "ABCDE:1" iColonPos becomes 6 sInstanceName = Left(sInstanceName,iColonPos-1) Trace.WriteLine("Component " + Str(i)+ " filename: " + sOccName + " in pattern name: " + sInstanceName) If sInstanceName = sToDelete Then ' ***HERE*** .... how to I remove the ith occurrence from the ObjectsEnumerator ' Trace.WriteLine ("Remove..." + Str(i)) ' Components.Remove (i) ' CompOcc.Delete End If Next
All seems to work, I get the names written out correctly, but I cannot remove any of the objects from the first Element. Manually this would move the occurrence from the first Pattern's element into the root of the assembly. But niether Delete nor Remove seemt to work.
I bet I've missed something obvious...
Solved! Go to Solution.