Ejemplo n.º 1
0
    private void CountPinsOfSymbol()
    {
        SCH.TObjectSet DontCountObject = new SCH.TObjectSet(SCH.TObjectId.eParameter, SCH.TObjectId.eDesignator);

        OpenFileDialog openDialog = InitFileOpenDialog("SCHLIB");

        if (openDialog == null)
        {
            return;
        }
        IClient client = DXP.GlobalVars.Client;

        string[] SymbolFiles = openDialog.FileNames;
        foreach (string SymbolFile in SymbolFiles)
        {
            //IServerDocument SymbolDocument = OpenDocuemnt(SymbolFile, "SCHLIB");
            IServerDocument      SymbolDocument = client.OpenDocumentShowOrHide("SCHLIB", SymbolFile, false);
            ISch_ServerInterface SchServer      = SCH.GlobalVars.SchServer;
            ISch_Lib             SchLib         = SchServer.GetSchDocumentByPath(SymbolFile) as ISch_Lib;
            //ISch_Lib SchLib = SchServer.GetCurrentSchDocument() as ISch_Lib;

            ISch_Iterator LibItera = SchLib.SchLibIterator_Create();
            LibItera.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eSchComponent));
            ISch_Component LibComp = LibItera.FirstSchObject() as ISch_Component;

            while (LibComp != null)
            {
                string SymbolName = LibComp.GetState_SymbolReference();

                ISch_Iterator       ObjIterator = LibComp.SchIterator_Create();
                ISch_BasicContainer SchObj      = ObjIterator.FirstSchObject();

                int PinCount       = 0;
                int PrimitiveCount = 0;

                while (SchObj != null)
                {
                    bool CountIt = true;

                    foreach (SCH.TObjectId ObjectKind in DontCountObject)
                    {
                        if (ObjectKind == SchObj.GetState_ObjectId())
                        {
                            CountIt = false;
                        }
                    }

                    if (SchObj.GetState_ObjectId() == SCH.TObjectId.ePin)
                    {
                        PinCount++;
                    }

                    if (CountIt)
                    {
                        PrimitiveCount++;
                    }

                    SchObj = ObjIterator.NextSchObject();
                }

                LibComp.SchIterator_Destroy(ref ObjIterator);

                System.IO.File.AppendAllText(@"G:\report.txt", SymbolName + "|" + PinCount.ToString() + "|" + PrimitiveCount.ToString() + "\r\n");

                LibComp = LibItera.NextSchObject() as ISch_Component;
            }

            SchLib.SchIterator_Destroy(ref LibItera);

            CloseDocument(SymbolDocument);
        }
    }