2 Replies Latest reply on Mar 7, 2011 11:20 AM by mans.joling

    How do I get a collection of properties on a part using MGCPCBPartsEditor and C#


      I'm trying to convert my scripts from vb to c#.  I wrote a template for getting info on parts from the library a while back: http://communities.mentor.com/thread/4752 my vb code is at the bottom or you can view it here.


      'Iterates through each part in each partition and collects the needed info for oracle and DxDatabook


      Dim partitions As MGCPCBPartsEditor.Partitions

      Dim partition As MGCPCBPartsEditor.Partition

      Dim parts As MGCPCBPartsEditor.Parts 

      Dim part As MGCPCBPartsEditor.Part

      Dim cellRefs As MGCPCBPartsEditor.CellReferences

      Dim cellRef As MGCPCBPartsEditor.CellReference


      Dim symbs As MGCPCBPartsEditor.SymbolReferences

      Dim symb As MGCPCBPartsEditor.SymbolReference


      Dim props As MGCPCBPartsEditor.Properties 

      Dim prop As MGCPCBPartsEditor.Property


      'Get the collection of partitions in the parts editor

      partitions = docPED.Partitions


      'Step through each partition in the parts editor


      For Each partition In partitions


      'Get the collection of parts in the current partition

      parts = partition.Parts


      'Step through each part in the parts collection


      For Each part In parts


      'Collect part information here


      'Get the collection of cells for the current part

      cellRefs = part.CellReferences


      'Step through each cell in the cells collection


      For Each cellRef In cellRefs


      'Collect cell information here




      'Get the collection of symbols for the current part

      symbs = part.SymbolReferences


      'Step through each symbol in the symbols collection


      For Each symb In symbs


      'Collect symbol information here




      'Get the collection of properties on the current part

      props = part.Properties


      'Step through each property in the properties collection


      For Each prop In props


      'Collect properties information here

      propList.Add(prop.Name & ": " & prop.Value)





      The issue I am having is finding how to collect the properties for the specific part now.  In C# I had to change how I got the collection of symbols and cells which ended up looking like:

      symbs = part.get_SymbolReferences();


      unfortunately there is no get_properties() call available for MGCPCBPartsEditor.Part


      How do I get the collection of properties associated with a part without knowing in advance the names of the properties.

        • 1. Re: How do I get a collection of properties on a part using MGCPCBPartsEditor and C#

          nevermind, its monday and I'm an idiot...  its done exaclty the same way in the vb example...

          • 2. Re: How do I get a collection of properties on a part using MGCPCBPartsEditor and C#

            Hello Andrew,


            This has been published in the past

            May be you can use this



            using System;
            using System.IO;
            using System.Runtime.InteropServices;
            using MGCPCBPartsEditor;
            namespace LoaderConsoleApp
            class Program
              public static System.Diagnostics.Stopwatch SWatch = new System.Diagnostics.Stopwatch();
              static void Main(string[] args)
                            FileInfo Libfile = new FileInfo(@"C:\Wdir\XX79\xxxxxx.lmc");
               IMGCPDBPartsEditorDlg PE = new MGCPCBPartsEditor.PartsEditorDlg(); //Lib.PartEditor;
               Console.WriteLine("Opening Database file " + Libfile.FullName + " readonly.");
               string FileName = Path.Combine(Path.GetTempPath(), "PDBCSharpTest.txt");
               Console.WriteLine("Dumping to " + FileName);
               using (StreamWriter SW = new StreamWriter(FileName, false, System.Text.Encoding.GetEncoding("iso-8859-15")))
                SW.WriteLine("PDB " + Libfile.Name + " at " + Libfile.FullName);
                int PartCount=dumpActiveLib(PE,SW);
                Console.WriteLine("Finished extracting " + PartCount + " parts after " + Program.SWatch.Elapsed.ToString());
                Console.WriteLine("Press any key to continue...");

              public static int dumpActiveLib(MGCPCBPartsEditor.IMGCPDBPartsEditorDlg PartsEditorDialog, TextWriter Wr)
               IMGCPDBPartsDB PartsDb = PartsEditorDialog.ActiveDatabaseEx;
               int PartIndex = 0;
               //Console.WriteLine("Dumping parts. Do you also get the strange locking issues?");
               foreach (MGCPCBPartsEditor.IMGCPDBPartition Partition in PartsDb.get_Partitions())
                Wr.WriteLine("Dumping parts for partition " + Partition.Name);
                foreach (IMGCPDBPart Part in Partition.Parts)
                 Wr.WriteLine(Part.Number + " " + Part.Name + " " + Part.Label + " " + Part.TypeString + " " + (int)Part.Type);
                 Wr.WriteLine("\t Description: " + Part.Description);
                 Wr.WriteLine("\t RefDes: " + Part.RefDesPrefix);
                 Wr.WriteLine("\t Modified: " + Part.LastModification);
                 //Wr.WriteLine("Part: " + Part.Name);
                 //foreach (IMGCPDBProperty PartsProp in Part.Properties)
                 //    {
                 //    Wr.WriteLine("\tPart Property: " + PartsProp.Name + "=" + PartsProp.get_Value());
                 //    }
                 //foreach (IMGCPDBCellReference CellRef in Part.CellReferences)
                 //    {
                 //    Wr.WriteLine("\tCell: " + CellRef.Name + " Pins: " + String.Join(", ", CellRef.PinNumbers));
                 //    }
                 //foreach (IMGCPDBSymbolReference SymRef in Part.SymbolReferences)
                 //    {
                 //    Wr.WriteLine("\tSchematic Symbol: " + SymRef.Name);
                 //    Wr.WriteLine("\tSchematic Pins: " + String.Join(", ", SymRef.PinNames));
                 //    }
                 //// Pin Mapping
                 //Wr.WriteLine("\tPin Mapping");
                 //foreach (IMGCPDBGate Gate in Part.PinMapping.Gates)
                 //    {
                 //    Wr.WriteLine("\t Gate: " + Gate.Name);
                 //    foreach (IMGCPDBSlot Slot in Gate.Slots)
                 //        {
                 //        Wr.WriteLine("\t\tSlot: " + Slot.SwapCode);
                 //        foreach (IMGCPDBPin Pin in Slot.Pins)
                 //            {
                 //            Wr.WriteLine("\t\t\t" + Pin.Name + "=" + Pin.Number);
                 //            }
                 //        }
                 //    }
               return PartIndex;