예제 #1
0
        public void EntsInsideWindow()
        {
            AcadApp.DocumentManager.MdiActiveDocument.Window.Focus();
            using (AcadApp.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction())
                {
                    PromptSelectionResult prmpt_ret = AcadFuncs.GetEditor().
                                                      SelectCrossingWindow(new Point3d(0.0, 0.0, 0.0), new Point3d(10.0, 10.0, 0.0));
                    if (PromptStatus.Cancel == prmpt_ret.Status)
                    {
                        tr.Abort();
                        tr.Dispose();
                        return;
                    }

                    ObjectId[] ss = prmpt_ret.Value.GetObjectIds();
                    foreach (ObjectId ent_id in ss)
                    {
                        DBObject obj = tr.GetObject(ent_id, OpenMode.ForRead);
                        if (null == obj)
                        {
                            continue;
                        }
                        if (obj is Line)
                        {
                            MessageBox.Show("Selected a line!");
                        }
                    }

                    tr.Commit();
                }
            }
        }
예제 #2
0
        public void GetPointOrString()
        {
            PromptSelectionOptions pnt_opts = new PromptSelectionOptions();

            //pnt_opts.Message = "\nPick point";

            // Define the valid keywords and allow Enter
            //pnt_opts.AllowArbitraryInput = true;
            //pnt_opts.AllowNone = true;
            pnt_opts.UnknownInput += Pnt_opts_UnknownInput;
            //pnt_opts.KeywordInput += Pnt_opts_KeywordInput;

            // Get the value entered by the user
            try
            {
                PromptSelectionResult pIntRes = AcadFuncs.GetActiveDoc().Editor.GetSelection(pnt_opts);
            }
            catch (System.Exception ex)
            {
            }
            MessageBox.Show(UnknownInput);

            pnt_opts.UnknownInput -= Pnt_opts_UnknownInput;
            //pnt_opts.KeywordInput -= Pnt_opts_KeywordInput;
        }
예제 #3
0
        public void PickSingleEnt()
        {
            AcadApp.DocumentManager.MdiActiveDocument.Window.Focus();
            using (AcadApp.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction())
                {
                    PromptEntityResult prmpt_ret = AcadFuncs.GetEditor().GetEntity("Chọn một đối tượng line");
                    if (PromptStatus.Cancel == prmpt_ret.Status)
                    {
                        tr.Abort();
                        tr.Dispose();
                        return;
                    }

                    ObjectId obj_id = prmpt_ret.ObjectId;
                    sel_obj_id = prmpt_ret.ObjectId;
                    DBObject obj = tr.GetObject(obj_id, OpenMode.ForRead);
                    if (obj is Line)
                    {
                        MessageBox.Show("Selected a line!");
                    }
                    else
                    {
                        MessageBox.Show("This entity isn't a line!");
                    }

                    tr.Commit();
                }
            }
        }
예제 #4
0
        public void FilterEnts()
        {
            AcadApp.DocumentManager.MdiActiveDocument.Window.Focus();
            using (AcadApp.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction())
                {
                    TypedValue[] type_var = new TypedValue[2];
                    type_var.SetValue(new TypedValue((int)DxfCode.Start, "circle,line"), 0);
                    type_var.SetValue(new TypedValue((int)DxfCode.Color, 1), 1);

                    /*
                     * https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2017/ENU/AutoCAD-NET/files/GUID-125398A5-184C-4114-9212-A2FF28FC1F1D-htm.html
                     * */

                    SelectionFilter sel_filter = new SelectionFilter(type_var);

                    PromptSelectionResult prmpt_ret = AcadFuncs.GetEditor().GetSelection(sel_filter);
                    if (PromptStatus.Cancel == prmpt_ret.Status)
                    {
                        tr.Abort();
                        tr.Dispose();
                        return;
                    }

                    ObjectId[] ss = prmpt_ret.Value.GetObjectIds();
                    foreach (ObjectId ent_id in ss)
                    {
                        DBObject obj = tr.GetObject(ent_id, OpenMode.ForRead);
                        if (null == obj)
                        {
                            continue;
                        }
                        if (obj is Line)
                        {
                            MessageBox.Show("Selected a line!");
                        }
                    }

                    tr.Commit();
                }
            }
        }
예제 #5
0
        public void PickPoint()
        {
            AcadApp.DocumentManager.MdiActiveDocument.Window.Focus();
            using (AcadApp.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction())
                {
                    PromptPointOptions prmpt_pnt = new PromptPointOptions("Chọn điểm");
                    PromptPointResult  prmpt_ret = AcadFuncs.GetEditor().GetPoint(prmpt_pnt);
                    if (PromptStatus.Cancel == prmpt_ret.Status)
                    {
                        tr.Abort();
                        tr.Dispose();
                        return;
                    }

                    Point3d picked_pnt = prmpt_ret.Value;
                    tr.Commit();
                }
            }
        }
예제 #6
0
        public void FilterEntsWildCard()
        {
            AcadApp.DocumentManager.MdiActiveDocument.Window.Focus();
            using (AcadApp.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction())
                {
                    TypedValue[] type_var = new TypedValue[2];
                    type_var.SetValue(new TypedValue((int)DxfCode.Start, "text"), 0);
                    type_var.SetValue(new TypedValue((int)DxfCode.Text, "*abc"), 1);
                    SelectionFilter sel_filter = new SelectionFilter(type_var);

                    PromptSelectionResult prmpt_ret = AcadFuncs.GetEditor().GetSelection(sel_filter);
                    if (PromptStatus.Cancel == prmpt_ret.Status)
                    {
                        tr.Abort();
                        tr.Dispose();
                        return;
                    }

                    ObjectId[] ss = prmpt_ret.Value.GetObjectIds();
                    foreach (ObjectId ent_id in ss)
                    {
                        DBObject obj = tr.GetObject(ent_id, OpenMode.ForRead);
                        if (null == obj)
                        {
                            continue;
                        }
                        if (obj is Line)
                        {
                            MessageBox.Show("Selected a line!");
                        }
                    }

                    tr.Commit();
                }
            }
        }
예제 #7
0
        public static bool PickPoint(ref AcadGeo.Point3d picked_pnt, string mess)
        {
            AcadApp.DocumentManager.MdiActiveDocument.Window.Focus();
            using (AcadApp.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction())
                {
                    PromptPointOptions prmpt_pnt = new PromptPointOptions(mess);
                    PromptPointResult  prmpt_ret = AcadFuncs.GetEditor().GetPoint(prmpt_pnt);
                    if (PromptStatus.Cancel == prmpt_ret.Status)
                    {
                        tr.Abort();
                        tr.Dispose();
                        return(false);
                    }

                    picked_pnt = prmpt_ret.Value;
                    tr.Commit();
                }
            }


            return(true);
        }