Beispiel #1
0
        public static List <Triangle> ToCeometricTriangleList(ObjectId[] idArray)
        {
            if (idArray == null)
            {
                throw new System.Exception("No faces selected.");
            }
            Database        workingDatabase = HostApplicationServices.WorkingDatabase;
            List <Triangle> list            = new List <Triangle>();

            using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
            {
                for (int i = 0; i < idArray.Length; i++)
                {
                    Autodesk.AutoCAD.DatabaseServices.Face face = (Autodesk.AutoCAD.DatabaseServices.Face)transaction.GetObject(idArray[i], (OpenMode)0, true);
                    Point3d vertexAt  = face.GetVertexAt(0);
                    Point3d vertexAt2 = face.GetVertexAt(1);
                    Point3d vertexAt3 = face.GetVertexAt(2);
                    Point3d vertexAt4 = face.GetVertexAt(3);
                    ngeometry.VectorGeometry.Point point  = new ngeometry.VectorGeometry.Point(vertexAt.X, vertexAt.Y, vertexAt.Z);
                    ngeometry.VectorGeometry.Point point2 = new ngeometry.VectorGeometry.Point(vertexAt2.X, vertexAt2.Y, vertexAt2.Z);
                    ngeometry.VectorGeometry.Point point3 = new ngeometry.VectorGeometry.Point(vertexAt3.X, vertexAt3.Y, vertexAt3.Z);
                    ngeometry.VectorGeometry.Point point4 = new ngeometry.VectorGeometry.Point(vertexAt4.X, vertexAt4.Y, vertexAt4.Z);
                    if (point != point2 && point != point3 && point != point4 && point2 != point3 && point2 != point4 && point3 != point4)
                    {
                        list.Add(new Triangle(point, point2, point4, false));
                        list.Add(new Triangle(point2, point3, point4, false));
                    }
                    else
                    {
                        list.Add(new Triangle(point, point2, point3, false));
                    }
                }
            }
            return(list);
        }
Beispiel #2
0
        public static List <Triangle> ToCeometricCADDataTriangleList(ObjectId[] faceIDs)
        {
            Database        workingDatabase = HostApplicationServices.WorkingDatabase;
            List <Triangle> list            = new List <Triangle>();

            using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
            {
                string     blockModelSpaceName = SymbolUtilityServices.BlockModelSpaceName;
                LayerTable arg_30_0            = (LayerTable)transaction.GetObject(workingDatabase.LayerTableId, (OpenMode)0);
                for (int i = 0; i < faceIDs.Length; i++)
                {
                    Autodesk.AutoCAD.DatabaseServices.Face face = (Autodesk.AutoCAD.DatabaseServices.Face)transaction.GetObject(faceIDs[i], (OpenMode)0, true);
                    LayerTableRecord layerTableRecord           = (LayerTableRecord)transaction.GetObject(face.LayerId, (OpenMode)0);
                    Autodesk.AutoCAD.Colors.Color color         = face.Color;
                    if (color.IsByLayer)
                    {
                        color = layerTableRecord.Color;
                    }
                    System.Drawing.Color empty = System.Drawing.Color.Empty;
                    short colorIndex           = 256;
                    Conversions.GetColors(color, ref empty, ref colorIndex);
                    CADData cADData = new CADData();
                    cADData.Layer.Name = layerTableRecord.Name;
                    cADData.Color      = empty;
                    cADData.ColorIndex = colorIndex;
                    cADData.BlockName  = blockModelSpaceName;
                    Point3d vertexAt  = face.GetVertexAt(0);
                    Point3d vertexAt2 = face.GetVertexAt(1);
                    Point3d vertexAt3 = face.GetVertexAt(2);
                    Point3d vertexAt4 = face.GetVertexAt(3);
                    ngeometry.VectorGeometry.Point point  = new ngeometry.VectorGeometry.Point(vertexAt.X, vertexAt.Y, vertexAt.Z);
                    ngeometry.VectorGeometry.Point point2 = new ngeometry.VectorGeometry.Point(vertexAt2.X, vertexAt2.Y, vertexAt2.Z);
                    ngeometry.VectorGeometry.Point point3 = new ngeometry.VectorGeometry.Point(vertexAt3.X, vertexAt3.Y, vertexAt3.Z);
                    ngeometry.VectorGeometry.Point point4 = new ngeometry.VectorGeometry.Point(vertexAt4.X, vertexAt4.Y, vertexAt4.Z);
                    if (point != point2 && point != point3 && point != point4 && point2 != point3 && point2 != point4 && point3 != point4)
                    {
                        list.Add(new Triangle(point, point2, point4, false)
                        {
                            CADData = cADData
                        });
                        list.Add(new Triangle(point2, point3, point4, false)
                        {
                            CADData = cADData
                        });
                    }
                    else
                    {
                        list.Add(new Triangle(point, point2, point3, false)
                        {
                            CADData = cADData
                        });
                    }
                }
            }
            return(list);
        }
Beispiel #3
0
        internal static ObjectId[] smethod_0(ObjectId[] objectId_0)
        {
            Database        workingDatabase = HostApplicationServices.WorkingDatabase;
            List <ObjectId> list            = new List <ObjectId>();

            using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
            {
                BlockTable arg_2A_0 = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)0);
                for (int i = objectId_0.Length - 1; i >= 0; i--)
                {
                    Autodesk.AutoCAD.DatabaseServices.Face face = (Autodesk.AutoCAD.DatabaseServices.Face)transaction.GetObject(objectId_0[i], (OpenMode)1, true);
                    BlockTableRecord blockTableRecord           = (BlockTableRecord)transaction.GetObject(face.BlockId, (OpenMode)1);
                    Point3d          vertexAt             = face.GetVertexAt(0);
                    Point3d          vertexAt2            = face.GetVertexAt(1);
                    Point3d          vertexAt3            = face.GetVertexAt(2);
                    Point3d          vertexAt4            = face.GetVertexAt(3);
                    ngeometry.VectorGeometry.Point left   = new ngeometry.VectorGeometry.Point(vertexAt.X, vertexAt.Y, vertexAt.Z);
                    ngeometry.VectorGeometry.Point point  = new ngeometry.VectorGeometry.Point(vertexAt2.X, vertexAt2.Y, vertexAt2.Z);
                    ngeometry.VectorGeometry.Point point2 = new ngeometry.VectorGeometry.Point(vertexAt3.X, vertexAt3.Y, vertexAt3.Z);
                    ngeometry.VectorGeometry.Point right  = new ngeometry.VectorGeometry.Point(vertexAt4.X, vertexAt4.Y, vertexAt4.Z);
                    if (left != point && left != point2 && left != right && point != point2 && point != right && point2 != right)
                    {
                        Autodesk.AutoCAD.DatabaseServices.Face face2 = new Autodesk.AutoCAD.DatabaseServices.Face(vertexAt, vertexAt2, vertexAt4, true, true, true, true);
                        face2.LayerId = (face.LayerId);
                        blockTableRecord.AppendEntity(face2);
                        transaction.AddNewlyCreatedDBObject(face2, true);
                        list.Add(face2.ObjectId);
                        Autodesk.AutoCAD.DatabaseServices.Face face3 = new Autodesk.AutoCAD.DatabaseServices.Face(vertexAt2, vertexAt3, vertexAt4, true, true, true, true);
                        face3.LayerId = (face.LayerId);
                        blockTableRecord.AppendEntity(face3);
                        transaction.AddNewlyCreatedDBObject(face3, true);
                        list.Add(face3.ObjectId);
                        if (!face.IsErased)
                        {
                            face.Erase();
                        }
                    }
                    else
                    {
                        list.Add(face.ObjectId);
                    }
                }
                transaction.Commit();
            }
            return(list.ToArray());
        }
Beispiel #4
0
        public IdEdge(Autodesk.AutoCAD.DatabaseServices.Line line, Autodesk.AutoCAD.DatabaseServices.Face face)
        {
            //System.ComponentModel.LicenseManager.Validate(typeof(IdEdge));
            this.MinX = double.NaN;
            this.MaxX = double.NaN;
            this.MinY = double.NaN;
            this.MaxY = double.NaN;
            //base..ctor();
            this.Line = line;
            this.Face = face;
            Point3d startPoint = line.StartPoint;
            Point3d endPoint   = line.EndPoint;

            this.Edge = new Edge(new Point(startPoint.X, startPoint.Y, startPoint.Z), new Point(endPoint.X, endPoint.Y, endPoint.Z));
            this.MinX = Math.Min(this.Edge.StartPoint.X, this.Edge.EndPoint.X);
            this.MaxX = Math.Max(this.Edge.StartPoint.X, this.Edge.EndPoint.X);
            this.MinY = Math.Min(this.Edge.StartPoint.Y, this.Edge.EndPoint.Y);
            this.MaxY = Math.Max(this.Edge.StartPoint.Y, this.Edge.EndPoint.Y);
        }
Beispiel #5
0
        public static List <Triangle> ToCeometricAcDbTriangleList(ObjectId[] faceIDs)
        {
            Database        workingDatabase = HostApplicationServices.WorkingDatabase;
            List <Triangle> list            = new List <Triangle>();

            using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
            {
                for (int i = 0; i < faceIDs.Length; i++)
                {
                    Autodesk.AutoCAD.DatabaseServices.Face face = (Autodesk.AutoCAD.DatabaseServices.Face)transaction.GetObject(faceIDs[i], (OpenMode)0, true);
                    Point3d vertexAt  = face.GetVertexAt(0);
                    Point3d vertexAt2 = face.GetVertexAt(1);
                    Point3d vertexAt3 = face.GetVertexAt(2);
                    Point3d vertexAt4 = face.GetVertexAt(3);
                    ngeometry.VectorGeometry.Point point  = new ngeometry.VectorGeometry.Point(vertexAt.X, vertexAt.Y, vertexAt.Z);
                    ngeometry.VectorGeometry.Point point2 = new ngeometry.VectorGeometry.Point(vertexAt2.X, vertexAt2.Y, vertexAt2.Z);
                    ngeometry.VectorGeometry.Point point3 = new ngeometry.VectorGeometry.Point(vertexAt3.X, vertexAt3.Y, vertexAt3.Z);
                    ngeometry.VectorGeometry.Point point4 = new ngeometry.VectorGeometry.Point(vertexAt4.X, vertexAt4.Y, vertexAt4.Z);
                    if (point != point2 && point != point3 && point != point4 && point2 != point3 && point2 != point4 && point3 != point4)
                    {
                        list.Add(new Triangle(point, point2, point4, false)
                        {
                            AcDbFace = face
                        });
                        list.Add(new Triangle(point2, point3, point4, false)
                        {
                            AcDbFace = face
                        });
                    }
                    else
                    {
                        list.Add(new Triangle(point, point2, point3, false)
                        {
                            AcDbFace = face
                        });
                    }
                }
            }
            return(list);
        }
Beispiel #6
0
        private void method_3(ObjectId[] objectId_0)
        {
            Editor        editor          = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Database      workingDatabase = HostApplicationServices.WorkingDatabase;
            MessageFilter messageFilter   = new MessageFilter();

            System.Windows.Forms.Application.AddMessageFilter(messageFilter);
            ProgressMeter progressMeter = new ProgressMeter();

            progressMeter.SetLimit(objectId_0.Length);
            progressMeter.Start("Writing 3df");
            try
            {
                CoordinateTransformator2 coordinateTransformator = new CoordinateTransformator2(CoordinateSystem.Global(), Conversions.GetUCS());
                int    num  = 0;
                int    num2 = 0;
                string text = this.method_6();
                using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
                {
                    using (StreamWriter streamWriter = new StreamWriter(IO2.string_2))
                    {
                        streamWriter.WriteLine(string.Concat(new object[]
                        {
                            "C ",
                            IO2.string_2,
                            " generated ",
                            DateTime.Now
                        }));
                        if (text == ",")
                        {
                            streamWriter.WriteLine("C Format: Layer name, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4");
                        }
                        if (text == ";")
                        {
                            streamWriter.WriteLine("C Format: Layer name; x1; y1; z1; x2; y2; z2; x3; y3; z3; x4; y4; z4");
                        }
                        if (text == " ")
                        {
                            streamWriter.WriteLine("C Format: Layer name  x1  y1  z1  x2  y2  z2  x3  y3  z3  x4  y4  z4");
                        }
                        for (int i = 0; i < objectId_0.Length; i++)
                        {
                            Autodesk.AutoCAD.DatabaseServices.Face face = (Autodesk.AutoCAD.DatabaseServices.Face)transaction.GetObject(objectId_0[i], (OpenMode)0, true);
                            Point3d vertexAt  = face.GetVertexAt(0);
                            Point3d vertexAt2 = face.GetVertexAt(1);
                            Point3d vertexAt3 = face.GetVertexAt(2);
                            Point3d vertexAt4 = face.GetVertexAt(3);
                            ngeometry.VectorGeometry.Point point  = new ngeometry.VectorGeometry.Point(vertexAt.X, vertexAt.Y, vertexAt.Z);
                            ngeometry.VectorGeometry.Point point2 = new ngeometry.VectorGeometry.Point(vertexAt2.X, vertexAt2.Y, vertexAt2.Z);
                            ngeometry.VectorGeometry.Point point3 = new ngeometry.VectorGeometry.Point(vertexAt3.X, vertexAt3.Y, vertexAt3.Z);
                            ngeometry.VectorGeometry.Point point4 = new ngeometry.VectorGeometry.Point(vertexAt4.X, vertexAt4.Y, vertexAt4.Z);
                            coordinateTransformator.Transform(point);
                            coordinateTransformator.Transform(point2);
                            coordinateTransformator.Transform(point3);
                            coordinateTransformator.Transform(point4);
                            string text2 = face.Layer.PadLeft(IO2.int_0) + text;
                            text2 += this.method_5(point, ref num);
                            text2 += this.method_5(point2, ref num);
                            text2 += this.method_5(point3, ref num);
                            text2 += this.method_5(point4, ref num);
                            streamWriter.WriteLine(text2.TrimEnd(new char[0]));
                            progressMeter.MeterProgress();
                            messageFilter.CheckMessageFilter((long)i, 10000);
                            num2++;
                        }
                        streamWriter.Flush();
                    }
                }
                progressMeter.Stop();
                if (num > 0)
                {
                    editor.WriteMessage(string.Concat(new object[]
                    {
                        Environment.NewLine,
                        num,
                        " conversion errors occurred writing ",
                        IO2.string_2,
                        ". Increase the column width and/or decrease the number of decimal digits."
                    }));
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Concat(new object[]
                    {
                        num,
                        " conversion errors occurred writing ",
                        IO2.string_2,
                        ".\nIncrease the column width and/or decrease the number of decimal digits."
                    }));
                }
                FileInfo fileInfo = new FileInfo(IO2.string_2);
                editor.WriteMessage(Environment.NewLine + "Output file name            : " + fileInfo.FullName);
                editor.WriteMessage(Environment.NewLine + "Number of faces written     : " + num2.ToString());
                editor.WriteMessage(Environment.NewLine + "Coordinate conversion errors: " + num.ToString());
            }
            catch (System.Exception ex)
            {
                progressMeter.Stop();
                throw;
            }
        }
Beispiel #7
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;
            }
        }
Beispiel #8
0
        private void method_1(ObjectId[] objectId_0)
        {
            Editor        editor          = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Database      workingDatabase = HostApplicationServices.WorkingDatabase;
            EntityList    entityList      = new EntityList();
            int           num             = 0;
            int           num2            = 0;
            int           num3            = 0;
            int           num4            = 0;
            MessageFilter messageFilter   = new MessageFilter();

            System.Windows.Forms.Application.AddMessageFilter(messageFilter);
            ProgressMeter progressMeter = new ProgressMeter();

            progressMeter.SetLimit(objectId_0.Length);
            progressMeter.Start("Serializing XML entities");
            try
            {
                CoordinateTransformator2 coordinateTransformator = new CoordinateTransformator2(CoordinateSystem.Global(), Conversions.GetUCS());
                using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
                {
                    LayerTable arg_83_0 = (LayerTable)transaction.GetObject(workingDatabase.LayerTableId, (OpenMode)0);
                    for (int i = 0; i < objectId_0.Length; i++)
                    {
                        messageFilter.CheckMessageFilter((long)i, 10000);
                        progressMeter.MeterProgress();
                        Entity entity = (Entity)transaction.GetObject(objectId_0[i], (OpenMode)0);
                        string name   = ((LayerTableRecord)transaction.GetObject(entity.LayerId, (OpenMode)0)).Name;
                        Autodesk.AutoCAD.DatabaseServices.Face face = entity as Autodesk.AutoCAD.DatabaseServices.Face;
                        if (face != null)
                        {
                            Point3d vertexAt  = face.GetVertexAt(0);
                            Point3d vertexAt2 = face.GetVertexAt(1);
                            Point3d vertexAt3 = face.GetVertexAt(2);
                            Point3d vertexAt4 = face.GetVertexAt(3);
                            global::TerrainComputeC.XML.Vertex v     = new global::TerrainComputeC.XML.Vertex(vertexAt.X, vertexAt.Y, vertexAt.Z);
                            global::TerrainComputeC.XML.Vertex v2    = new global::TerrainComputeC.XML.Vertex(vertexAt2.X, vertexAt2.Y, vertexAt2.Z);
                            global::TerrainComputeC.XML.Vertex v3    = new global::TerrainComputeC.XML.Vertex(vertexAt3.X, vertexAt3.Y, vertexAt3.Z);
                            global::TerrainComputeC.XML.Vertex v4    = new global::TerrainComputeC.XML.Vertex(vertexAt4.X, vertexAt4.Y, vertexAt4.Z);
                            global::TerrainComputeC.XML.Face   face2 = new global::TerrainComputeC.XML.Face(v, v2, v3, v4);
                            face2.SetProperties(name, face.Color.ColorIndex);
                            entityList.Faces.Add(face2);
                            coordinateTransformator.Transform(face2);
                            num4++;
                        }
                        else
                        {
                            DBPoint dBPoint = entity as DBPoint;
                            if (dBPoint != null)
                            {
                                global::TerrainComputeC.XML.Point point = new global::TerrainComputeC.XML.Point(dBPoint.Position.X, dBPoint.Position.Y, dBPoint.Position.Z);
                                point.SetProperties(name, dBPoint.Color.ColorIndex);
                                entityList.Points.Add(point);
                                coordinateTransformator.Transform(point);
                                num++;
                            }
                            else
                            {
                                Autodesk.AutoCAD.DatabaseServices.Line line = entity as Autodesk.AutoCAD.DatabaseServices.Line;
                                if (line != null)
                                {
                                    Point3d startPoint = line.StartPoint;
                                    Point3d endPoint   = line.EndPoint;
                                    global::TerrainComputeC.XML.Vertex startVertex = new global::TerrainComputeC.XML.Vertex(startPoint.X, startPoint.Y, startPoint.Z);
                                    global::TerrainComputeC.XML.Vertex endVertex   = new global::TerrainComputeC.XML.Vertex(endPoint.X, endPoint.Y, endPoint.Z);
                                    global::TerrainComputeC.XML.Line   line2       = new global::TerrainComputeC.XML.Line(startVertex, endVertex);
                                    line2.SetProperties(name, line.Color.ColorIndex);
                                    entityList.Lines.Add(line2);
                                    coordinateTransformator.Transform(line2);
                                    num2++;
                                }
                                else
                                {
                                    Polyline   polyline   = entity as Polyline;
                                    Polyline2d polyline2d = entity as Polyline2d;
                                    Polyline3d polyline3d = entity as Polyline3d;
                                    if (polyline != null || polyline2d != null || polyline3d != null)
                                    {
                                        short colorIndex = 256;
                                        if (polyline != null)
                                        {
                                            colorIndex = polyline.Color.ColorIndex;
                                        }
                                        if (polyline2d != null)
                                        {
                                            colorIndex = polyline2d.Color.ColorIndex;
                                        }
                                        if (polyline3d != null)
                                        {
                                            colorIndex = polyline3d.Color.ColorIndex;
                                        }
                                        PointSet pointSet = PointGeneration.SubdividePolyline(entity, transaction, 0.0);
                                        List <global::TerrainComputeC.XML.Vertex> list = new List <global::TerrainComputeC.XML.Vertex>();
                                        for (int j = 0; j < pointSet.Count; j++)
                                        {
                                            list.Add(new global::TerrainComputeC.XML.Vertex(pointSet[j].X, pointSet[j].Y, pointSet[j].Z));
                                        }
                                        PolyLine polyLine = new PolyLine(list);
                                        polyLine.SetProperties(name, colorIndex);
                                        entityList.Polylines.Add(polyLine);
                                        coordinateTransformator.Transform(polyLine);
                                        num3++;
                                    }
                                }
                            }
                        }
                    }
                }
                progressMeter.Stop();
                editor.WriteMessage("\nXML entity list created:");
                editor.WriteMessage("\nNumber of points        : " + entityList.Points.Count);
                editor.WriteMessage("\nNumber of lines         : " + entityList.Lines.Count);
                editor.WriteMessage("\nNumber of polylines     : " + entityList.Polylines.Count);
                editor.WriteMessage("\nNumber of faces         : " + entityList.Faces.Count);
                editor.WriteMessage("\nTotal number of entities: " + entityList.Count);
                editor.WriteMessage("\nWriting xml file " + IO2.string_0 + "...");
                Serializer.Serialize(IO2.string_0, entityList);
                editor.WriteMessage("OK\n");
            }
            catch (System.Exception ex)
            {
                progressMeter.Stop();
                throw;
            }
        }
Beispiel #9
0
        public static void WriteListInDatabase <T>(List <T> entities, CoordinateSystem acutalCS, DBManager.EntityPropertiesAssignment propertyAssignmentMethod, ObjectId layerID, ObjectId blockID, string layerName)
        {
            if (entities != null && entities.Count != 0)
            {
                Database      workingDatabase = HostApplicationServices.WorkingDatabase;
                Editor        editor          = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
                ProgressMeter progressMeter   = new ProgressMeter();
                MessageFilter messageFilter   = new MessageFilter();
                System.Windows.Forms.Application.AddMessageFilter(messageFilter);

                List <Triangle> triList = new List <Triangle>();

                try
                {
                    blockID = SymbolUtilityServices.GetBlockModelSpaceId(workingDatabase);
                    if (layerName != null)
                    {
                        layerID = LayerUtil.CreateLayer(layerName, 127, false);
                    }
                    else
                    {
                        layerID = ObjectId.Null;
                    }

                    if (typeof(T) != typeof(Triangle))
                    {
                        throw new NotImplementedException("Generic list type not supported: " + typeof(T).ToString());
                    }

                    triList = (List <Triangle>)Convert.ChangeType(entities, typeof(List <Triangle>));

                    if (acutalCS != null)
                    {
                        Conversions.ToWCS(acutalCS, triList);
                    }
                    progressMeter.SetLimit(entities.Count);
                    progressMeter.Start("Writing database");
                    using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
                    {
                        LayerTable       layerTable       = (LayerTable)transaction.GetObject(workingDatabase.LayerTableId, (OpenMode)0);
                        BlockTable       blockTable       = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)0);
                        BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockID, (OpenMode)1);
                        for (int i = 0; i < entities.Count; i++)
                        {
                            Autodesk.AutoCAD.Colors.Color color = null;
                            short   colorIndex = 256;
                            Point3d point3d3   = new Point3d(triList[i].Vertex1.X, triList[i].Vertex1.Y, triList[i].Vertex1.Z);

                            Point3d point3d4 = new Point3d(triList[i].Vertex2.X, triList[i].Vertex2.Y, triList[i].Vertex2.Z);

                            Point3d point3d5 = new Point3d(triList[i].Vertex3.X, triList[i].Vertex3.Y, triList[i].Vertex3.Z);

                            Entity entity = new Autodesk.AutoCAD.DatabaseServices.Face(point3d3, point3d4, point3d5, true, true, true, true);

                            if (layerID != ObjectId.Null)
                            {
                                entity.LayerId = (layerID);
                            }

                            if (color == null)
                            {
                                entity.ColorIndex = ((int)colorIndex);
                            }
                            else
                            {
                                entity.Color = (color);
                            }
                            blockTableRecord.AppendEntity(entity);
                            transaction.AddNewlyCreatedDBObject(entity, true);
                            progressMeter.MeterProgress();
                            messageFilter.CheckMessageFilter((long)i, 10000);
                        }

                        transaction.Commit();
                    }

                    progressMeter.Stop();
                    editor.WriteMessage(Environment.NewLine + entities.Count.ToString() + " entities written to database.");
                    editor.WriteMessage("\n");
                    editor.Regen();
                    return;
                }
                catch
                {
                    progressMeter.Stop();
                    throw;
                }
            }
            throw new System.Exception("No entities written in database.");
        }