private void ExportPoints_Load(object sender, EventArgs e) { Autodesk.AutoCAD.ApplicationServices.Document AcadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; CivilDocument CivilDoc = CivilApplication.ActiveDocument; Database db = AcadDoc.Database; Editor ed = AcadDoc.Editor; ObjectIdCollection alignmentIds = CivilDoc.GetAlignmentIds(); //lista ID aliniamente ObjectIdCollection pointIds = CivilDoc.GetAllPointIds(); //lista ID puncte using (Transaction trans = AcadDoc.TransactionManager.StartTransaction()) { //Popularea listei de aliniamente double length = 0; string LongestAlignName = string.Empty; foreach (ObjectId alinId in alignmentIds) { Alignment alin = (Alignment)trans.GetObject(alinId, OpenMode.ForRead); this.cmbBoxAlignment.Items.Add(alin.Name); alinIdTable.Add(alin.Name, alinId); if (alin.Length > length) { LongestAlignName = alin.Name; length = alin.Length; } } this.cmbBoxAlignment.Text = LongestAlignName; //Obtinerea listei cu toate punctele din desen foreach (ObjectId pointId in pointIds) { CogoPoint point = (CogoPoint)trans.GetObject(pointId, OpenMode.ForRead); Ovidiu.StringUtil.Punct3D punct = new StringUtil.Punct3D(); Alignment alin = (Alignment)trans.GetObject((ObjectId)alinIdTable[cmbBoxAlignment.Text], OpenMode.ForRead); punct.Nr = (int)point.PointNumber; punct.X = point.Location.X; punct.Y = point.Location.Y; punct.Z = point.Location.Z; punct.D = point.RawDescription; double kmPunct = 0; double offsetPunct = 0; try { alin.StationOffset(punct.X, punct.Y, ref kmPunct, ref offsetPunct); } catch { kmPunct = -999; offsetPunct = -999; } punct.KM = kmPunct; punct.Offset = offsetPunct; listaPuncte.Add(punct); } //listaScurta = listaPuncte; //Popularea tabelului de previzualizare fillTable(listaPuncte); ed.WriteMessage(listaPuncte.Count.ToString()); trans.Commit(); } }
private void btnOk_Click(object sender, EventArgs e) { //Exportarea listei finale de puncte Ovidiu.StringUtil.String3D lista = new StringUtil.String3D(); try { foreach (DataGridViewRow rand in dataGridView1.Rows) { if ((bool)rand.Cells["Include"].Value) { Ovidiu.StringUtil.Punct3D punct = new StringUtil.Punct3D(); if (rand.Cells["Point Nr."].Value != null) { punct.Nr = Convert.ToInt32(rand.Cells["Point Nr."].Value); } if (rand.Cells["Chainage"].Value != null) { punct.KM = Math.Round(Convert.ToDouble(rand.Cells["Chainage"].Value), 3); } if (rand.Cells["Offset"].Value != null) { punct.Offset = Convert.ToDouble(rand.Cells["Offset"].Value); } if (rand.Cells["Easting"].Value != null) { punct.X = Convert.ToDouble(rand.Cells["Easting"].Value); } if (rand.Cells["Northing"].Value != null) { punct.Y = Convert.ToDouble(rand.Cells["Northing"].Value); } if (rand.Cells["Elevation"].Value != null) { punct.Z = Convert.ToDouble(rand.Cells["Elevation"].Value); } if (rand.Cells["Description"].Value != null) { punct.D = rand.Cells["Description"].Value.ToString(); } lista.Add(punct); } } //Confirmare suplimentara de suprascriere a fisierului indicat (special pentru fisierul implicit) //if (System.IO.File.Exists(txtBoxFile.Text) && // System.IO.File. // MessageBox.Show("File exists, overwrite?", "Overwrite confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) // == System.Windows.Forms.DialogResult.No) //{ // return; //} if (lista.ExportPoints(txtBoxFile.Text, StringUtil.Punct3D.Format.NrKmOENZD, StringUtil.Punct3D.DelimitedBy.Comma, 3, false) == false) { MessageBox.Show("File already open in another application! File export unsuccessful.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } this.Close(); } catch (SystemException error) { MessageBox.Show("Unsuccessful point export!\n" + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }