예제 #1
0
        public void genscs()
        {
            //Definitii generale
            Document      acadDoc  = Application.DocumentManager.MdiActiveDocument;
            CivilDocument civilDoc = CivilApplication.ActiveDocument;
            Database      db       = HostApplicationServices.WorkingDatabase;
            Editor        ed       = acadDoc.Editor;

            //Verificarea existentei macar a unui singur grup de sectiuni transversale
            //SectionViewGroupCollection SVGColl = civilDoc.get
            //SelectionSet SS =

            //Gasirea caii documentului curent
            string caleDocAcad = acadDoc.Database.Filename;

            //Daca fisierul este unul nou, ne salvat inca, calea apartine sablonului folosit pentru acesta.
            //Se verifica daca fisierul este unul sablon, se atentioneaza utilizatorul si se paraseste programul.
            if (caleDocAcad.EndsWith(".dwt") == true)
            {
                ed.WriteMessage("\nThe current drawing is a template file (*.dwt). Exiting program! ");
                return;
            }
            caleDocAcad = HostApplicationServices.Current.FindFile(acadDoc.Name, acadDoc.Database, FindFileHint.Default);


            //Selectarea grupului de sectiuni transversale
            ed.WriteMessage("\nCommand for generating section coordinate systems file (*.SCS) from section view groups");
            PromptEntityOptions PEO = new PromptEntityOptions("\nSelect a section view belonging to the desired section view group: ");

            PEO.SetRejectMessage("\nThe selected object is not a section view! Select object: ");
            PEO.AddAllowedClass(typeof(SectionView), true);

            PromptEntityResult PER = ed.GetEntity(PEO);

            if (PER.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nInvalid selection! Aborting.");
                return;
            }

            //Inceperea tranzactiei pentru interogarea sectiunilor transversale
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                SectionView SV = PER.ObjectId.GetObject(OpenMode.ForRead) as SectionView;     //Sectiunea selectata
                SampleLine  SL = SV.ParentEntityId.GetObject(OpenMode.ForRead) as SampleLine; //Pichetul de care apartine sectiunea

                //Gasirea grupului de sectiuni din care face parte sectiunea, folosindu-ne de numarul acesteia
                int nrSect                = int.Parse(SV.Name.Substring(SV.Name.IndexOf('(') + 1).Replace(")", ""));
                ObjectIdCollection ids    = SL.GetSectionViewIds();
                List <int>         seturi = new List <int>();
                foreach (ObjectId id in ids)
                {
                    string SVname = ((SectionView)id.GetObject(OpenMode.ForRead)).Name;
                    seturi.Add(int.Parse(SVname.Substring(SVname.IndexOf('(') + 1).Replace(")", "")));
                }
                int set = seturi.IndexOf(nrSect);


                SampleLineGroup    SLG  = SL.GroupId.GetObject(OpenMode.ForRead) as SampleLineGroup;
                ObjectIdCollection OIDS = SLG.GetSampleLineIds();

                //Obtinerea sistemelor de coordonate si scrierea lor in fisierul SCS
                string       caleSCS  = caleDocAcad.Remove(caleDocAcad.LastIndexOf('.')) + ".SCS";
                StreamWriter scriitor = new StreamWriter(caleSCS, false);
                foreach (ObjectId OID in OIDS)
                {
                    SampleLine  SLcurr = OID.GetObject(OpenMode.ForRead) as SampleLine;
                    SectionView SVcurr = SLcurr.GetSectionViewIds()[set].GetObject(OpenMode.ForRead) as SectionView;
                    double      x = -999; double y = -999;
                    SVcurr.FindXYAtOffsetAndElevation(0, 0, ref x, ref y);
                    string km = SVcurr.Name.Remove(SVcurr.Name.IndexOf('(') - 1).Replace("+", "");
                    scriitor.WriteLine(string.Format("{0},{1},{2}", km, x, y));
                }
                scriitor.Dispose();
                ed.WriteMessage("\nCoordinate System File written succesfully.");
            }
        }