Author Topic: RemovePartialMenu quit working  (Read 1310 times)

0 Members and 1 Guest are viewing this topic.

57gmc

  • Newt
  • Posts: 93
RemovePartialMenu quit working
« on: April 29, 2010, 11:32:54 AM »
I had created the function below. It was working, but now, when you run it, it finds the cui and executes the RemovePartialMenu method, and the count decrements, but the cui doesn't actually get removed. The next time you run it, PartialCuiFiles.Count is back to what it was and the cui is still there. I'm on 2010.
Code: [Select]
        Friend Function UnloadPartialCui(ByVal PartialCuiPath As String) As Boolean
            'CuiPath parameter is the fully qualified path of the partial cui to be removed from main cui.

            Try
                Dim strParentCui As String = Application.GetSystemVariable("MENUNAME") & ".cuix"
                Dim oMainCui As CustomizationSection = New CustomizationSection(strParentCui)

                For i = 0 To oMainCui.PartialCuiFiles.Count - 1
                    If oMainCui.PartialCuiFiles.Item(i).ToLower = PartialCuiPath.ToLower Then
                        oMainCui.RemovePartialMenu(PartialCuiPath)
                    End If
                Next

            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                Return False
            Catch ex As System.IO.FileNotFoundException
                Return False
            Finally
                UnloadPartialCui = True
            End Try

        End Function

57gmc

  • Newt
  • Posts: 93
Re: RemovePartialMenu quit working
« Reply #1 on: August 03, 2010, 04:33:55 PM »
This is what I ended up with.
Code: [Select]

        Friend Function UnloadPartialCui(ByVal PartialCuiPath As String) As Boolean
            'CuiPath parameter is the fully qualified path of the partial cui to be removed from main cui.

            Try
                Dim strParentCui As String = Application.GetSystemVariable("MENUNAME") & ".cuix"
                Dim oMainCui As CustomizationSection = New CustomizationSection(strParentCui)

                For i = 0 To oMainCui.PartialCuiFiles.Count - 1
                    If oMainCui.PartialCuiFiles.Item(i).ToLower = PartialCuiPath.ToLower Then
                        oMainCui.RemovePartialMenu(PartialCuiPath)
                        Return True   'step out of loop, now that it is out of sync with Count.
                    End If
                Next

            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                Return False
            Catch ex As System.IO.FileNotFoundException
                Return False
            Finally

            End Try

        End Function

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: RemovePartialMenu quit working
« Reply #2 on: August 05, 2010, 10:39:03 AM »
A better way is to iterate backwards:
Code: [Select]
  for (int i = somevar.Count - 1; i >=0; i--) {
    // some intersting mojo to remove here...
  }

Or, if the collection supports it, the generic RemoveAll(predicate goes here) method.
Me