Exemplo n.º 1
0
            public bool askForDistances(AC_Line acline)
            {
                circleCenter  = acline.StartPoint;
                previewCircle = new AC_Circle();
                previewCircle.addToDrawing();
                removeSnap noSnap = new removeSnap(previewCircle.ObjectId);

                ObjectOverrule.AddOverrule(RXObject.GetClass(typeof(Entity)), noSnap, true);

                drawPreviewCircle = true;
                PromptDistanceOptions DistOption = new PromptDistanceOptions("Triangulation Distance");

                DistOption.BasePoint    = circleCenter;
                DistOption.UseBasePoint = true;

                PromptDoubleResult triang1 = tr.AC_Doc.Editor.GetDistance(DistOption);

                if (triang1.Status == PromptStatus.OK)
                {
                    if (triang1.Value != 0)
                    {
                        tr.AC_Doc.Editor.WriteMessage(triang1.Value.ToString() + "\n");
                        circleCenter         = acline.EndPoint;
                        DistOption.BasePoint = circleCenter;
                        radius.Add(triang1.Value);
                        PromptDoubleResult triang2 = tr.AC_Doc.Editor.GetDistance(DistOption);
                        if (triang2.Status == PromptStatus.OK)
                        {
                            tr.AC_Doc.Editor.WriteMessage(triang2.Value.ToString() + "\n");
                            radius.Add(triang2.Value);
                            previewCircle.Visible = false;
                            drawPreviewCircle     = false;
                            return(true);
                        }
                        else
                        {
                            tr.AC_Doc.Editor.PointMonitor -= Editor_PointMonitor;
                            ObjectOverrule.RemoveOverrule(RXObject.GetClass(typeof(Entity)), noSnap);
                            previewCircle.Erase(true);
                            return(false);
                        }
                    }
                    else
                    {
                        tr.AC_Doc.Editor.PointMonitor -= Editor_PointMonitor;
                        tr.AC_Doc.Editor.WriteMessage("Cannot Calculate Triangulation \n");
                        ObjectOverrule.RemoveOverrule(RXObject.GetClass(typeof(Entity)), noSnap);
                        previewCircle.Erase(true);
                        return(false);
                    }
                }
                else
                {
                    tr.AC_Doc.Editor.PointMonitor -= Editor_PointMonitor;
                    ObjectOverrule.RemoveOverrule(RXObject.GetClass(typeof(Entity)), noSnap);
                    previewCircle.Visible = false;
                    drawPreviewCircle     = false;
                    return(false);
                }
            }
Exemplo n.º 2
0
        public void DistanceTest()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptDistanceOptions opt1 = new PromptDistanceOptions("Enter the radius of the circle");

            opt1.AllowNegative = false;
            opt1.AllowZero     = false;
            opt1.AllowNone     = false;
            opt1.UseDashedLine = true;

            PromptDoubleResult res = ed.GetDistance(opt1);

            if (res.Status == PromptStatus.OK)
            {
                Point3d  center = new Point3d(9.0, 3.0, 0.0);
                Vector3d normal = new Vector3d(0.0, 0.0, 1.0);
                Database db     = Application.DocumentManager.MdiActiveDocument.Database;
                Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
                using (Transaction myT = tm.StartTransaction())
                {
                    BlockTable       bt  = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                    BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                    using (Circle pcirc = new Circle(center, normal, res.Value))
                    {
                        btr.AppendEntity(pcirc);
                        tm.AddNewlyCreatedDBObject(pcirc, true);
                    }
                    myT.Commit();
                }
            }
        }
Exemplo n.º 3
0
        Stream(ArrayList data, PromptNumericalOptions opts)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(PromptNumericalOptions)));

            data.Add(new Snoop.Data.Bool("Allow arbitrary input", opts.AllowArbitraryInput));
            data.Add(new Snoop.Data.Bool("Allow none", opts.AllowNone));
            data.Add(new Snoop.Data.Bool("Allow negative", opts.AllowNegative));
            data.Add(new Snoop.Data.Bool("Allow zero", opts.AllowZero));
            data.Add(new Snoop.Data.Bool("Use default value", opts.UseDefaultValue));

            PromptIntegerOptions promptIntOpts = opts as PromptIntegerOptions;

            if (promptIntOpts != null)
            {
                Stream(data, promptIntOpts);
                return;
            }

            PromptDoubleOptions promptDoubleOpts = opts as PromptDoubleOptions;

            if (promptDoubleOpts != null)
            {
                Stream(data, promptDoubleOpts);
                return;
            }

            PromptDistanceOptions promptDistanceOpts = opts as PromptDistanceOptions;

            if (promptDistanceOpts != null)
            {
                Stream(data, promptDistanceOpts);
                return;
            }
        }
Exemplo n.º 4
0
        XformScale()
        {
            ObjectIdCollection selSet = null;

            if (Utils.AcadUi.GetSelSetFromUser(out selSet) == false)
            {
                return;
            }

            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            PromptPointResult prBasePtRes = ed.GetPoint("\nBase point");

            if (prBasePtRes.Status == PromptStatus.OK)
            {
                PromptDistanceOptions prScaleOpts = new PromptDistanceOptions("\nScale factor");
                prScaleOpts.AllowZero     = false;
                prScaleOpts.AllowNegative = false;

                PromptDoubleResult prScaleRes = ed.GetDistance(prScaleOpts);

                if (prScaleRes.Status == PromptStatus.OK)
                {
                    DoXform(selSet, Matrix3d.Scaling(prScaleRes.Value, Utils.Db.UcsToWcs(prBasePtRes.Value)));
                }
            }
        }
Exemplo n.º 5
0
        private bool GetTextHeight()
        {
            this.TextHeight = Ac.GetValue("OrthoDist.TextHeight").ToDouble();
            if (this.TextHeight <= 0.0)
            {
                this.TextHeight = 1.0;
            }

            var opts = new PromptDistanceOptions(AppServices.Strings.EnterTextHeight);

            opts.DefaultValue  = this.TextHeight;
            opts.Only2d        = true;
            opts.UseDashedLine = true;
            opts.UseBasePoint  = false;

            var res = Ac.Editor.GetDistance(opts);

            if (res.Status != PromptStatus.OK)
            {
                return(false);
            }

            this.TextHeight = res.Value;
            return(true);
        }
Exemplo n.º 6
0
        private PromptStatus GetDistance(string message1, string message2, out double length, bool allowEmpty)
        {
            Editor             ed   = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            PromptPointOptions opt1 = new PromptPointOptions(message1);

            opt1.AllowNone = allowEmpty;
            PromptPointResult res1 = ed.GetPoint(opt1);

            if (res1.Status == PromptStatus.OK)
            {
                PromptDistanceOptions opt2 = new PromptDistanceOptions(message2);
                opt2.AllowNone    = allowEmpty;
                opt2.BasePoint    = res1.Value;
                opt2.UseBasePoint = true;
                PromptDoubleResult res2 = ed.GetDistance(opt2);
                if (res2.Status == PromptStatus.OK)
                {
                    length = res2.Value;
                    return(PromptStatus.OK);
                }
            }

            length = 0;
            return(PromptStatus.Cancel);
        }
Exemplo n.º 7
0
        internal static double GetTwoPointLength(IntPtr handle)
        {
            double length = 0;

            var ed = AcAp.DocumentManager.MdiActiveDocument.Editor;

            using (var eduserinteraction = ed.StartUserInteraction(handle))
            {
                PromptDistanceOptions opt1 = new PromptDistanceOptions("量取:");

                opt1.AllowNegative = false;
                opt1.AllowZero     = false;
                opt1.AllowNone     = false;
                opt1.UseDashedLine = true;

                PromptDoubleResult res = ed.GetDistance(opt1);
                ed.WriteMessage("\n距离是..." + res.Value);
                if (res != null)
                {
                    length = res.Value;
                }
            }
            Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Focus();
            return(length);
        }
Exemplo n.º 8
0
        public void Cmd_RcGap()
        {
            var acCurDoc = Application.DocumentManager.MdiActiveDocument;
            var acCurDb  = acCurDoc.Database;
            var acCurEd  = acCurDoc.Editor;

            try
            {
                // Begin Transaction
                using (var acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    //Prompt To Select Solids to perform Boolean Operations On
                    var boolRes1 = acCurEd.GetFilteredSelection(Enums.DxfNameEnum._3Dsolid, false, null,
                                                                "\nSelect 3DSOLIDS to be subtracted from: ");

                    if (boolRes1.Length <= 0)
                    {
                        return;
                    }

                    //Prompt To Select Solids to perform Boolean Operations On
                    var boolRes2 = acCurEd.GetFilteredSelection(Enums.DxfNameEnum._3Dsolid, false, null,
                                                                "\nSelect 3DSOLIDS to be used as gap criteria: ");

                    if (boolRes2.Length <= 0)
                    {
                        return;
                    }

                    var prSelOpts = new PromptDistanceOptions("\nEnter gap distance: ")
                    {
                        AllowNone     = false,
                        AllowZero     = true,
                        AllowNegative = true,
                        DefaultValue  = SettingsUser.RcGapDepth
                    };

                    //Get the offset distance
                    var prSelRes = acCurEd.GetDistance(prSelOpts);

                    if (prSelRes.Status != PromptStatus.OK)
                    {
                        return;
                    }

                    SettingsUser.RcGapDepth = prSelRes.Value;

                    boolRes1.SolidGap(boolRes2, acCurDb, acTrans, false, SettingsUser.RcGapDepth);

                    // Commit Transaction
                    acTrans.Commit();
                }
            }
            catch (Exception e)
            {
                acCurEd.WriteMessage(e.Message);
            }
        }
Exemplo n.º 9
0
        Stream(ArrayList data, PromptDistanceOptions opts)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(PromptDistanceOptions)));

            data.Add(new Snoop.Data.Point3d("Base point", opts.BasePoint));
            data.Add(new Snoop.Data.Double("Default value", opts.DefaultValue));
            data.Add(new Snoop.Data.Bool("Only2d", opts.Only2d));
            data.Add(new Snoop.Data.Bool("Use base point", opts.UseBasePoint));
            data.Add(new Snoop.Data.Bool("Use dashed line", opts.UseDashedLine));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Prompts the user to input a distance.
        /// </summary>
        /// <param name="message">Message to display in the command line.</param>
        /// <returns>The distance input by the user.</returns>
        public static double GetDistance(string message, ref PromptStatus status)
        {
            PromptDistanceOptions options = new PromptDistanceOptions(System.Environment.NewLine + message);
            Editor command = Application.DocumentManager.MdiActiveDocument.Editor;

            PromptDoubleResult result = command.GetDistance(options);

            status = result.Status;

            return(result.Value);
        }
Exemplo n.º 11
0
        public void GetDistance()
        {
            var ed  = Application.DocumentManager.MdiActiveDocument.Editor;
            var pdo = new PromptDistanceOptions("Find distance, select first point:");
            var pdr = ed.GetDistance(pdo);

            if (pdr.Status != PromptStatus.OK)
            {
                ed.WriteMessage("Error!");
            }
            else
            {
                ed.WriteMessage("The distance is: " + pdr.Value.ToString());
            }
        }
Exemplo n.º 12
0
        public void GetDistance()
        {
            PromptDistanceOptions prDistOptions = new PromptDistanceOptions("计算两点距离,请选择第一个点:");
            PromptDoubleResult    prDistRes;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            prDistRes = ed.GetDistance(prDistOptions);
            if (prDistRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("选择错误!");
            }
            else
            {
                ed.WriteMessage("两点的距离为:" + prDistRes.Value.ToString());
            }
        }
Exemplo n.º 13
0
        private static double SelectStep(string prompt)
        {
            var editor  = Application.DocumentManager.MdiActiveDocument.Editor;
            var options = new PromptDistanceOptions(prompt)
            {
                AllowNegative = false,
                AllowZero     = false
            };
            var result = editor.GetDistance(options);

            if (result.Status != PromptStatus.OK)
            {
                throw new UserCancelledException();
            }
            return(result.Value);
        }
Exemplo n.º 14
0
        static public void getdistance()        // This method can have any name
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptDistanceOptions prDistOptions = new PromptDistanceOptions("Find distance, select first point:");
            PromptDoubleResult    prDistRes;

            prDistRes = ed.GetDistance(prDistOptions);
            if (prDistRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("Error\n");
            }
            else
            {
                ed.WriteMessage("The distance is: " + prDistRes.Value.ToString());
            }
        }
Exemplo n.º 15
0
        /// <summary> 分段的长度 </summary>
        private static double GetDistance(DocumentModifier docMdf)
        {
            var op = new PromptDistanceOptions("\n每个分段的长度")
            {
                AllowNegative       = false,
                AllowNone           = false,
                AllowZero           = false,
                AllowArbitraryInput = false
            };
            //
            var res = docMdf.acEditor.GetDistance(op);

            if (res.Status == PromptStatus.OK)
            {
                return(res.Value);
            }
            return(0);
        }
        public void MyCommand() // This method can have any name
        {
            Active.Editor.WriteMessage("\nThis will add a circle to the current space!");

            // Put your command code here
            PromptPointOptions ppo = new PromptPointOptions("Pick the centre of the circle");
            PromptPointResult  ppr = Active.Editor.GetPoint(ppo);

            if (ppr.Status != PromptStatus.OK)
            {
                return;
            }

            Point3d pt = ppr.Value;

            PromptDistanceOptions pdo = new PromptDistanceOptions("Pick radius")
            {
                UseBasePoint        = true,
                BasePoint           = pt,
                AllowArbitraryInput = true
            };

            PromptDoubleResult pdr = Active.Editor.GetDistance(pdo);

            if (pdr.Status != PromptStatus.OK)
            {
                return;
            }

            double dist = pdr.Value;

            using (Transaction tr = Active.Database.TransactionManager.StartTransaction())
            {
                Circle circle = new Circle(pt, Vector3d.ZAxis, dist);

                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(Active.Database.CurrentSpaceId, OpenMode.ForWrite);

                btr.AppendEntity(circle);
                tr.AddNewlyCreatedDBObject(circle, true);

                tr.Commit();
            }
        }
Exemplo n.º 17
0
 /// <summary>Получения расстояния между двумя указанными точками в виде double</summary>
 /// <param name="showError">Отображать окно ошибки (Exception) в случае возникновения</param>
 /// <returns>Полученное расстояние или double.NaN в случае отмены или ошибки</returns>
 public static double GetLenByTwoPoint(bool showError = false)
 {
     try
     {
         using (AcApp.DocumentManager.MdiActiveDocument.LockDocument())
         {
             var ed  = AcApp.DocumentManager.MdiActiveDocument.Editor;
             var pdo = new PromptDistanceOptions($"\n{Language.GetItem(LangItem, "msg10")}");
             var pdr = ed.GetDistance(pdo);
             return(pdr.Status != PromptStatus.OK ? double.NaN : pdr.Value);
         }
     }
     catch (Exception ex)
     {
         if (showError)
         {
             ExceptionBox.Show(ex);
         }
         return(double.NaN);
     }
 }
Exemplo n.º 18
0
        public double pickDistDragonBonetoLine()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptDistanceOptions opt1 = new PromptDistanceOptions("量取:");

            opt1.AllowNegative = false;
            opt1.AllowZero     = false;
            opt1.AllowNone     = false;
            opt1.UseDashedLine = true;

            PromptDoubleResult res = ed.GetDistance(opt1);

            if (res == null)
            {
                return(0);
            }
            else
            {
                return(res.Value);
            }
        }
Exemplo n.º 19
0
        double GetScale(double baseReferenceDimension)
        {
            string prompt             = string.Format("\nЗадайте или укажите длину основной надписи (то, что должно быть {0} мм):", baseReferenceDimension);
            PromptDistanceOptions pdo =
                new PromptDistanceOptions(prompt);

            pdo.AllowZero     = false;
            pdo.AllowNegative = false;
            pdo.Only2d        = true;
            pdo.UseDashedLine = true;
            pdo.DefaultValue  = baseReferenceDimension;
            PromptDoubleResult res = ed.GetDistance(pdo);

            if (res.Status != PromptStatus.OK)
            {
                return(0.0);
            }
            double scale = res.Value / baseReferenceDimension;

            ed.WriteMessage("\nМасштабный коэффициент: {0}", scale);
            return(scale);
        }
        public void MyCommand()
        {
            Active.Editor.WriteMessage("\nThis will add a circle to the current space!");

            // Put your command code here
            PromptPointOptions ppo = new PromptPointOptions("Pick the centre of the circle");
            PromptPointResult ppr = Active.Editor.GetPoint(ppo);

            if (ppr.Status != PromptStatus.OK)
                return;

            Point3d pt = ppr.Value;

            PromptDistanceOptions pdo = new PromptDistanceOptions("Pick radius") {
                UseBasePoint = true,
                BasePoint = pt,
                AllowArbitraryInput = true
            };

            PromptDoubleResult pdr = Active.Editor.GetDistance(pdo);

            if (pdr.Status != PromptStatus.OK)
                return;

            double dist = pdr.Value;

            using (Transaction tr = Active.Database.TransactionManager.StartTransaction())
            {
                Circle circle = new Circle(pt, Vector3d.ZAxis, dist);

                BlockTableRecord btr = (BlockTableRecord) tr.GetObject(Active.Database.CurrentSpaceId, OpenMode.ForWrite);

                btr.AppendEntity(circle);
                tr.AddNewlyCreatedDBObject(circle, true);

                tr.Commit();
            }
        }
Exemplo n.º 21
0
        public void RunDist()
        {
            Document acDoc = acApp.DocumentManager.MdiActiveDocument;
            Editor   acEd  = acDoc.Editor;

            PromptDistanceOptions pdo = new PromptDistanceOptions("\nSelect first point:");

            int prec = (Int16)acApp.GetSystemVariable("DIMDEC");
            // List of the points selected and our result object

            List <double>      pts = new List <double>();
            PromptDoubleResult dist;

            // The selection loop
            pdo.AllowNone = true;
            do
            {
                dist = acEd.GetDistance(pdo);
                pts.Add(dist.Value);
            }while (dist.Status == PromptStatus.OK);

            if (dist.Status == PromptStatus.None)
            {
                double totDist = 0;
                if (pts.Count >= 1)
                {
                    foreach (double item in pts)
                    {
                        totDist = totDist + item;
                    }
                }
                string arch_dist = Converter.DistanceToString(totDist, DistanceUnitFormat.Architectural, prec);
                string dec_dist  = Converter.DistanceToString(totDist, DistanceUnitFormat.Decimal, prec);

                MessageBox.Show("Total distance is: " + arch_dist + " (" + dec_dist + "\")");
            }
        }
Exemplo n.º 22
0
        public void DrawCircleFunction()
        {
            //画个圆
            Editor             ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptPointOptions getPointOptions = new PromptPointOptions("Pick Center Point : ");
            PromptPointResult  getPointResult  = ed.GetPoint(getPointOptions);

            if ((getPointResult.Status == PromptStatus.OK))
            {
                PromptDistanceOptions getRadiusOptions = new PromptDistanceOptions("Pick Radius : ");
                getRadiusOptions.BasePoint    = getPointResult.Value;
                getRadiusOptions.UseBasePoint = true;
                PromptDoubleResult getRadiusResult = ed.GetDistance(getRadiusOptions);
                if ((getRadiusResult.Status == PromptStatus.OK))
                {
                    Database    dwg   = ed.Document.Database;
                    Transaction trans = dwg.TransactionManager.StartTransaction();
                    try
                    {
                        Circle           circle = new Circle(getPointResult.Value, Vector3d.ZAxis, getRadiusResult.Value);
                        BlockTableRecord btr    = (BlockTableRecord)trans.GetObject(dwg.CurrentSpaceId, OpenMode.ForWrite);
                        btr.AppendEntity(circle);
                        trans.AddNewlyCreatedDBObject(circle, true);
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        ed.WriteMessage("problem due to " + ex.Message);
                    }
                    finally
                    {
                        trans.Dispose();
                    }
                }
            }
        }
Exemplo n.º 23
0
        public void AddAnEnt()
        {
            // 2. Declare an Editor variable named ed. Instantiate it using the Editor property
            // of the Application.DocumentManager.MdiActiveDocument.Editor
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            // 3. Declare a PromptKeywordOptions variable and instantiate it by creating
            // a new PromptKeywordOptions. Use a string similar to the following for the
            // messageAndKeywords string.
            // "Which entity do you want to create? [Circle/Block] : ", "Circle Block"
            PromptKeywordOptions getWhichEntityOptions = new PromptKeywordOptions("Which entity do you want to create? [Circle/Block] : ", "Circle Block");

            // 4. Declare a PromptResult. Use the GetKeywords method of the Editor variable
            // created in step 1. Pass in the PromptKeywordOptions created in step 2. Instantiate
            // the PromptResult by making it equal to the return value of the GetKeywords method.
            PromptResult getWhichEntityResult = ed.GetKeywords(getWhichEntityOptions);

            // 5. Add an if statement that tests the Status of the PromptResult created in step 4.
            // Use the PromptStatus enum for the test. (see if it is equal to PromptStatus.OK)
            // Note: Move the closing curly brace after step 21.
            if (getWhichEntityResult.Status == PromptStatus.OK)
            {
                // 6. PromptStatus was ok. Now use a switch statement. For the switch argument
                // use the StringResult property of the PromptResult variable used above
                // Note: Move the closing curly brace after step 21.
                // (Above the closing curly brace for the if statement in step 5)
                switch (getWhichEntityResult.StringResult)
                {
                // 7. Use "Circle" for the case. (if the StringResult is "Circle") Below
                // we will use "Block" for the case. (jump ahead to step 15 to add the break
                // to resolve the "Control cannot fall through... message")
                case "Circle":

                    // 8. We want to ask the user for the center of the circle. Declare
                    // a PromptPointOptions variable and instatiate it by making it equal
                    // to a new PromptPointOptions. Use "Pick Center Point : " for message parameter
                    PromptPointOptions getPointOptions = new PromptPointOptions("Pick Center Point : ");

                    // 9. Declare a PromptPointResult variable. Use the GetPoint method of
                    // the Editor created in step 2. (Pass in the PromptPointOptions created
                    // in step 8). Instantiate the PromptPointResult by making it equal to the
                    // return of the GetPoint method.
                    PromptPointResult getPointResult = ed.GetPoint(getPointOptions);

                    // 10. Add an if statement that tests the Status of the PromptPointResult
                    // created in step 9. Use the PromptStatus enum for the test. (make sure it is OK)
                    // Note: Move the closing curly brace right before step 15.
                    if ((getPointResult.Status == PromptStatus.OK))
                    {
                        // 11. Now we want to ask the user for the radius of the circle. Declare
                        // a PromptDistanceOptions variable. Instatiate it by making it equal
                        // to a new PromptDistanceOptions. Use "Pick Radius : " for the message parameter.
                        PromptDistanceOptions getRadiusOptions = new PromptDistanceOptions("Pick Radius : ");

                        // 12. We want to use the point selected in step 9 as the
                        // base point for the GetDistance call coming up. To do this use
                        // the BasePoint property of the PromptDistanceOptions variable created
                        // in the previous step. Make the BasePoint equal to the Value property
                        // of the PromptPointResult created in step 9.
                        getRadiusOptions.BasePoint = getPointResult.Value;


                        // 13. We need to tell the input mechanism to actually use the basepoint.
                        // Do this by setting the UseBasePoint property of the
                        // PromptDistanceOptions created in step 11 to True.
                        getRadiusOptions.UseBasePoint = true;

                        // 14. Get the radius for the circle. Declare a PromptDoubleResult variable.
                        // Instantiate it using the GetDistance method of the Editor variable created
                        // in step 2. Pass in the PromptDistanceOptions created in step 11 and
                        // modified in the previous steps.
                        PromptDoubleResult getRadiusResult = ed.GetDistance(getRadiusOptions);
                    }
                    // 15. Add break to mark the end of the code for the "Circle" case.
                    break;

                // 16. Add the Case for the "Block" (jump ahead to step 20 to add the break
                // to resolve the "Control cannot fall through... message")
                case "Block":

                    // 17. Now we want to ask the user for the name of the block. Delcare
                    // a PromptStringOptions varable and instatiate it by creating a new
                    // PromptStringOptions. Use "Enter name of the Block to create : " for
                    // the message parameter.
                    PromptStringOptions blockNameOptions = new PromptStringOptions("Enter name of the Block to create : ");

                    // 18. No spaces are allowed in a blockname so disable it. Do this by setting
                    // the AllowSpaces property of the PromptStringOptions created in step 15
                    // to false.
                    blockNameOptions.AllowSpaces = false;

                    // 19. Get the name the user entered. Declare a PromptResult variable
                    // and instantiate it using the GetString method of the Editor object
                    // created in step 2. Pass in the PromptStringOptions created in step 17.
                    PromptResult blockNameResult = ed.GetString(blockNameOptions);

                    // 20. Add break to mark the end of the code for the "Block" case.
                    break;

                    // 21. Build the project. Place a break point. Use the NETLOAD command
                    // and run the AddAnEnt command. Step through the code and fix any errors.
                    // Remember to run the command and test the code for both circle and block.
                }
            }
        }
Exemplo n.º 24
0
        public void AddAnEnt()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;

            // Declare a PromptKeywordOptions variable and instantiate it by creating
            // a new PromptKeywordOptions. Use a string similar to the following for the
            // messageAndKeywords string.
            // "Which entity do you want to create? [Circle/Block] : ", "Circle Block"
            PromptKeywordOptions poEntity = new PromptKeywordOptions(
                "Which entity do you want to create? [Circle/Block] : ",
                "Circle Block");    // String with the options separated with a space

            // Instantiate the PromptResult by making it equal to the return value of the GetKeywords method.
            PromptResult prEntity = ed.GetKeywords(poEntity);

            if (prEntity.Status == PromptStatus.OK)
            {
                switch (prEntity.StringResult)
                {
                case "Circle":
                    // Ask for a point, which will be the center of the circle
                    PromptPointOptions poCenterPoint = new PromptPointOptions("Pick Center Point: ");

                    // Pass the prompt to the editor and get the resulting point
                    PromptPointResult prCenterPoint = ed.GetPoint(poCenterPoint);

                    if (prCenterPoint.Status == PromptStatus.OK)
                    {
                        // Ask for a distance (radius)
                        PromptDistanceOptions poRadius = new PromptDistanceOptions("Pick Radius: ");

                        // Make the point selected earlier the base point of the distance prompt
                        poRadius.BasePoint = prCenterPoint.Value;
                        // Tell the prompt to actually use the base point
                        poRadius.UseBasePoint = true;

                        // Get the distance
                        PromptDoubleResult prRadius = ed.GetDistance(poRadius);

                        if (prRadius.Status == PromptStatus.OK)
                        {
                            // Add the circle to the DWG
                            Database dwg = ed.Document.Database;

                            // Start a transaction (as you would with a database)
                            Transaction trans = dwg.TransactionManager.StartTransaction();

                            try
                            {
                                // Create the circle.
                                // The second parameter is the normal (perpendicular) vector.
                                Circle circle = new Circle(prCenterPoint.Value, Vector3d.ZAxis, prRadius.Value);

                                // Create a new block
                                // A BlockTableRecord is similar to using the "BLOCK" command on AutoCAD.
                                // When we add a record to the current space, we ARE NOT adding it to the "Blocks" utility.
                                BlockTableRecord curSpace = (BlockTableRecord)trans.GetObject(dwg.CurrentSpaceId, OpenMode.ForWrite);

                                // Add the circle to the new block
                                curSpace.AppendEntity(circle);

                                // Tell the transaction about the new object (entity)
                                trans.AddNewlyCreatedDBObject(circle, true);

                                // Commit
                                trans.Commit();
                            }
                            catch (Autodesk.AutoCAD.Runtime.Exception ex)
                            {
                                // Write exception on the AutoCAD command line
                                ed.WriteMessage("EXCEPTION: " + ex.Message);
                            }
                            finally
                            {
                                // Dispose of the transaction (whether an error has occurred or not)
                                trans.Dispose();
                            }
                        }
                    }
                    break;

                case "Block":
                    // Add a prompt to name the block
                    PromptStringOptions poBlockName = new PromptStringOptions("Enter the name of the Block to create: ");

                    // Don't allow spaces, as a block's name can't have spaces
                    poBlockName.AllowSpaces = false;

                    // Get the name
                    PromptResult prBlockName = ed.GetString(poBlockName);

                    if (prBlockName.Status == PromptStatus.OK)
                    {
                        // Add the block to the dwg
                        Database    dwg   = ed.Document.Database;
                        Transaction trans = dwg.TransactionManager.StartTransaction();

                        try
                        {
                            // Create new BTR from scratch
                            BlockTableRecord btr = new BlockTableRecord();

                            // Set name to the prompt result
                            btr.Name = prBlockName.StringResult;

                            // First verify if a block with the same name already exists in the Block Table
                            // We open the Block Table in read, because we won't be changing it right now
                            BlockTable blockTable = (BlockTable)trans.GetObject(dwg.BlockTableId, OpenMode.ForRead);

                            if (blockTable.Has(prBlockName.StringResult))
                            {
                                throw new Autodesk.AutoCAD.Runtime.Exception(
                                          ErrorStatus.InvalidInput,
                                          "Cannot create block. Block with same name already exists.");
                            }
                            else
                            {
                                // Update OpenMode to ForWrite
                                blockTable.UpgradeOpen();

                                // Add to the block table (this will make the block available for the user in the "Block" utility)
                                blockTable.Add(btr);

                                // Tell the transaction about the new object, so that it auto-closes it
                                trans.AddNewlyCreatedDBObject(btr, true);

                                // We defined that the block consists of two circles, so we'll add them
                                Circle circle1 = new Circle(new Point3d(0, 0, 0), Vector3d.ZAxis, 10);
                                Circle circle2 = new Circle(new Point3d(20, 10, 0), Vector3d.ZAxis, 10);

                                btr.AppendEntity(circle1);
                                btr.AppendEntity(circle2);

                                trans.AddNewlyCreatedDBObject(circle1, true);
                                trans.AddNewlyCreatedDBObject(circle2, true);

                                // Prompt for insertion point
                                PromptPointOptions poPoint = new PromptPointOptions("Pick insertion point of BlockRef : ");
                                PromptPointResult  prPoint = ed.GetPoint(poPoint);

                                if (prPoint.Status != PromptStatus.OK)
                                {
                                    // If point is not valid, return

                                    trans.Dispose();
                                    return;
                                }

                                // The BlockTableRecord is the BLOCK (i.e., a template)
                                // The BlockReference is the result of using INSERT (i.e., an instance of a block)
                                BlockReference blockRef = new BlockReference(prPoint.Value, btr.ObjectId);

                                // Add to the current space
                                BlockTableRecord curSpace = (BlockTableRecord)trans.GetObject(dwg.CurrentSpaceId, OpenMode.ForWrite);
                                curSpace.AppendEntity(blockRef);

                                // Finish transaction
                                trans.AddNewlyCreatedDBObject(blockRef, true);
                                trans.Commit();
                            }
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception ex)
                        {
                            ed.WriteMessage("EXCEPTION: " + ex.Message);
                        }
                        finally
                        {
                            trans.Dispose();
                        }
                    }
                    break;
                }
            }
        }
Exemplo n.º 25
0
        public void RunDist()
        {
            Document acDoc = acApp.DocumentManager.MdiActiveDocument;
            Editor acEd = acDoc.Editor;

            PromptDistanceOptions pdo = new PromptDistanceOptions("\nSelect first point:");

            int prec = (Int16)acApp.GetSystemVariable("DIMDEC");
            // List of the points selected and our result object

            List<double> pts = new List<double>();
            PromptDoubleResult dist;

            // The selection loop
            pdo.AllowNone = true;
            do
            {
                dist = acEd.GetDistance(pdo);
                pts.Add(dist.Value);
            }
            while (dist.Status == PromptStatus.OK);

            if (dist.Status == PromptStatus.None)
            {
                double totDist = 0;
                if (pts.Count >= 1)
                {
                    foreach (double item in pts)
                    {
                        totDist = totDist + item;
                    }
                }
                string arch_dist = Converter.DistanceToString(totDist, DistanceUnitFormat.Architectural, prec);
                string dec_dist = Converter.DistanceToString(totDist, DistanceUnitFormat.Decimal, prec);

                MessageBox.Show("Total distance is: " + arch_dist + " (" + dec_dist + "\")");

            }
        }
Exemplo n.º 26
0
        //public static IAcedCmdArg Argument(PromptAngleOptions options)
        //{
        //    return new PromptAngleArgument(options);
        //}

        public static IAcedCmdArg Argument(PromptDistanceOptions options)
        {
            return new PromptDistanceArgument(options);
        }
Exemplo n.º 27
0
        public void RunQuery()
        {
            // ��ȡ��ͼӦ�ó������͹��̶���
            MapApplication mapApi = HostMapApplicationServices.Application;
            ProjectModel proj = mapApi.ActiveProject;
            DrawingSet drawingSet = proj.DrawingSet;

               //������ͼ�μ��߽�
            proj.DrawingSet.ZoomExtents();

              //ʹ��LocationCondition������һ����ѯ����
            LocationCondition qryCondition  =   new LocationCondition ();
            qryCondition.LocationType  = LocationType.LocationInside ;
            qryCondition.JoinOperator = JoinOperator .OperatorAnd ;
               // ����Բ�߽�
            CircleBoundary boundary = null;

            PromptPointResult pointRes = Utility.AcadEditor.GetPoint("\nѡ��ԭ��: ");
            if (pointRes.Status == PromptStatus.OK)
            {
                Point3d point = pointRes.Value;
                PromptDistanceOptions distOptions = new PromptDistanceOptions("\nѡ��뾶: ");
                distOptions.BasePoint = point;
                distOptions.UseBasePoint = true;
                distOptions.DefaultValue = 0.0;
                PromptDoubleResult doubleRes = Utility.AcadEditor.GetDistance(distOptions);
                if (doubleRes.Status == PromptStatus.OK)
                {
                    double rad = doubleRes.Value;
                    boundary = new CircleBoundary(new Point3d(point.X, point.Y, 0.0), rad);
                }
            }
            //
            qryCondition.Boundary = boundary;
            //����һ��������֧
             QueryBranch qryBranch  =  QueryBranch.Create ();
            qryBranch.JoinOperator = JoinOperator.OperatorAnd;
            qryBranch.AppendOperand(qryCondition);
             ////ʹ��PropertyCondition������һ�����Բ�ѯ����(LWPOLYLINE)
            PropertyCondition propCondition= new PropertyCondition();
             //JoinOperator.OperatorAnd, PropertyType.EntityType, ConditionOperator.ConditionEqual, "LWPOLYLINE";
            propCondition.JoinOperator = JoinOperator.OperatorAnd ;
            propCondition.PropertyType  = PropertyType.EntityType ;
            propCondition.ConditionOperator = ConditionOperator.ConditionEqual ;
            propCondition.Value = "LWPOLYLINE";

            //	ͨ��QueryBranch�Ĺ��캯��������һ��������ѯ��֧��
            QueryBranch  subBranch  = new QueryBranch(JoinOperator.OperatorAnd);
             //	����һ�����в�ѯ�����ͷ�֧�IJ�ѯ����
            subBranch.AppendOperand(propCondition);
            qryBranch.AppendOperand(subBranch);
            //  ����һ����ѯ��
            QueryModel qryModel  = proj.CreateQuery (true);
            //	��ɲ�ѯ�Ķ��塣
            qryModel.Define (qryBranch);
            //���û���ģʽ
            qryModel.Mode = QueryType.QueryDraw;
            //�����ѯ
            qryModel.Define(qryBranch);
            //ִ�в�ѯ��
            qryModel.Run();

            Utility.AcadEditor.WriteMessage("\n ��ɲ�ѯ ��");
        }
Exemplo n.º 28
0
        //public static IAcedCmdArg Argument(PromptAngleOptions options)
        //{
        //    return new PromptAngleArgument(options);
        //}

        public static IAcedCmdArg Argument(PromptDistanceOptions options)
        {
            return(new PromptDistanceArgument(options));
        }
Exemplo n.º 29
0
        public void AddAnEnt()
        {
            // get the editor object so we can carry out some input
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            // first decide what type of entity we want to create
            PromptKeywordOptions getWhichEntityOptions = new PromptKeywordOptions("Which entity do you want to create? [Circle/Block] : ", "Circle Block");

            // now input it
            PromptResult getWhichEntityResult = ed.GetKeywords(getWhichEntityOptions);

            // if ok
            if ((getWhichEntityResult.Status == PromptStatus.OK))
            {
                // test which one is required
                switch (getWhichEntityResult.StringResult)
                {
                case "Circle":
                    // pick the center point of the circle
                    PromptPointOptions getPointOptions = new PromptPointOptions("Pick Center Point : ");
                    PromptPointResult  getPointResult  = ed.GetPoint(getPointOptions);

                    // if ok
                    if ((getPointResult.Status == PromptStatus.OK))
                    {
                        // the get the radius
                        PromptDistanceOptions getRadiusOptions = new PromptDistanceOptions("Pick Radius : ");

                        // set the start point to the center (the point we just picked)
                        getRadiusOptions.BasePoint = getPointResult.Value;

                        // now tell the input mechanism to actually use the basepoint!
                        getRadiusOptions.UseBasePoint = true;

                        // now get the radius
                        PromptDoubleResult getRadiusResult = ed.GetDistance(getRadiusOptions);

                        // if all is ok
                        if ((getRadiusResult.Status == PromptStatus.OK))
                        {
                            // need to add the circle to the current space
                            //get the current working database
                            Database dwg = ed.Document.Database;

                            // now start a transaction
                            Transaction trans = dwg.TransactionManager.StartTransaction();
                            try
                            {
                                //create a new circle
                                Circle circle = new Circle(getPointResult.Value, Vector3d.ZAxis, getRadiusResult.Value);

                                // open the current space (block table record) for write
                                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(dwg.CurrentSpaceId, OpenMode.ForWrite);

                                // now the circle to the current space, model space more than likely
                                btr.AppendEntity(circle);

                                // tell the transaction about the new circle so that it can autoclose it
                                trans.AddNewlyCreatedDBObject(circle, true);

                                // now commit the transaction
                                trans.Commit();
                            }
                            catch (Exception ex)
                            {
                                // ok so we have an exception
                                ed.WriteMessage("problem due to " + ex.Message);
                            }
                            finally
                            {
                                // all done, whether an error on not - dispose the transaction.
                                trans.Dispose();
                            }
                        }
                    }
                    break;

                case "Block":

                    // enter the name of the block
                    PromptStringOptions blockNameOptions = new PromptStringOptions("Enter name of the Block to create : ");
                    // no spaces are allowed in a blockname so disable it
                    blockNameOptions.AllowSpaces = false;
                    // get the name
                    PromptResult blockNameResult = ed.GetString(blockNameOptions);
                    // if ok
                    if ((blockNameResult.Status == PromptStatus.OK))
                    {
                        // lets create the block definition
                        // get the current drawing
                        Database dwg = ed.Document.Database;

                        // now start a transaction
                        Transaction trans = (Transaction)dwg.TransactionManager.StartTransaction();
                        try
                        {
                            // create the new block definition
                            BlockTableRecord newBlockDef = new BlockTableRecord();

                            // name the block definition
                            newBlockDef.Name = blockNameResult.StringResult;

                            // now add the new block defintion to the block table
                            // open the blok table for read so we can check to see if the name already exists
                            BlockTable blockTable = (BlockTable)trans.GetObject(dwg.BlockTableId, OpenMode.ForRead);

                            // check to see if the block already exists
                            if ((blockTable.Has(blockNameResult.StringResult) == false))
                            {
                                // if it's not there, then we are ok to add it
                                // but first we need to upgrade the open to write
                                blockTable.UpgradeOpen();

                                // Add the BlockTableRecord to the blockTable
                                blockTable.Add(newBlockDef);

                                // tell the transaction manager about the new object so that the transaction will autoclose it
                                trans.AddNewlyCreatedDBObject(newBlockDef, true);

                                // now add some objects to the block definition
                                Circle circle1 = new Circle(new Point3d(0, 0, 0), Vector3d.ZAxis, 10);
                                newBlockDef.AppendEntity(circle1);

                                Circle circle2 = new Circle(new Point3d(20, 10, 0), Vector3d.ZAxis, 10);
                                newBlockDef.AppendEntity(circle2);

                                // tell the transaction manager about the new objects
                                //so that the transaction will autoclose it
                                trans.AddNewlyCreatedDBObject(circle1, true);
                                trans.AddNewlyCreatedDBObject(circle2, true);

                                // now set where it should appear in the current space
                                PromptPointOptions blockRefPointOptions = new PromptPointOptions("Pick insertion point of BlockRef : ");
                                PromptPointResult  blockRefPointResult  = ed.GetPoint(blockRefPointOptions);

                                // check to see if everything was ok - if not
                                if ((blockRefPointResult.Status != PromptStatus.OK))
                                {
                                    //dispose of everything that we have done so far and return
                                    trans.Dispose();
                                    return;
                                }

                                // now we have the block defintion in place and the position we need to create the reference to it
                                BlockReference blockRef = new BlockReference(blockRefPointResult.Value, newBlockDef.ObjectId);

                                // otherwise add it to the current space, first open the current space for write
                                BlockTableRecord curSpace = (BlockTableRecord)trans.GetObject(dwg.CurrentSpaceId, OpenMode.ForWrite);

                                // now add the block reference to it
                                curSpace.AppendEntity(blockRef);

                                // remember to tell the transaction about the new block reference so that the transaction can autoclose it
                                trans.AddNewlyCreatedDBObject(blockRef, true);

                                // all ok, commit it
                                trans.Commit();
                            }
                        }
                        catch (Exception ex)
                        {
                            // a problem occured, lets print it
                            ed.WriteMessage("a problem occured because " + ex.Message);
                        }
                        finally
                        {
                            // whatever happens we must dispose the transaction
                            trans.Dispose();
                        }
                    }
                    break;
                }
            }
        }
Exemplo n.º 30
0
            public bool askForDistances(AC_Line acline)
            {
                circleCenter = acline.StartPoint;
                previewCircle = new AC_Circle();
                previewCircle.addToDrawing();
                removeSnap noSnap = new removeSnap(previewCircle.ObjectId);
                ObjectOverrule.AddOverrule(RXObject.GetClass(typeof(Entity)), noSnap, true);

                drawPreviewCircle = true;
                PromptDistanceOptions DistOption = new PromptDistanceOptions("Triangulation Distance");
                DistOption.BasePoint = circleCenter;
                DistOption.UseBasePoint = true;

                PromptDoubleResult triang1 = tr.AC_Doc.Editor.GetDistance(DistOption);
                if (triang1.Status == PromptStatus.OK)
                {
                    if (triang1.Value != 0)
                    {
                        tr.AC_Doc.Editor.WriteMessage(triang1.Value.ToString() + "\n");
                        circleCenter = acline.EndPoint;
                        DistOption.BasePoint = circleCenter;
                        radius.Add(triang1.Value);
                        PromptDoubleResult triang2 = tr.AC_Doc.Editor.GetDistance(DistOption);
                        if (triang2.Status == PromptStatus.OK)
                        {
                            tr.AC_Doc.Editor.WriteMessage(triang2.Value.ToString() + "\n");
                            radius.Add(triang2.Value);
                            previewCircle.Visible = false;
                            drawPreviewCircle = false;
                            return true;
                        }
                        else
                        {
                            tr.AC_Doc.Editor.PointMonitor -= Editor_PointMonitor;
                            ObjectOverrule.RemoveOverrule(RXObject.GetClass(typeof(Entity)), noSnap);
                            previewCircle.Erase(true);
                            return false;
                        }
                    }
                    else
                    {
                        tr.AC_Doc.Editor.PointMonitor -= Editor_PointMonitor;
                        tr.AC_Doc.Editor.WriteMessage("Cannot Calculate Triangulation \n");
                        ObjectOverrule.RemoveOverrule(RXObject.GetClass(typeof(Entity)), noSnap);
                        previewCircle.Erase(true);
                        return false;
                    }
                }
                else
                {
                    tr.AC_Doc.Editor.PointMonitor -= Editor_PointMonitor;
                    ObjectOverrule.RemoveOverrule(RXObject.GetClass(typeof(Entity)), noSnap);
                    previewCircle.Visible = false;
                    drawPreviewCircle = false;
                    return false;
                }
            }
Exemplo n.º 31
0
        public void Cmd_RCChop()
        {
            var acCurDoc = Application.DocumentManager.MdiActiveDocument;
            var acCurDb  = acCurDoc.Database;
            var acCurEd  = acCurDoc.Editor;

            //Call user to select a face
            var userSel = acCurEd.SelectSubentity(SubentityType.Face, "\nSelect a FACE to use as chopping criteria: ");

            if (userSel == null)
            {
                return;
            }
            if (userSel.Item1 == ObjectId.Null)
            {
                return;
            }
            if (userSel.Item2 == SubentityId.Null)
            {
                return;
            }

            var prSelOpts = new PromptDistanceOptions("\nEnter chop distance: ")
            {
                AllowNone     = false,
                AllowZero     = false,
                AllowNegative = false,
                DefaultValue  = SettingsUser.RcChopDepth
            };

            //Get the offset distance
            var prSelRes = acCurEd.GetDistance(prSelOpts);


            if (prSelRes.Status != PromptStatus.OK)
            {
                return;
            }

            SettingsUser.RcChopDepth = prSelRes.Value;

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (SettingsUser.RcChopDepth == 0)
            {
                return;
            }
            var     sList    = new List <Surface>();
            Entity  faceEnt  = null;
            Surface tempSurf = null;

            try
            {
                //Open a transaction
                using (var acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    var acSol = acTrans.GetObject(userSel.Item1, OpenMode.ForWrite) as Solid3d;
                    if (acSol == null)
                    {
                        acTrans.Abort();
                        return;
                    }

                    faceEnt = acSol.GetSubentity(userSel.Item2);

                    using (tempSurf = faceEnt.CreateSurfaceFromFace(acCurDb, acTrans, false))
                    {
                        var canSlice   = true;
                        var multiplier = 1;

                        using (var pWorker = new ProgressAgent("Testing Chops: ", 100))
                        {
                            while (canSlice)
                            {
                                if (!pWorker.Progress())
                                {
                                    break;
                                }

                                var sliceSurf =
                                    Surface.CreateOffsetSurface(tempSurf,
                                                                -SettingsUser.RcChopDepth * multiplier) as Surface;

                                if (sliceSurf == null)
                                {
                                    break;
                                }

                                canSlice = CanSlice(acSol, sliceSurf);

                                if (!canSlice)
                                {
                                    sliceSurf.Dispose();
                                    continue;
                                }

                                sList.Add(sliceSurf);

                                multiplier++;
                            }

                            if (sList.Count > 0)
                            {
                                pWorker.SetTotalOperations(sList.Count);
                                pWorker.Reset("Chopping Solid: ");

                                foreach (var su in sList)
                                {
                                    if (!pWorker.Progress())
                                    {
                                        acTrans.Abort();
                                        break;
                                    }

                                    var obj = acSol.Slice(su, true);
                                    obj.SetPropertiesFrom(acSol);
                                    acCurDb.AppendEntity(obj);
                                }
                            }
                            else
                            {
                                acCurEd.WriteMessage("\nNo Chopping Criteria found!");
                            }
                        }
                    }

                    acTrans.Commit();
                }
            }
            catch (Exception e)
            {
                acCurEd.WriteMessage(e.Message);
            }
            finally
            {
                foreach (var suf in sList)
                {
                    suf.Dispose();
                }

                if (faceEnt != null)
                {
                    faceEnt.Dispose();
                }
                if (tempSurf != null)
                {
                    tempSurf.Dispose();
                }
            }
        }
Exemplo n.º 32
0
        public void Cmd_EdgeBand()
        {
            if (!LicensingAgent.Check())
            {
                return;
            }
            var acCurDoc = Application.DocumentManager.MdiActiveDocument;
            var acCurDb  = acCurDoc.Database;
            var acCurEd  = acCurDoc.Editor;

            //Call user to select a face
            var userSel = acCurEd.SelectSubentity(SubentityType.Face, "\nSelect a FACE to use as cutting criteria: ");

            if (userSel == null)
            {
                return;
            }
            if (userSel.Item1 == ObjectId.Null)
            {
                return;
            }
            if (userSel.Item2 == SubentityId.Null)
            {
                return;
            }

            var insetOpts = new PromptDistanceOptions("\nEnter edge banding thickness: ")
            {
                AllowNone     = false,
                AllowZero     = false,
                AllowNegative = false,
                DefaultValue  = SettingsUser.EdgeBandThickness
            };

            //Get the offset distance
            var insetRes = acCurEd.GetDistance(insetOpts);

            if (insetRes.Status != PromptStatus.OK)
            {
                return;
            }

            SettingsUser.EdgeBandThickness = insetRes.Value;


            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (SettingsUser.EdgeBandThickness <= 0)
            {
                return;
            }

            Entity  faceEnt  = null;
            Surface tempSurf = null;
            Solid3d tempSol  = null;

            try
            {
                //Open a transaction
                using (var acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    var acSol = acTrans.GetObject(userSel.Item1, OpenMode.ForWrite) as Solid3d;

                    if (acSol == null)
                    {
                        acTrans.Abort();
                        return;
                    }

                    var innerSol = acSol.Clone() as Solid3d;

                    if (innerSol == null)
                    {
                        acTrans.Abort();
                        return;
                    }

                    acSol.Layer = acCurDb.GetCLayer(acTrans);
                    acCurDb.AppendEntity(innerSol);

                    faceEnt = acSol.GetSubentity(userSel.Item2);

                    var eInfo    = new EntInfo(acSol, acCurDb, acTrans);
                    var largestM = eInfo.GetLargestMeasurement();

                    using (tempSurf = faceEnt.CreateSurfaceFromFace(acCurDb, acTrans, false))
                    {
                        var thickness = largestM + SettingsUser.EdgeBandThickness;

                        using (tempSol = tempSurf.Thicken(-(thickness * 2), true))
                        {
                            tempSol.OffsetBody(-SettingsUser.EdgeBandThickness);

                            var cutSol = tempSol.Slice(tempSurf, true);
                            cutSol.Dispose();

                            acSol.BooleanOperation(BooleanOperationType.BoolSubtract, tempSol);
                        }
                    }

                    var acBool1 = new[] { innerSol.ObjectId };
                    var acBool2 = new[] { acSol.ObjectId };

                    acBool1.SolidSubtrahend(acBool2, acCurDb, acTrans, false);

                    acTrans.Commit();
                }
            }
            catch (Exception e)
            {
                acCurEd.WriteMessage(e.Message);
                MailAgent.Report(e.Message);
            }
            finally
            {
                if (faceEnt != null)
                {
                    faceEnt.Dispose();
                }
                if (tempSurf != null)
                {
                    tempSurf.Dispose();
                }
                if (tempSol != null)
                {
                    tempSol.Dispose();
                }
            }
        }
Exemplo n.º 33
0
        public void DistanceTest()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptDistanceOptions opt1 = new PromptDistanceOptions("Enter the radius of the circle");

            opt1.AllowNegative = false;
            opt1.AllowZero = false;
            opt1.AllowNone = false;
            opt1.UseDashedLine = true;

            PromptDoubleResult res = ed.GetDistance(opt1);

            if(res.Status == PromptStatus.OK)
            {
                Point3d center = new Point3d(9.0, 3.0, 0.0);
                Vector3d normal = new Vector3d(0.0, 0.0, 1.0);
                Database db = Application.DocumentManager.MdiActiveDocument.Database;
                Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
                using (Transaction myT = tm.StartTransaction())
                {
                    BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                    BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                    using (Circle pcirc = new Circle(center, normal, res.Value))
                    {
                        btr.AppendEntity(pcirc);
                        tm.AddNewlyCreatedDBObject(pcirc, true);
                    }
                    myT.Commit();
                }

            }
        }
 public PromptDistanceArgument(PromptDistanceOptions options)
 {
     _options = options;
 }
Exemplo n.º 35
0
        public void Cmd_RcLaminate()
        {
            var acCurDoc = Application.DocumentManager.MdiActiveDocument;
            var acCurDb  = acCurDoc.Database;
            var acCurEd  = acCurDoc.Editor;


            //Prompt user to select a 3dFace
            var userSel = acCurEd.SelectSubentities(SubentityType.Face);

            if (userSel.Count <= 0)
            {
                return;
            }

            //Get the offset distance from the user
            var prSelOpts = new PromptDistanceOptions("\nEnter laminate thickness: ")
            {
                AllowNone     = false,
                AllowZero     = false,
                AllowNegative = false,
                DefaultValue  = SettingsUser.LaminateThickness
            };

            var prSelRes = acCurEd.GetDistance(prSelOpts);

            if (prSelRes.Status != PromptStatus.OK)
            {
                return;
            }

            //Set the offset variable
            SettingsUser.LaminateThickness = prSelRes.Value;

            try
            {
                var objList = new List <OffsetObject>();

                //Start a transaction
                using (var acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    foreach (var(objectId, subEntList) in userSel)
                    {
                        if (objList.Any(n => n.ObjId == objectId))
                        {
                            var offsetObject = objList.Find(i => i.ObjId == objectId);

                            foreach (var subentityId in subEntList)
                            {
                                offsetObject?.SubentIds.Add(subentityId);
                            }
                        }
                        else
                        {
                            var offsetObject = new OffsetObject(objectId);

                            foreach (var subentityId in subEntList)
                            {
                                offsetObject.SubentIds.Add(subentityId);
                            }

                            objList.Add(offsetObject);
                        }
                    }

                    var fuseList = new List <ObjectId>();

                    var layer = acCurDb.GetCLayer(acTrans);

                    foreach (var obj in objList)
                    {
                        var acSol = acTrans.GetObject(obj.ObjId, OpenMode.ForWrite) as Solid3d;
                        if (acSol != null)
                        {
                            var subtSol = acSol.Clone() as Solid3d;
                            if (subtSol != null)
                            {
                                subtSol.SetPropertiesFrom(acSol);
                                acCurDb.AppendEntity(subtSol, acTrans);

                                if (obj.SubentIds.Count > 0)
                                {
                                    acSol.Layer = layer;
                                    acSol.OffsetFaces(obj.SubentIds.ToArray(), SettingsUser.LaminateThickness);
                                    acSol.Downgrade();

                                    var acBool1 = new[] { acSol.ObjectId };
                                    var acBool2 = new[] { subtSol.ObjectId };

                                    acBool1.SolidSubtrahend(acBool2, acCurDb, acTrans, false);

                                    fuseList.Add(obj.ObjId);
                                }
                            }
                        }
                    }

                    var fusedObjId = fuseList.ToArray().SolidFusion(acTrans, acCurDb, true);

                    var fusedObj = acTrans.GetObject(fusedObjId, OpenMode.ForWrite) as Solid3d;
                    if (fusedObj != null)
                    {
                        var sepObj = fusedObj.SeparateBody();

                        foreach (var o in sepObj)
                        {
                            o.SetPropertiesFrom(fusedObj);
                            acCurDb.AppendEntity(o, acTrans);
                        }
                    }

                    //Commit the transaction
                    acTrans.Commit();
                }
            }
            catch (Exception e)
            {
                acCurEd.WriteMessage(e.Message);
            }
        }
Exemplo n.º 36
0
        private PromptStatus GetDistance(string message1, string message2, out double length, bool allowEmpty)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            PromptPointOptions opt1 = new PromptPointOptions(message1);
            opt1.AllowNone = allowEmpty;
            PromptPointResult res1 = ed.GetPoint(opt1);
            if (res1.Status == PromptStatus.OK)
            {
                PromptDistanceOptions opt2 = new PromptDistanceOptions(message2);
                opt2.AllowNone = allowEmpty;
                opt2.BasePoint = res1.Value;
                opt2.UseBasePoint = true;
                PromptDoubleResult res2 = ed.GetDistance(opt2);
                if (res2.Status == PromptStatus.OK)
                {
                    length = res2.Value;
                    return PromptStatus.OK;
                }
            }

            length = 0;
            return PromptStatus.Cancel;
        }
        public void ZZ_OffsetEdge()
        {
            Document doc = GetDocument();
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            double requiredOffset = 0;

            try
            {
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    PromptDistanceOptions pdo = new PromptDistanceOptions(
                        "\nSpecify the required offset: ")
                    {
                        AllowNegative   = true,
                        AllowNone       = false,
                        AllowZero       = true,
                        DefaultValue    = defaultOffset,
                        UseDefaultValue = defaultOffset == 0 ? false : true
                    };
                    PromptDoubleResult pdr = ed.GetDistance(pdo);
                    if (pdr.Status != PromptStatus.OK)
                    {
                        return;
                    }

                    requiredOffset = defaultOffset = pdr.Value;

                    PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline edge: ")
                    {
                        AllowNone = false
                    };
                    peo.SetRejectMessage("\n>>>this is not a polyline, Select a polyline edge: ");
                    peo.AddAllowedClass(typeof(Polyline), true);

                    PromptEntityResult per = ed.GetEntity(peo);
                    if (per.Status != PromptStatus.OK)
                    {
                        return;
                    }
                    var pline  = trans.GetObject(per.ObjectId, OpenMode.ForRead) as Polyline;
                    var pickPt = pline.GetClosestPointTo(per.PickedPoint, true);

                    PromptPointOptions ppo = new PromptPointOptions("\nSelect a side: ")
                    {
                        AllowNone = false
                    };
                    PromptPointResult ppr = ed.GetPoint(ppo);
                    if (ppr.Status != PromptStatus.OK)
                    {
                        return;
                    }
                    var p3 = ppr.Value.GetPoint2d();

                    int par  = (int)pline.GetParameterAtPoint(pickPt);
                    int pos1 = par + 1 == (int)pline.EndParam &&
                               pline.Closed ? 0 : par + 1;

                    // get the the surrounding points
                    var p1 = pline.GetPointAtParameter(par).GetPoint2d();
                    var p2 = pline.GetPointAtParameter(pos1).GetPoint2d();

                    double ang  = p1.GetVectorTo(p2).Angle;
                    bool   cw   = Clockwise(p1, p2, p3);
                    double ang1 = cw ? ang - Math.PI * 0.5 : ang + Math.PI * 0.5;
                    ed.WriteMessage("\nAng = " + ang);
                    ed.WriteMessage("\nAng1 = " + ang1);
                    var pt1 = p1.Polar(ang1, requiredOffset).GetPoint3d();
                    var pt2 = p2.Polar(ang1, requiredOffset).GetPoint3d();

                    BlockTable blockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
                                            as BlockTable;
                    BlockTableRecord record = trans.GetObject(blockTable[BlockTableRecord.ModelSpace]
                                                              , OpenMode.ForWrite) as BlockTableRecord;
                    Line line = new Line(pt1, pt2);
                    line.SetDatabaseDefaults();
                    record.AppendEntity(line);
                    trans.AddNewlyCreatedDBObject(line, true);
                    trans.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                ed.WriteMessage(ex.Message);
            }
        }
 double GetScale(double baseReferenceDimension)
 {
     string prompt = string.Format("\nЗадайте или укажите длину основной надписи (то, что должно быть {0} мм):", baseReferenceDimension);
     PromptDistanceOptions pdo =
         new PromptDistanceOptions(prompt);
     pdo.AllowZero = false;
     pdo.AllowNegative = false;
     pdo.Only2d = true;
     pdo.UseDashedLine = true;
     pdo.DefaultValue = baseReferenceDimension;
     PromptDoubleResult res = ed.GetDistance(pdo);
     if (res.Status!= PromptStatus.OK)
         return 0.0;
     double scale = res.Value / baseReferenceDimension;
     ed.WriteMessage("\nМасштабный коэффициент: {0}", scale);
     return scale;
 }