5 Replies Latest reply on Jul 25, 2012 10:46 PM by seajoe.li

    Questions about MGC Collection manipulating

    seajoe.li

      I am trying to get the collections of pins or nets. Frequently I get the error messages. I am using VB2005. Following is the example.

       

      Task:

           1. Get the collection of Pins of a component

           2. Remove the pin from the collection if the pin.net.netclass is POWER, GROUND or (Net0)

       

                Dim centerIC As IMGCPCBComponent = expdoc.FindComponent("U7")

                Dim centerIC_PINs As IMGCPCBPins = centerIC.Pins

       

      Code:

      For i As Integer = 1 To centerIC_PINs.Count

                  If Not centerIC_PINs(i) Is Nothing Then

                      Dim expnet As Net = centerIC_PINs(i).Net

       

                      If expnet.NetClass.Name = "POWER" Or expnet.NetClass.Name = "Ground" Or expnet.NumberOfOpens = 0 Then

       

                          centerIC_PINs.Remove(i)

       

       

                      End If

       

                  End If

      Next

       

      Problem:

      1. I found only (Net0) was removed, POWER and GROUND pins are still in the collection (I already set the netclasses in the CES).

      2. I must declare pins collection as Dim centerIC_PINs As IMGCPCBPins, otherwise error message will prompt when execute centerIC_PINs.Remove(i). Is there any difference if I use Dim Pins as MGCPCB.Pins?

      3. I tried to use another empty Pins Collection, for instance Apins, and add pin object if certain creteria is met. However, it does not work like following.

       

      Dim Apins As IMGCPCBPins

      For i As Integer = 1 To centerIC_PINs.Count

                  If Not centerIC_PINs(i) Is Nothing Then

                      Dim expnet As Net = centerIC_PINs(i).Net

       

                      If expnet.NetClass.Name <> "POWER" And expnet.NetClass.Name <> "Ground" And expnet.NumberOfOpens = 0 Then

                          ListBox1.Items.Add(expnet.Name & "//" & centerIC_PINs(i).Name)

                          If Not Apins Is Nothing Then

                              Apins.Add(centerIC_PINs(i))

                          End If

       

                      End If

       

                  End If

      Next

       

      I use the following to check the result:

       

      If Not Apins Is Nothing Then

                  MsgBox("A Pins after: " & Apins.Count)

      End If

       

       

      The message box can not show up, so the Apins is still NOTHING!

       

      Can anyone give me some hints? A general question is what's the guideline of the COM Collections usage under VB environment.