Esempio n. 1
0
        private void method_4()
        {
            Editor        editor          = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Database      workingDatabase = HostApplicationServices.WorkingDatabase;
            string        value           = IO2.AutoDetermineDelimiter(IO2.string_4, false);
            char          c             = Convert.ToChar(value);
            MessageFilter messageFilter = new MessageFilter();

            System.Windows.Forms.Application.AddMessageFilter(messageFilter);
            int num = 0;

            using (StreamReader streamReader = new StreamReader(IO2.string_4))
            {
                while (streamReader.Peek() >= 0)
                {
                    streamReader.ReadLine();
                    num++;
                }
            }
            ProgressMeter progressMeter = new ProgressMeter();

            progressMeter.SetLimit(num);
            progressMeter.Start("Reading XYZ");
            try
            {
                CoordinateTransformator2 coordinateTransformator = new CoordinateTransformator2(Conversions.GetUCS(), CoordinateSystem.Global());
                using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
                {
                    ObjectId         layerId           = DBManager.CurrentLayerId();
                    BlockTable       arg_C3_0          = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)0);
                    ObjectId         blockModelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(workingDatabase);
                    BlockTableRecord blockTableRecord  = (BlockTableRecord)transaction.GetObject(blockModelSpaceId, (OpenMode)1);
                    int num2 = 1;
                    int num3 = 0;
                    using (StreamReader streamReader2 = new StreamReader(IO2.string_4))
                    {
                        while (streamReader2.Peek() >= 0)
                        {
                            string text = streamReader2.ReadLine().Trim();
                            if (!text.StartsWith("C", true, null))
                            {
                                try
                                {
                                    string[] array = text.Split(new char[]
                                    {
                                        c
                                    }, StringSplitOptions.RemoveEmptyEntries);
                                    double num4 = Convert.ToDouble(array[0]);
                                    double num5 = Convert.ToDouble(array[1]);
                                    double num6 = 0.0;
                                    if (array.Length > 2)
                                    {
                                        num6 = Convert.ToDouble(array[2]);
                                    }
                                    coordinateTransformator.Transform(ref num4, ref num5, ref num6);
                                    Entity entity = new DBPoint(new Point3d(num4, num5, num6));
                                    entity.LayerId    = (layerId);
                                    entity.ColorIndex = (256);
                                    blockTableRecord.AppendEntity(entity);
                                    transaction.AddNewlyCreatedDBObject(entity, true);
                                    num3++;
                                }
                                catch (System.Exception ex)
                                {
                                    if (text.Trim() == "")
                                    {
                                        text = "Empty line!";
                                    }
                                    throw new FormatException(string.Concat(new string[]
                                    {
                                        "Invalid point data format in line ",
                                        num2.ToString(),
                                        ":",
                                        Environment.NewLine,
                                        text,
                                        Environment.NewLine
                                    }));
                                }
                            }
                            num2++;
                            progressMeter.MeterProgress();
                            messageFilter.CheckMessageFilter((long)num2, 1000);
                        }
                    }
                    transaction.Commit();
                    progressMeter.Stop();
                    editor.WriteMessage(string.Concat(new object[]
                    {
                        Environment.NewLine,
                        num3,
                        " points read",
                        Environment.NewLine
                    }));
                }
                DBManager.ZoomExtents();
            }
            catch (System.Exception ex)
            {
                progressMeter.Stop();
                throw;
            }
        }
Esempio n. 2
0
        private void method_2()
        {
            Database      workingDatabase = HostApplicationServices.WorkingDatabase;
            Editor        editor          = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            string        value           = IO2.AutoDetermineDelimiter(IO2.string_3, true);
            char          c             = Convert.ToChar(value);
            MessageFilter messageFilter = new MessageFilter();

            System.Windows.Forms.Application.AddMessageFilter(messageFilter);
            int num = 0;

            using (StreamReader streamReader = new StreamReader(IO2.string_3))
            {
                while (streamReader.Peek() >= 0)
                {
                    streamReader.ReadLine();
                    num++;
                }
            }
            ProgressMeter progressMeter = new ProgressMeter();

            progressMeter.SetLimit(num);
            progressMeter.Start("Reading 3df file");
            try
            {
                CoordinateTransformator2 coordinateTransformator = new CoordinateTransformator2(Conversions.GetUCS(), CoordinateSystem.Global());
                using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
                {
                    LayerTable       lt                = (LayerTable)transaction.GetObject(workingDatabase.LayerTableId, (OpenMode)0);
                    BlockTable       arg_D1_0          = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)0);
                    ObjectId         blockModelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(workingDatabase);
                    BlockTableRecord blockTableRecord  = (BlockTableRecord)transaction.GetObject(blockModelSpaceId, (OpenMode)1);
                    int num2 = 1;
                    int num3 = 0;
                    using (StreamReader streamReader2 = new StreamReader(IO2.string_3))
                    {
                        while (streamReader2.Peek() >= 0)
                        {
                            string text = streamReader2.ReadLine();
                            if (!text.StartsWith("C", true, null) && !(text == ""))
                            {
                                try
                                {
                                    string[] array = text.Split(new char[]
                                    {
                                        c
                                    }, StringSplitOptions.RemoveEmptyEntries);
                                    string text2 = array[0].Trim();
                                    if (!DBManager.ValidateName(text2))
                                    {
                                        throw new System.Exception(string.Concat(new object[]
                                        {
                                            "Invalid layer name in line ",
                                            num2,
                                            ":\n",
                                            text
                                        }));
                                    }
                                    if (text2 == "")
                                    {
                                        text2 = "0";
                                    }
                                    double num4  = Convert.ToDouble(array[1]);
                                    double num5  = Convert.ToDouble(array[2]);
                                    double num6  = Convert.ToDouble(array[3]);
                                    double num7  = Convert.ToDouble(array[4]);
                                    double num8  = Convert.ToDouble(array[5]);
                                    double num9  = Convert.ToDouble(array[6]);
                                    double num10 = Convert.ToDouble(array[7]);
                                    double num11 = Convert.ToDouble(array[8]);
                                    double num12 = Convert.ToDouble(array[9]);
                                    double num13 = Convert.ToDouble(array[10]);
                                    double num14 = Convert.ToDouble(array[11]);
                                    double num15 = Convert.ToDouble(array[12]);
                                    coordinateTransformator.Transform(ref num4, ref num5, ref num6);
                                    coordinateTransformator.Transform(ref num7, ref num8, ref num9);
                                    coordinateTransformator.Transform(ref num10, ref num11, ref num12);
                                    coordinateTransformator.Transform(ref num13, ref num14, ref num15);
                                    Point3d point3d = new Point3d(num4, num5, num6);
                                    //point3d..ctor(num4, num5, num6);
                                    Point3d point3d2 = new Point3d(num7, num8, num9);
                                    //point3d2..ctor(num7, num8, num9);
                                    Point3d point3d3 = new Point3d(num10, num11, num12);
                                    //point3d3..ctor(num10, num11, num12);
                                    Point3d point3d4 = new Point3d(num13, num14, num15);
                                    //point3d4..ctor(num13, num14, num15);
                                    Entity entity = new Autodesk.AutoCAD.DatabaseServices.Face(point3d, point3d2, point3d3, point3d4, true, true, true, true);
                                    entity.LayerId    = (DBManager.GetLayerId(text2, 7, lt));
                                    entity.ColorIndex = (256);
                                    blockTableRecord.AppendEntity(entity);
                                    transaction.AddNewlyCreatedDBObject(entity, true);
                                    num3++;
                                }
                                catch (System.Exception ex)
                                {
                                    if (text.Trim() == "")
                                    {
                                        text = "Empty line!";
                                    }
                                    throw new FormatException(string.Concat(new string[]
                                    {
                                        "Invalid format in line ",
                                        num2.ToString(),
                                        ":",
                                        Environment.NewLine,
                                        text,
                                        Environment.NewLine
                                    }));
                                }
                            }
                            num2++;
                            progressMeter.MeterProgress();
                            messageFilter.CheckMessageFilter((long)num2, 1000);
                        }
                    }
                    transaction.Commit();
                    progressMeter.Stop();
                    editor.WriteMessage(string.Concat(new object[]
                    {
                        Environment.NewLine,
                        num3,
                        " faces read.",
                        Environment.NewLine
                    }));
                }
                DBManager.ZoomExtents();
            }
            catch (System.Exception ex)
            {
                progressMeter.Stop();
                throw;
            }
        }