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)); } }
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!"); }
[CommandMethod("ES")] //Comanda care exporta un set de sectiuni in format KmOZD txt public void ExportSections() { CivilDocument civDoc = CivilApplication.ActiveDocument; Document acadDoc = Application.DocumentManager.MdiActiveDocument; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Database db = HostApplicationServices.WorkingDatabase; string caleDocAcad = HostApplicationServices.Current.FindFile(acadDoc.Name, db, FindFileHint.Default); //Optiuni pentru selectia unei sectiuni PromptEntityOptions PrEntOpt = new PromptEntityOptions("\nSelect a section from the desired set to be exported: "); PrEntOpt.SetRejectMessage("\nThe selected object is not a Section object! "); PrEntOpt.AddAllowedClass(typeof(CivilDBS.Section), true); //Selectia unei sectiuni din setul ce trebuie exportat PromptEntityResult PrEntRes = ed.GetEntity(PrEntOpt); if (PrEntRes.Status == PromptStatus.OK) { ObjectId SSID = PrEntRes.ObjectId; using (Transaction trans = db.TransactionManager.StartTransaction()) { //Obtinerea sectiunii din baza de date, aflarea sursei acesteia si a grupului de sectiuni din care face parte CivilDBS.Section SS = (CivilDBS.Section)trans.GetObject(SSID, OpenMode.ForRead); int SSstart = SS.Name.LastIndexOf("- ") + 2; int SSend = SS.Name.LastIndexOf('('); string SSsource = SS.Name.Substring(SSstart, SSend - SSstart); ed.WriteMessage("\nSelected sections's source is: {0}", SSsource); CivilDBS.SampleLine SL = (CivilDBS.SampleLine)trans.GetObject(SS.SampleLineId, OpenMode.ForRead); CivilDBS.SampleLineGroup SLG = (CivilDBS.SampleLineGroup)trans.GetObject(SL.GroupId, OpenMode.ForRead); //Aflarea aliniamentului de care apartine grupul de sectiuni string numeAx = String.Empty; ObjectIdCollection ALIDS = civDoc.GetAlignmentIds(); try { foreach (ObjectId ALID in ALIDS) { Alignment AL = (Alignment)trans.GetObject(ALID, OpenMode.ForRead); if (AL.GetSampleLineGroupIds().Contains(SL.GroupId)) { numeAx = AL.Name; } } } catch { } string caleFisSect = caleDocAcad.Remove(caleDocAcad.LastIndexOf('.')) + " - " + numeAx + " - " + SSsource + ".txt"; StreamWriter scriitor = new StreamWriter(caleFisSect); //Exportarea datelor ObjectIdCollection SLIDS = SLG.GetSampleLineIds(); foreach (ObjectId SLID in SLIDS) { CivilDBS.SampleLine currSL = (CivilDBS.SampleLine)trans.GetObject(SLID, OpenMode.ForRead); ObjectIdCollection SIDS = currSL.GetSectionIds(); foreach (ObjectId SID in SIDS) { CivilDBS.Section S = (CivilDBS.Section)trans.GetObject(SID, OpenMode.ForRead); int Sstart = S.Name.LastIndexOf("- ") + 2; int Send = S.Name.LastIndexOf('('); string Ssource = S.Name.Substring(Sstart, Send - Sstart); if (SSsource == Ssource) { CivilDBS.SectionPointCollection Spoints = S.SectionPoints; double LO = -999; double RO = 999; try { LO = S.LeftOffset; RO = S.RightOffset; } catch { ed.WriteMessage("\nLimits of section at chainage: {0} cound not be read! Section skipped.", S.Station); continue; } for (int i = 0; i < Spoints.Count; i++) { //if (Spoints[i].Location.X >= S.LeftOffset && Spoints[i].Location.X <= S.RightOffset) if (Spoints[i].Location.X >= LO && Spoints[i].Location.X <= RO) { string sectiune = S.Station.ToString() + "," + Spoints[i].Location.X.ToString("F4") + "," + Spoints[i].Location.Y.ToString("F4") + "," + Ssource; scriitor.WriteLine(sectiune); } } //Polyline poly = (Polyline)S.BaseCurve; //for (int i = 0; i < poly.NumberOfVertices; i++) //{ // Point3d p = poly.GetPoint3dAt(i); // string sectiune = S.Station.ToString() + "," + // p.X.ToString("F3") + "," + // p.Y.ToString("F3") + "," + Ssource; // scriitor.WriteLine(sectiune); //} } } } scriitor.Dispose(); } } }