public MicrostationExport(CopyToClipboard cpc, BackgroundWorker ExportWorker, string filename) { string exportPath = FunctionUse.GetExportPath(filename); List <SveraClass.FromDataBaseWide> rowgrid = SveraCl.PereformSpec(cpc, TypeOfExport.Microstation); int maxofprog = rowgrid.Count + 2 * 5; maxofprog += rowgrid.Count; int counter = 0; ExportWorker.ReportProgress(maxofprog, Operation.init); try { exportPath += "\\"; exportPath += (filename != null && filename != "") ? Path.GetFileNameWithoutExtension(filename) + "Spec" : "specification"; exportPath += ".dgn"; File.WriteAllBytes(exportPath, MicroSvera.Properties.Resources.seed2d); } catch (Exception ex) { MessageBox.Show("Файл открыт и используется. Закройте файл и повторите попытку", "Svera Export Microstation", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } counter += 2; ExportWorker.ReportProgress(counter, Operation.change); if (ExportWorker.CancellationPending) { return; } MS = null; MSex = null; try { try { MSex = new MicroStationDGN.ApplicationObjectConnector(); MS = MSex.Application; } catch (Exception ex) { MessageBox.Show("Невозможно запустить Microstation. Проверьте версию программы. Необходим Select Series 2", "Svera Export Microstation", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message); return; } counter += 2; ExportWorker.ReportProgress(counter, Operation.change); if (ExportWorker.CancellationPending) { MS.Quit(); return; } currentDoc = MS.OpenDesignFile(exportPath); currentset = MS.ActiveSettings; currentset.TextStyle.Height = visfont; currentset.TextStyle.Width = shirfont; currentset.TextStyle.Font = currentDoc.Fonts["txt"]; currentset.TextStyle.NodeLineSpacing = mezhstroch; currentset.Color = mainCOlor; counter += 2; ExportWorker.ReportProgress(counter, Operation.change); if (ExportWorker.CancellationPending) { MS.Quit(); return; } GetShapka(); counter += 2; ExportWorker.ReportProgress(counter, Operation.change); if (ExportWorker.CancellationPending) { MS.Quit(); return; } double lowPOint = pos.Range.Low.Y; for (int i = 0; i <= rowgrid.Count - 1; i++) { counter += 1; ExportWorker.ReportProgress(counter, Operation.change); if (ExportWorker.CancellationPending) { MS.Quit(); return; } // if (rowgrid[i].KolicByDetalize > 0) // { MicroStationDGN.ShapeElement posElem = null; MicroStationDGN.ShapeElement oboznElem = null; MicroStationDGN.ShapeElement naimElem = null; MicroStationDGN.ShapeElement kolElem = null; MicroStationDGN.ShapeElement massaElem = null; MicroStationDGN.ShapeElement primElem = null; MicroStationDGN.TextNodeElement posElemText = null; MicroStationDGN.TextNodeElement oboznElemText = null; MicroStationDGN.TextNodeElement naimElemText = null; MicroStationDGN.TextNodeElement kolElemText = null; MicroStationDGN.TextNodeElement massaElemText = null; MicroStationDGN.TextNodeElement primElemText = null; REcANdTExt(ref posElem, ref posElemText, new PointF((float)pos.Range.Low.X, (float)lowPOint), new SizeF((float)(pos.Range.High.X - pos.Range.Low.X), -4F), ((rowgrid[i].PosicToExp > 0) ? (rowgrid[i].PosicToExp).ToString() : "").ToString(), false, false, true, 1, true); REcANdTExt(ref oboznElem, ref oboznElemText, new PointF((float)(obozn.Range.Low.X), (float)lowPOint), new SizeF((float)(obozn.Range.High.X - obozn.Range.Low.X), (float)(posElem.Range.Low.Y - posElem.Range.High.Y)), rowgrid[i].Markirov, false, false, true, 1, true); REcANdTExt(ref naimElem, ref naimElemText, new PointF((float)(naim.Range.Low.X), (float)lowPOint), new SizeF((float)(naim.Range.High.X - naim.Range.Low.X), (float)(oboznElem.Range.Low.Y - oboznElem.Range.High.Y)), rowgrid[i].GetNaim(false), false, false, true, 3, true); REcANdTExt(ref kolElem, ref kolElemText, new PointF((float)(kol.Range.Low.X), (float)lowPOint), new SizeF((float)(kol.Range.High.X - kol.Range.Low.X), (float)(naimElem.Range.Low.Y - naimElem.Range.High.Y)), ((rowgrid[i].KolicByDetalizeR != 0) ? (rowgrid[i].KolicByDetalizeR).ToString() : "").ToString(), false, false, true, 1, true); REcANdTExt(ref massaElem, ref massaElemText, new PointF((float)(massa.Range.Low.X), (float)lowPOint), new SizeF((float)(massa.Range.High.X - massa.Range.Low.X), (float)(kolElem.Range.Low.Y - kolElem.Range.High.Y)), rowgrid[i].MassaStr, false, false, true, 1, true); REcANdTExt(ref primElem, ref primElemText, new PointF((float)(prim.Range.Low.X), (float)lowPOint), new SizeF((float)(prim.Range.High.X - prim.Range.Low.X), (float)(massaElem.Range.Low.Y - massaElem.Range.High.Y)), rowgrid[i].PrimMicro, false, false, true, 1, true); List <MicroStationDGN.ShapeElement> elStolb = new List <MicroStationDGN.ShapeElement> { posElem, oboznElem, naimElem, kolElem, massaElem, primElem }; List <MicroStationDGN.TextNodeElement> elStolbText = new List <MicroStationDGN.TextNodeElement> { posElemText, oboznElemText, naimElemText, kolElemText, massaElemText, primElemText }; lowPOint = elStolb.Min <MicroStationDGN.ShapeElement, double>(el => el.Range.Low.Y); for (int j = 0; j < elStolb.Count; j++) { if (lowPOint < elStolb[j].Range.Low.Y) { elStolb[j].ModifyVertex(2, MS.Point3dFromXY(elStolb[j].get_Vertex(3).X, lowPOint)); elStolb[j].ModifyVertex(3, MS.Point3dFromXY(elStolb[j].get_Vertex(4).X, lowPOint)); elStolb[j].Rewrite(); elStolb[j].Redraw(); int position = 0; if (elStolbText[j] != null) { if (elStolbText[j].Justification == MicroStationDGN.MsdTextJustification.msdTextJustificationCenterCenter) { position = 1; } else if (elStolbText[j].Justification == MicroStationDGN.MsdTextJustification.msdTextJustificationLeftTop) { position = 3; } MicroStationDGN.Point3d POintIns = POintIns = GetPOintText(position, new PointF((float)elStolb[j].Range.Low.X, (float)elStolb[j].Range.High.Y), new SizeF((float)(elStolb[j].Range.High.X - elStolb[j].Range.Low.X), (float)(elStolb[j].Range.High.Y - elStolb[j].Range.Low.Y))); elStolbText[j].Move(MS.Point3dFromXY(POintIns.X - elStolbText[j].Origin.X, POintIns.Y - elStolbText[j].Origin.Y)); elStolbText[j].Rewrite(); elStolbText[j].Redraw(); } } } // } } currentDoc.Save(); int statusSaveCHanges = (int)MS.GetCExpressionValue("userPrefsP->extFlags.immediatelySaveChanges"); int statusDesignOnExit = (int)MS.GetCExpressionValue("userPrefsP->extFlags.fileDesignOnExit"); MS.SetCExpressionValue("userPrefsP->extFlags.immediatelySaveChanges", 1); MS.SetCExpressionValue("userPrefsP->extFlags.fileDesignOnExit", 0); currentDoc.Close(); MS.SetCExpressionValue("userPrefsP->extFlags.immediatelySaveChanges", statusSaveCHanges); MS.SetCExpressionValue("userPrefsP->extFlags.fileDesignOnExit", statusDesignOnExit); MS.Visible = true; currentDoc = MS.OpenDesignFile(exportPath); currentDoc.Views[1].DisplaysFill = true; try { currentDoc.Views[1].Fit(false); } catch (Exception ex) { MessageBox.Show(ex.Message, "Svera Export Microstation", MessageBoxButtons.OK, MessageBoxIcon.Error); } currentDoc.Views[1].Redraw(); counter += 2; ExportWorker.ReportProgress(counter, Operation.change); if (ExportWorker.CancellationPending) { MS.Quit(); return; } } catch (Exception ex) { if (MS != null) { MS.Quit(); MS = null; } if (MSex != null) { MSex = null; } //MessageBox.Show(ex.Message); //MessageBox.Show(ex.StackTrace); //if (ex.InnerException != null) //{ // MessageBox.Show(ex.InnerException.ToString()); //} throw new Exception("MicrostationExport", ex); } }
private void REcANdTExt(ref MicroStationDGN.ShapeElement ScemRam, ref MicroStationDGN.TextNodeElement ScemText, PointF leftTop, SizeF Sizo, string stro, bool Povorot, bool NulToTir, bool needOfRam, int Position, bool RashirRam) { int chet = 0; povtor: try { double[] points = new double[10]; points[0] = leftTop.X; points[1] = leftTop.Y; points[2] = leftTop.X + Sizo.Width; points[3] = leftTop.Y; points[4] = leftTop.X + Sizo.Width; points[5] = leftTop.Y + Sizo.Height; points[6] = leftTop.X; points[7] = leftTop.Y + Sizo.Height; points[8] = leftTop.X; points[9] = leftTop.Y; if (MS != null) { if (stro != null && stro != "") { OnlyTExt(ref ScemText, new PointF((float)points[0], (float)points[3]), new SizeF((float)(points[2] - points[0]), (float)(points[5] - points[3])), stro, Povorot, Position); if (RashirRam == true && stro != null && stro != "" && ScemText != null) { if (ScemText.TextLinesCount > 1) { points[5] = ScemText.Range.Low.Y; points[7] = points[5]; } } } if (needOfRam == true) { MicroStationDGN.Point3d[] pointos = new MicroStationDGN.Point3d[4]; pointos[0] = MS.Point3dFromXY(points[0], points[1]); pointos[1] = MS.Point3dFromXY(points[2], points[3]); pointos[2] = MS.Point3dFromXY(points[4], points[5]); pointos[3] = MS.Point3dFromXY(points[6], points[7]); //if needOfHatch = True Then // ScemRam = ms.CreateShapeElement1(Nothing, pointos, MicroStationDGN.MsdFillMode.msdFillModeFilled) //Else ScemRam = MS.CreateShapeElement1(null, pointos); //End If currentDoc.Models[1].AddElement(ScemRam as MicroStationDGN._Element); //If needOfRazriv = True Then // Try // ScemRam.LineStyle = ModExport.currentDoc.LineStyles("3") // Catch ex As Exception // End Try //Else try { ScemRam.LineStyle = currentDoc.LineStyles["0"]; } finally { } // End If ScemRam.Rewrite(); } //If Not str Is Nothing Then // If str(0) <> "" Then // End If //End If } } catch (Exception ex) { if (chet < 2) { chet += 1; try { if (ScemRam != null) { MS.ActiveModelReference.RemoveElement(ScemRam as MicroStationDGN._Element); } } finally { } try { if (ScemText != null) { MS.ActiveModelReference.RemoveElement(ScemText as MicroStationDGN._Element); } } finally { } System.Threading.Thread.Sleep(500); goto povtor; } else { throw new Exception("REcANdTExt", ex); // MessageBox.Show(ex.Message); } } }