Example #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);
            }
        }
        public void GenerateSolidCommand()
        {
            ProgressMeter progressMeter = new ProgressMeter();
            Database      arg_0B_0      = HostApplicationServices.WorkingDatabase;
            Editor        editor        = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            this.messageFilter_0 = new MessageFilter();
            System.Windows.Forms.Application.AddMessageFilter(this.messageFilter_0);
            try
            {
                //LicenseManager.CheckValid("FULL");
                ObjectId[] objectId_ = CommandLineQuerries.SelectFaces(false);
                CMD_FacesToSolid.string_1 = CommandLineQuerries.SpecifyReferencePlane(CMD_FacesToSolid.string_1);
                CoordinateSystem coordinateSystem = CoordinateSystem.Global();
                if (CMD_FacesToSolid.string_1 == "U")
                {
                    coordinateSystem = Conversions.GetUCS();
                }
                if (CMD_FacesToSolid.string_1 == "3P")
                {
                    coordinateSystem = CommandLineQuerries.Specify3PSystem();
                }
                coordinateSystem.Orthonormalize();
                CMD_FacesToSolid.double_0 = CommandLineQuerries.SpecifyDouble("Extrusion height in actual Z", CMD_FacesToSolid.double_0, false, true, false, false);
                bool flag = false;
                while (!flag)
                {
                    CMD_FacesToSolid.string_2 = CommandLineQuerries.SpecifyString("Minimum projected edge length", CMD_FacesToSolid.string_2, false);
                    if (Convert.ToDouble(CMD_FacesToSolid.string_2) >= 0.0001 && Convert.ToDouble(CMD_FacesToSolid.string_2) <= 1.0)
                    {
                        flag = true;
                    }
                    else
                    {
                        editor.WriteMessage("\nValue must be between 0.0001 and 1.");
                    }
                }
                CMD_FacesToSolid.string_0 = CommandLineQuerries.KeywordYesNo("Union solids", CMD_FacesToSolid.string_0, false, false).ToUpper().Trim();
                this.method_0(objectId_, progressMeter, coordinateSystem);
            }
            catch (System.Exception ex)
            {
                progressMeter.Stop();
                editor.WriteMessage("\n" + ex.Message);
            }
        }