Exemple #1
0
        public void STLASCIIOutCommand()
        {
            Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                //LicenseManager.CheckValid("FULL");
                CommandLineQuerries.SpecifyFileNameForWrite(ref CMD_STL.string_2, ref CMD_STL.string_4, "stl");
                CMD_STL.string_1 = CommandLineQuerries.SpecifySTLType(CMD_STL.string_1);
                ObjectId[] array = CommandLineQuerries.SelectFaces(false);
                Global.SuspendEpsilon(0.0, 0.0);
                List <Triangle> list = Conversions.ToCeometricAcDbTriangleList(array);
                Global.ResumeEpsilon();
                string a;
                if ((a = CMD_STL.string_1) != null)
                {
                    if (!(a == "A"))
                    {
                        if (a == "B")
                        {
                            BinarySTL binarySTL = new BinarySTL();
                            binarySTL.Triangles = list;
                            for (int i = 0; i < list.Count; i++)
                            {
                                BinarySTL.STLColor sTLColor = new BinarySTL.STLColor();
                                sTLColor.R       = (byte)Math.Floor((double)list[i].AcDbFace.Color.Red / 8.0);
                                sTLColor.G       = (byte)Math.Floor((double)list[i].AcDbFace.Color.Green / 8.0);
                                sTLColor.B       = (byte)Math.Floor((double)list[i].AcDbFace.Color.Blue / 8.0);
                                sTLColor.IsValid = true;
                                sTLColor._cDef   = binarySTL.ColorDefinition;
                                binarySTL.Colors.Add(sTLColor);
                            }
                            binarySTL.Write(CMD_STL.string_2);
                            editor.WriteMessage("\nNumber of triangles written   : " + binarySTL.NumberOfTrianglesWritten.ToString());
                            editor.WriteMessage("\nNumber of degenerate triangles: " + binarySTL.NumberOfDegenerateTriangles.ToString());
                            editor.WriteMessage("\nHas negative coordinates      : " + binarySTL.HasNegativeCoordinates.ToString());
                            editor.WriteMessage("\nSTL file in binary format written to " + CMD_STL.string_2);
                        }
                    }
                    else
                    {
                        string   layerNameOfEntity = DBManager.GetLayerNameOfEntity(array[0]);
                        string   solidName         = CommandLineQuerries.SpecifyString("Specify STL solid name", layerNameOfEntity, true);
                        ASCIISTL aSCIISTL          = new ASCIISTL();
                        aSCIISTL.Triangles = list;
                        aSCIISTL.SolidName = solidName;
                        aSCIISTL.Write(CMD_STL.string_2);
                        editor.WriteMessage("\nNumber of triangles written   : " + aSCIISTL.NumberOfTrianglesWritten.ToString());
                        editor.WriteMessage("\nNumber of degenerate triangles: " + aSCIISTL.NumberOfDegenerateTriangles.ToString());
                        editor.WriteMessage("\nHas negative coordinates      : " + aSCIISTL.HasNegativeCoordinates.ToString());
                        editor.WriteMessage("\nSTL file in ASCII format written to " + CMD_STL.string_2);
                    }
                }
            }
            catch (System.Exception ex)
            {
                editor.WriteMessage("\n" + ex.Message);
            }
        }