addSections(this ObjectId idAlign, ObjectId idSLG, double offLeft, double offRight) { try { using (Transaction tr = BaseObjs.startTransactionDb()) { SampleLineGroup group = (SampleLineGroup)tr.GetObject(idSLG, OpenMode.ForWrite); foreach (ObjectId id in group.GetSampleLineIds()) { SampleLine SL = (SampleLine)tr.GetObject(id, OpenMode.ForRead); foreach (ObjectId idSection in SL.GetSectionIds()) { Section section = (Section)tr.GetObject(idSection, OpenMode.ForWrite); section.UpdateMode = SectionUpdateType.Dynamic; section.LeftSwathWidth = offLeft; section.RightSwathWidth = offRight; section.StyleName = section.Name; section.Layer = string.Format("{0}-SURFACE-SEC", section.Name); } } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} Sect.cs: line: 50", ex.Message)); } }
getSampleLineIDs(this ObjectId idSLG) { ObjectIdCollection ids = new ObjectIdCollection(); using (var tr = BaseObjs.startTransactionDb()){ SampleLineGroup group = (SampleLineGroup)tr.GetObject(idSLG, OpenMode.ForWrite); ids = group.GetSampleLineIds(); tr.Commit(); } return(ids); }
public void SampleLines() { Alignment algn = GetAlignment(); ObjectIdCollection slgIds = algn.GetSampleLineGroupIds(); using (Transaction ts = Dwg.TransactionManager.StartTransaction()) { try { // sample line groups foreach (ObjectId item in slgIds) { SampleLineGroup slg = ts.GetObject(item, OpenMode.ForRead) as SampleLineGroup; //sample lines ObjectIdCollection smpLinesIds = slg.GetSampleLineIds(); foreach (ObjectId smpLineId in smpLinesIds) { SampleLine sl = ts.GetObject(smpLineId, OpenMode.ForRead) as SampleLine; // her bir sampleline da örneklenmiş sectionlar döndürülür. ObjectIdCollection sectionIds = sl.GetSectionIds(); foreach (ObjectId sectionId in sectionIds) { Autodesk.Civil.DatabaseServices.Section sction = ts.GetObject(sectionId, OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Section; } } } } catch (System.Exception) { throw; } } }
public static void MillingDepthToProfileView() { CivilDocument civilDoc = CivilApplication.ActiveDocument; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; List <string> resultForFile = new List <string>(); using (Transaction ts = Application.DocumentManager.MdiActiveDocument. Database.TransactionManager.StartTransaction()) { // dterminate location of section view profiles // ask user to select Alignment PromptEntityOptions opt = new PromptEntityOptions("\nSelect an Alignment"); opt.SetRejectMessage("\nObject must be an alignment.\n"); opt.AddAllowedClass(typeof(Alignment), false); ObjectId alignID = ed.GetEntity(opt).ObjectId; try { Alignment myAlignment = ts.GetObject(alignID, OpenMode.ForRead) as Alignment; ObjectIdCollection sampleLineIdCollection = myAlignment.GetSampleLineGroupIds(); SampleLineGroup sampleLineGroup = sampleLineIdCollection[0].GetObject(OpenMode.ForRead) as SampleLineGroup; //if you have problem chech here foreach (ObjectId sampleLineId in sampleLineGroup.GetSampleLineIds()) { SampleLine sampleLine = ts.GetObject(sampleLineId, OpenMode.ForRead) as SampleLine; foreach (ObjectId sectionId in sampleLine.GetSectionIds()) { Section section = ts.GetObject(sectionId, OpenMode.ForWrite) as Section; ed.WriteMessage("Section {0} elevation max: {1} min: {2}\n", section.Name, section.MaximumElevation, section.MinmumElevation); // set the section update mode: //section.UpdateMode = SectionUpdateType.Dynamic; } } SectionViewGroupCollection sectionViewGrouopColection = sampleLineGroup.SectionViewGroups; int sectionViewNumber = 0; try { string askString = String.Format("\nEnter number of ACTIVE SectionViewGroup (1-{0}): ", sectionViewGrouopColection.Count); sectionViewNumber = Convert.ToInt32(GetStringFromUser(ed, askString)); if (sectionViewNumber < 1 || sectionViewNumber > sectionViewGrouopColection.Count) { throw new ArgumentOutOfRangeException("Value is out of range!"); } } catch (System.Exception) { ed.WriteMessage("Please enter valid value!"); return; } SectionViewGroup theSectionViewGroup = sectionViewGrouopColection[sectionViewNumber - 1]; ObjectIdCollection sectionViewIdColection = theSectionViewGroup.GetSectionViewIds(); // create milling Elements MillingDataEngine.DataStruct.RoadSection theRoadSection = MillingDataEngine.Func.ExcelDataRead.RoadSectionElementsBuilder(MillingDataEngine.Func.ExcelDataRead.ReadData()); foreach (ObjectId sectionViewId in sectionViewIdColection) { SectionView theSectionView = ts.GetObject(sectionViewId, OpenMode.ForWrite) as SectionView; theSectionView.IsElevationRangeAutomatic = false; string minRangeElevation = theSectionView.ElevationMin.ToString(); theSectionView.IsElevationRangeAutomatic = true; MillingDataEngine.DataStruct.ThreeDPoint theLocation = new MillingDataEngine.DataStruct.ThreeDPoint(theSectionView.Location.X, theSectionView.Location.Y, Convert.ToInt32(theSectionView.Location.Z)); double baseElevation = Convert.ToDouble(minRangeElevation); double station = MillingDataEngine.Func.SectionViews.ConvertNameToStationLocation(theSectionView.Name); double range = 0.5; //+- range of stations // search maching of cross section in drowing ana xls tanble MillingDataEngine.DataStruct.Cross_section tempCross = theRoadSection.CrossSections.Find((x) => ((x.Station >= station - range && x.Station <= station) || (x.Station <= station + range && x.Station >= station))); if (tempCross != null && tempCross.MillingElements.Count > 0) //if there is milling elements go next { MillingDataEngine.DataStruct.Cross_section_for_sectionView tempCrossForCV = new MillingDataEngine.DataStruct.Cross_section_for_sectionView(tempCross, theLocation, baseElevation); theRoadSection.AddCrossSectionview(tempCrossForCV); } } DrowToSectionViews(theRoadSection); } catch (System.Exception e) { //throw new System.Exception(e.Message); ed.WriteMessage(e.Message); //return; } // Save the changes and dispose of the transaction ts.Commit(); } ed.WriteMessage("\nOK!"); }
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."); } }