public DxfModel Read() { string extension = Path.GetExtension(this.string_0); if (string.Compare(extension, ".dwg", StringComparison.InvariantCultureIgnoreCase) == 0) { using (DwgReader dwgReader = new DwgReader(this.string_0) { LoadUnknownObjects = this.bool_0 }) return(dwgReader.Read()); } else if (string.Compare(extension, ".dxf", StringComparison.InvariantCultureIgnoreCase) == 0) { using (DxfReader dxfReader = new DxfReader(this.string_0) { LoadUnknownObjects = this.bool_0 }) return(dxfReader.Read()); } else { if (string.Compare(extension, ".zip", StringComparison.InvariantCultureIgnoreCase) != 0 && string.Compare(extension, ".gz", StringComparison.InvariantCultureIgnoreCase) != 0 && string.Compare(extension, ".bz2", StringComparison.InvariantCultureIgnoreCase) != 0) { throw new ArgumentException("Unknown extension " + extension + ", it must be either .dxf or .dwg."); } using (DxfReader dxfReader = new DxfReader(this.string_0) { LoadUnknownObjects = this.bool_0 }) return(dxfReader.Read()); } }
//控制平台Form装载函数 private void MotionControlPlatform_Load(object sender, EventArgs e) { //串口参数初始化 Usart.BaudRate = 115200; Usart.DataBits = 8; Usart.StopBits = System.IO.Ports.StopBits.One; Usart.Parity = System.IO.Ports.Parity.None; Usart.ReadBufferSize = 4096; KeyPointNumLabel.Text = ""; NoticeInformation.Text = ""; //初始化背景 string filename = Directory.GetCurrentDirectory() + "\\blank.dwg"; DxfModel model; string extension = Path.GetExtension(filename); if (string.Compare(extension, ".dwg", true) == 0) { model = DwgReader.Read(filename); } else { model = DxfReader.Read(filename); } viewControl.Model = model; }
public static void Touch(ObjectId[] polylineIds) { var database = polylineIds[0].Database; using (var tr = database.TransactionManager.StartTransaction()) { foreach (var polylineId in polylineIds) { var curve = tr.GetObject(polylineId, OpenMode.ForRead) as Curve; // 读取CAD图元 var reader = new DwgReader(); var lineString = reader.ReadGeometry(curve, tr) as LineString; //lineString.Touches() // 做出缓冲区 var geometry = LineStringSelfIntersectionsOp(lineString); if (geometry.GeometryType == "Point") { var writer = new DwgWriter(); DBPoint dbPt = writer.WriteDbPoint(geometry as Point); CadUtils.DrawPoint(tr, database, dbPt); } } tr.Commit(); } }
public static Interface30 Create( DxfVersion version, DwgReader dwgReader, Stream stream, bool enableLogging) { if (version >= DxfVersion.Dxf13 && version < DxfVersion.Dxf15) { return((Interface30) new Class445(dwgReader, stream)); } if (version < DxfVersion.Dxf18) { return((Interface30) new Class446(dwgReader, stream)); } if (version < DxfVersion.Dxf21) { return((Interface30) new Class447(dwgReader, stream)); } if (version < DxfVersion.Dxf24) { return((Interface30) new Class448(dwgReader, stream)); } if (version >= DxfVersion.Dxf24 && version <= DxfVersion.Dxf27) { return((Interface30) new Class449(dwgReader, stream)); } throw new DxfException("Version " + version.ToString() + " not supported."); }
public static void CreateBuffer(ObjectId polylineId, double bufferDist) { var database = polylineId.Database; using (var tr = database.TransactionManager.StartTransaction()) { var curve = tr.GetObject(polylineId, OpenMode.ForRead) as Curve; // 读取CAD图元 var reader = new DwgReader(); var lineString = reader.ReadGeometry(curve, tr) as LineString; // 做出缓冲区 var buffer = lineString.Buffer(bufferDist) as Geometry; if (buffer.GeometryType == "Polygon") { var writer = new DwgWriter(); Polyline[] polylines = writer.WritePolyline(buffer as IPolygon); // 输出到CAD foreach (var polyline in polylines) { CadUtils.AddToCurrentDb(tr, database, polyline); } } tr.Commit(); } }
static TopoData BuildTopology() { var polylineIds = CadUtils.FindAllPolylines(Application.DocumentManager.MdiActiveDocument); var datebase = Application.DocumentManager.MdiActiveDocument.Database; using (var tr = datebase.TransactionManager.StartTransaction()) { // 读入多边形数据 var reader = new DwgReader(); var polygons = new Dictionary <ObjectId, IPolygon>(); var quadtree = new Quadtree <IGeometry>(); // 构建拓扑 foreach (ObjectId polylineId in polylineIds) { var polygon = reader.ReadEntityAsPolygon(tr, polylineId) as IPolygon; if (polygon != null) { polygons.Add(polylineId, polygon); quadtree.Insert(polygon.EnvelopeInternal, polygon); } } tr.Commit(); return(new TopoData() { Polygons = polygons, Quadtree = quadtree, Reader = reader, }); } }
private async void openAutoCadFileMenuItem_Click(object sender, RoutedEventArgs e) { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.List; openPicker.SuggestedStartLocation = PickerLocationId.ComputerFolder; openPicker.FileTypeFilter.Add(".dwg"); openPicker.FileTypeFilter.Add(".dxf"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { Stream inStream = await file.OpenStreamForReadAsync(); model = DwgReader.Read(inStream); var graphicsConfig = GraphicsConfig.AcadLikeWithBlackBackground; cadGraphics = new NetCoreGraphics3D(graphicsConfig, ImageRenderOptions.Default.GraphicsOptions); cadGraphics.CreateDrawables(model); bounds = new Bounds3D(); cadGraphics.BoundingBox(bounds); resizeEventDelayer.StopStart(); } }
public void openFile(string filename) { modelTransform = Matrix4D.Identity; from2DTransform = gdiGraphics3D.To2DTransform.GetInverse(); translation = Vector3D.Zero; mouseDown = false; shiftPressed = false; lastMouseLocation.X = (int)0.5d * ClientSize.Width; lastMouseLocation.Y = (int)0.5d * ClientSize.Height; mouseClickLocation = lastMouseLocation; scaleFactor = 1d; if (filename == "" || filename == null) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "AutoCad files (*.dwg, *.dxf)|*.dxf;*.dwg"; if (dialog.ShowDialog() == DialogResult.OK) { filename = dialog.FileName; } } if (!string.IsNullOrEmpty(filename)) { // To prevent flicker. SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.UserPaint, true); ImageControl.BackColor = System.Drawing.Color.Black; try { string extension = Path.GetExtension(filename); if (string.Compare(extension, ".dwg", true) == 0) { model = DwgReader.Read(filename); } else { model = DxfReader.Read(filename); } this.Text = filename; gdiGraphics3D.CreateDrawables(model); bounds = new Bounds3D(); gdiGraphics3D.BoundingBox(bounds, modelTransform); CalculateTo2DTransform(); ImageControl.Invalidate(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private static TopologyData BuildTopology(ObjectId[] objectIds) { var topoData = new TopologyData(); var database = objectIds[0].Database; using (var tr = database.TransactionManager.StartTransaction()) { var reader = new DwgReader(); foreach (ObjectId objectId in objectIds) { // 如果没有 var curve = tr.GetObject(objectId, OpenMode.ForRead) as Curve; if (curve == null || !curve.Visible) { continue; } // 图层关闭,继续,因为有可能是图幅层 var layer = (LayerTableRecord)tr.GetObject(curve.LayerId, OpenMode.ForRead); if (layer.IsOff) { continue; } // 目前只处理封闭的和大于3的多边形 // http://192.168.0.6:8080/browse/LCLIBCAD-903 // 否则会弹出points must form a closed linestring异常 if (curve.Closed && reader.NumberOfVerticesMoreThan3(curve)) { var geom = reader.ReadCurveAsPolygon(tr, curve) as IGeometry; geom = geom.Buffer(0); if (!geom.IsValid) { topoData.InvalidObjects.Add(objectId); System.Diagnostics.Trace.WriteLine(geom.ToString()); } // 没有包围盒,无法进入空间索引 else if (geom.EnvelopeInternal.IsNull) { topoData.WrongEnvelopeObjects.Add(objectId); } else { //geom = SimpleGeometryPrecisionReducer.Reduce(geom, pmFixed3); geom.UserData = objectId; topoData.Quadtree.Insert(geom.EnvelopeInternal, geom); topoData.Geometries.Add(geom); topoData.GeometryDictionary[objectId] = geom; } } } tr.Commit(); } return(topoData); }
public Class887(DwgReader dwgReader, Interface30 bitStream, Class374 builder) { this.dwgReader_0 = dwgReader; this.interface30_0 = bitStream; this.interface30_1 = bitStream; this.interface30_2 = bitStream; this.interface30_3 = bitStream; this.class374_0 = builder; }
static IEnumerable <Insert> getInsertEntities(string file, string blockname) { CadDocument doc = DwgReader.Read(file); // Get the model space where all the drawing entities are BlockRecord modelSpace = doc.BlockRecords["*Model_Space"]; // Get the insert instance that is using the block that you are looking for return(modelSpace.Entities.OfType <Insert>().Where(e => e.Block.Name == blockname)); }
public static Dictionary <ObjectId, IList <Point3d> > FindDanglingLine(IList <ObjectId> objectIds) { var dictionary = new Dictionary <ObjectId, IList <Point3d> >(); //var points = new List<Point3d>(); var database = objectIds[0].Database; using (var tr = database.TransactionManager.StartTransaction()) { var reader = new DwgReader(); // var pmFixed3 = new PrecisionModel(3); // 读入多边形数据 foreach (ObjectId objectId in objectIds) { if (!objectId.IsValid) { continue; } IGeometry geom = reader.ReadEntityAsGeometry(tr, objectId); if (geom == null) { continue; } // 开始做Union var nodedLineString = UnaryUnionOp.Union(geom); var polygonizer = new Polygonizer(); polygonizer.Add(nodedLineString); var polygons = polygonizer.GetPolygons(); // 悬挂线 var points = new List <Point3d>(); foreach (ILineString lineString in polygons) { foreach (var coordinate in lineString.Coordinates) { // 如果是NaN直接设定为0 if (double.IsNaN(coordinate.Z)) { coordinate.Z = 0; } points.Add(new Point3d(coordinate.X, coordinate.Y, coordinate.Z)); } } if (points.Any()) { dictionary.Add(objectId, points); } } tr.Commit(); } return(dictionary); }
public static Point3d?GetCentroid(Entity entity, Transaction tr) { Point3d?result = null; var reader = new DwgReader(); var geomerty = reader.ReadGeometry(entity, tr); var coords = NetTopologySuite.Algorithm.Centroid.GetCentroid(geomerty); if (coords != null) { result = new Point3d(coords.X, coords.Y, coords.Z); } return(result); }
public static void FindTouchedEdge(ObjectId[] polylineIds) { if (polylineIds.Length != 2) { return; } //var ids = CadUtils.FindAllPolylines(Application.DocumentManager.MdiActiveDocument); var database = Application.DocumentManager.MdiActiveDocument.Database; using (var tr = database.TransactionManager.StartTransaction()) { var reader = new DwgReader(); var entity1 = tr.GetObject(polylineIds[0], OpenMode.ForRead) as Curve; var lineString1 = reader.ReadCurveAsLineString(tr, entity1); lineString1.UserData = polylineIds[0]; var entity2 = tr.GetObject(polylineIds[1], OpenMode.ForRead) as Curve; var lineString2 = reader.ReadCurveAsLineString(tr, entity2); lineString2.UserData = polylineIds[1]; var isTouch = lineString1.Touches(lineString2); System.Diagnostics.Trace.WriteLine(isTouch); IGeometry intersections = lineString1.Intersection(lineString2); //IGeometry intersections = CommonUtils.GetIntersectionPoints(lineString, polygon1); if (intersections.Coordinates.Any()) { foreach (var Coordinate in intersections.Coordinates) { var dbpoint = new DBPoint(new Point3d(Coordinate.X, Coordinate.Y, 0)); CadUtils.DrawPoint(tr, database, dbpoint); } // Draw all var d = new DBPoint(new Point3d(intersections.Coordinates[0].X, intersections.Coordinates[0].Y, 0)); CadUtils.DrawPoint(tr, database, d, 2); var lastIndex = intersections.Coordinates[intersections.Coordinates.Length - 1]; var d1 = new DBPoint(new Point3d(lastIndex.X, lastIndex.Y, 0)); CadUtils.DrawPoint(tr, database, d1, 2); } tr.Commit(); } }
//public static IList<ObjectId> CheckValid(IList<ObjectId> objectIds) //{ // var result = IsValid(objectIds); // System.Diagnostics.Trace.WriteLine(result.Count); // return result.Keys.ToList(); //} public static Dictionary <ObjectId, SingleTopologyError> CheckValid(IList <ObjectId> objectIds) { var errorDictionary = new Dictionary <ObjectId, SingleTopologyError>(); if (!objectIds.Any()) { return(errorDictionary); } var database = objectIds[0].Database; var geometries = new List <IGeometry>(); using (var tr = database.TransactionManager.StartTransaction()) { var reader = new DwgReader(); foreach (ObjectId objectId in objectIds) { if (!objectId.IsValid) { continue; } IGeometry geom = reader.ReadEntityAsGeometry(tr, objectId); if (geom == null) { continue; } geometries.Add(geom); if (!geom.IsValid) { var ivop = new IsValidOp(geom); if (!ivop.IsValid) { Console.WriteLine(geom.AsText()); Console.Write(ivop.ValidationError); int errorType = (int)ivop.ValidationError.ErrorType; var point = new Point3d(ivop.ValidationError.Coordinate.X, ivop.ValidationError.Coordinate.Y, 0); var error = new SingleTopologyError((SingleTopologyErrors)errorType, point); errorDictionary.Add(objectId, error); } } } tr.Commit(); } return(errorDictionary); }
public static void Cad2dModels() { DxfModel model; Assembly assembly = Assembly.GetExecutingAssembly(); var input = assembly.GetManifestResourceStream("ZebecLoadMaster.Images.TankPlan_FairyTale.dwg"); model = DwgReader.Read(input); Models.clsGlobVar.CentrelineProfile = model; model = null; input = null; assembly = null; }
//Read DWG or DXF public static DxfModel ReadDxf(string _filename) { DxfModel _model = null; string extension = Path.GetExtension(_filename); if (string.Compare(extension, ".dwg", true) == 0) { _model = DwgReader.Read(_filename); } else { _model = DxfReader.Read(_filename); } return(_model); }
static void ReadDwg() { string[] files = Directory.GetFiles(PathSamples + "/dwg/", "*.dwg"); foreach (var f in files) { using (DwgReader reader = new DwgReader(f, onNotification)) { CadDocument doc = reader.Read(); } Console.WriteLine($"file read : {f}"); Console.ReadLine(); } }
public static bool WithIn(ObjectId hole, ObjectId pacelId) { using (var tr = hole.Database.TransactionManager.StartTransaction()) { // 读入多边形数据 var reader = new DwgReader(); var polygon = reader.ReadEntityAsPolygon(tr, hole) as IPolygon; var polygon2 = reader.ReadEntityAsPolygon(tr, pacelId) as IPolygon; if (polygon != null && polygon2 != null) { return(polygon.Within(polygon2)); } } return(false); }
public static IList <Point3d> GetMinimumDiameterRectangle(Entity entity, Transaction tr) { var reader = new DwgReader(); var geomerty = reader.ReadGeometry(entity, tr); var diameter = new NetTopologySuite.Algorithm.MinimumDiameter(geomerty); var rectangle = diameter.GetMinimumRectangle(); var coordinates = new List <Point3d>(); foreach (var coordinate in rectangle.Coordinates) { var point = new Point3d(coordinate.X, coordinate.Y, 0); coordinates.Add(point); } return(coordinates); }
private void OpenDxfFile_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "AutoCad files (*.dwg, *.dxf)|*.dxf;*.dwg"; if (dialog.ShowDialog() == DialogResult.OK) { filename = dialog.FileName; } if (!string.IsNullOrEmpty(filename)) { //this.xtraTabPage1.BackColor = System.Drawing.Color.Black; try { //通过文件扩展名判断CAD文件是dwg格式还是dxf格式 string extension = Path.GetExtension(filename); if (string.Compare(extension, ".dwg", true) == 0) { model = DwgReader.Read(filename); } else { model = DxfReader.Read(filename); } //将控件的标签添加上文件名 this.xtraTabPage1.Text = "二维仿真(" + Path.GetFileName(filename) + ")"; //设置控件背景为黑色 this.xtraTabPage1.BackColor = System.Drawing.Color.Black; //使用GDIGraphics3D绘制CAD文件的方法 //创建中间可绘制对象 gdiGraphics3D = new GDIGraphics3D(GraphicsConfig.BlackBackgroundCorrectForBackColor); gdiGraphics3D.CreateDrawables(model); //获得bounding box bounds = new Bounds3D(); gdiGraphics3D.BoundingBox(bounds, modelTransform); //计算GDIGraphics3D的属性To2DTransform CalculateTo2DTransform(); //响应控件的Paint事件,画CAD文件 } catch (Exception ex) { MessageBox.Show("文件有错!请用AutoCad打开,通过“文件-核查”尝试修复。错误信息:" + ex.Message); } } }
public static Dictionary <Curve, IList <Curve> > GetNearGeometries(IEnumerable <Curve> curves, double buffer, bool forceClosed = true) { var dictionary = new Dictionary <Curve, IList <Curve> >(); var quadtree = new Quadtree <IGeometry>(); var reader = new DwgReader(); var geometries = new List <IGeometry>(); foreach (var curve in curves) { // 目前只处理封闭的和大于3的多边形 // http://192.168.0.6:8080/browse/LCLIBCAD-903 // 否则会弹出“points must form a closed linestring”异常 if (forceClosed && !curve.Closed || !reader.NumberOfVerticesMoreThan3(curve)) { continue; } var geom = reader.ReadCurveAsPolygon(null, curve) as Polygon; if (geom == null) { continue; } geom.UserData = curve; quadtree.Insert(geom.EnvelopeInternal, geom); geometries.Add(geom); } foreach (var geom in geometries) { var nearGeoms = GetNearGeometries(geom, quadtree, buffer); var curve = (Curve)geom.UserData; var nearCurves = new List <Curve>(); foreach (var geometry in nearGeoms) { var nearCurve = (Curve)geometry.UserData; if (nearCurve != curve) { nearCurves.Add(nearCurve); } } dictionary[curve] = nearCurves; } return(dictionary); }
public static bool IsCcw(Curve curve, Transaction tr) { var reader = new DwgReader(); var geomerty = reader.ReadCurveAsLineString(tr, curve); /* * This check catches cases where the ring contains an A-B-A configuration of points. * This can happen if the ring does not contain 3 distinct points * (including the case where the input array has fewer than 4 elements), * or it contains coincident line segments. */ if (geomerty.CoordinateSequence.Count < 3) // To avoid exception from CGAlgorithms.IsCCW routine { return(false); } return(CGAlgorithms.IsCCW(geomerty.CoordinateSequence)); }
public static List <ObjectId> FindHoles() { var polylineIds = CadUtils.FindAllPolylines(Application.DocumentManager.MdiActiveDocument); var datebase = Application.DocumentManager.MdiActiveDocument.Database; using (var tr = datebase.TransactionManager.StartTransaction()) { // 读入多边形数据 var reader = new DwgReader(); var polygons = new List <IPolygon>(); var quadtree = new Quadtree <IGeometry>(); foreach (ObjectId polylineId in polylineIds) { var polygon = reader.ReadEntityAsPolygon(tr, polylineId) as IPolygon; if (polygon != null) { polygons.Add(polygon); quadtree.Insert(polygon.EnvelopeInternal, polygon); } } var possibleHoleIds = new List <ObjectId>(); // 便利多边形,如果有洞,开始计算 foreach (var polygon in polygons) { // 找洞 foreach (var geom in quadtree.Query(polygon.EnvelopeInternal)) { var insidePolygon = geom as IPolygon; if (insidePolygon != null && polygon.Within(insidePolygon) && insidePolygon.UserData != polygon.UserData) // 不要是自己 { possibleHoleIds.Add((ObjectId)insidePolygon.UserData); } } } tr.Commit(); return(possibleHoleIds); } }
static void ReadDwg() { //string file = Path.Combine(PathSamples, "dwg/drawing_2000.dwg"); //string file = Path.Combine(PathSamples, "dwg/drawing_2007.dwg"); //string file = Path.Combine(PathSamples, "dwg/drawing_2010.dwg"); //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_R14.dwg"); //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2000.dwg"); string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2007.dwg"); //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2010.dwg"); //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2013.dwg"); //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2018.dwg"); using (DwgReader reader = new DwgReader(file)) { CadDocument doc = reader.Read(onProgress); } }
public bool ContainsHole(ObjectId holeId) { using (var tr = ObjectId.Database.TransactionManager.StartTransaction()) { var curve = tr.GetObject(ObjectId, OpenMode.ForRead) as Curve; var hole = tr.GetObject(holeId, OpenMode.ForRead) as Curve; if (curve != null && curve.Closed && hole != null && hole.Closed) { var reader = new DwgReader(); var polygon1 = reader.ReadCurveAsPolygon(tr, curve); var polygon2 = reader.ReadCurveAsPolygon(tr, hole); if (polygon1.Contains(polygon2)) { return(true); } } } return(false); }
public IPolygon GetPolygon(Transaction tr) { var curve = tr.GetObject(ObjectId, OpenMode.ForRead) as Curve; if (curve != null && curve.Closed) { var holeIds = FindHolesInEntity(tr, curve); var reader = new DwgReader(); var polygon = reader.ReadCurveAsPolygon(tr, curve); var linearRings = new List <ILinearRing>(); foreach (var holeId in holeIds) { // 处理洞 var insideCurve = tr.GetObject(holeId, OpenMode.ForRead) as Curve; if (insideCurve != null && curve.Closed) { var insidePolygon = reader.ReadCurveAsPolygon(tr, insideCurve); if (polygon.Contains(insidePolygon)) { ILinearRing linearRing = reader.GeometryFactory.CreateLinearRing(insidePolygon.ExteriorRing.CoordinateSequence); if (!linearRing.IsCCW) { linearRing.Reverse(); } linearRings.Add(linearRing); } } } if (!linearRings.Any()) { return(polygon); } // 返回新建的多边形 IPolygon newPolygon = reader.GeometryFactory.CreatePolygon(polygon.Shell, linearRings.ToArray()); return(newPolygon); } return(null); }
public static Dictionary <ObjectId, IList <Point3d> > LineStringSelfIntersectionsOp(IList <ObjectId> objectIds) { var dictionary = new Dictionary <ObjectId, IList <Point3d> >(); var database = objectIds[0].Database; using (var tr = database.TransactionManager.StartTransaction()) { var reader = new DwgReader(); foreach (ObjectId objectId in objectIds) { if (!objectId.IsValid) { continue; } var curve = tr.GetObject(objectId, OpenMode.ForRead) as Curve; var geom = reader.ReadCurveAsLineString(tr, curve) as LineString; var intersectGeom = LineStringSelfIntersectionsOp(geom); var points = new List <Point3d>(); foreach (var coordinate in intersectGeom.Coordinates) { // 如果是NaN直接设定为0 if (double.IsNaN(coordinate.Z)) { coordinate.Z = 0; } points.Add(new Point3d(coordinate.X, coordinate.Y, coordinate.Z)); } dictionary.Add(objectId, points); } tr.Commit(); } return(dictionary); }
private void 打开文件_Click(object sender, EventArgs e) { string filename = null; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "AutoCad files (*.dxf, *.dwg)|*.dxf;*.dwg"; if (openFileDialog.ShowDialog() == DialogResult.OK) { try { filename = openFileDialog.FileName; } catch (Exception ex) { MessageBox.Show("Error occurred: " + ex.Message); Environment.Exit(1); } } else { Environment.Exit(0); } DxfModel model; string extension = Path.GetExtension(filename); if (string.Compare(extension, ".dwg", true) == 0) { model = DwgReader.Read(filename); } else { model = DxfReader.Read(filename); } viewControl.Model = model; }
public static DxfModel Read(string filename, out DxfMessageCollection messagesReturn) { string extension = Path.GetExtension(filename); DxfModel dxfModel; if (string.Compare(extension, ".dwg", StringComparison.InvariantCultureIgnoreCase) == 0) { dxfModel = DwgReader.Read(filename, (ProgressEventHandler)null, out messagesReturn); } else if (string.Compare(extension, ".dxf", StringComparison.InvariantCultureIgnoreCase) == 0) { dxfModel = DxfReader.Read(filename, (ProgressEventHandler)null, out messagesReturn); } else { if (string.Compare(extension, ".gz", StringComparison.InvariantCultureIgnoreCase) != 0 && string.Compare(extension, ".zip", StringComparison.InvariantCultureIgnoreCase) != 0) { throw new ArgumentException("Unknown extension " + extension + ", it must be either .dxf or .dwg."); } dxfModel = DxfReader.Read(filename, (ProgressEventHandler)null, out messagesReturn); } return(dxfModel); }