Esempio n. 1
0
        private void SelectBlock(int button)
        {
            Document acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            path = acDoc.Name;

            PromptSelectionResult selRes;

            using (EditorUserInteraction preventFlikkering = acDoc.Editor.StartUserInteraction(Autodesk.AutoCAD.ApplicationServices.Core.Application.MainWindow.Handle))
            {
                selRes = acDoc.Editor.GetSelection();
                preventFlikkering.End();
            }

            using (Transaction trans = acCurDb.TransactionManager.StartTransaction())
            {
                if (selRes.Status == PromptStatus.OK)
                {
                    SelectionSet acSet = selRes.Value;
                    if (acSet[0] != null)
                    {
                        if (trans.GetObject(acSet[0].ObjectId, OpenMode.ForRead) is Entity acEnt)
                        {
                            if (acEnt.GetType() == typeof(BlockReference))
                            {
                                BlockReference selectedBlock = acEnt as BlockReference;

                                if (button == 1)
                                {
                                    hBlockReplace       = selectedBlock.Handle;
                                    LabelBlock1.Content = selectedBlock.Name;
                                }
                                else
                                {
                                    BlockReplacement    = selectedBlock.Name;
                                    LabelBlock2.Content = selectedBlock.Name;
                                }
                            }
                            else
                            {
                                acDoc.Editor.WriteMessage("Selected entity was not a block.\n"); return;
                            }
                        }
                        else
                        {
                            acDoc.Editor.WriteMessage("Selected entity was not an entity.\n"); return;
                        }
                    }
                    else
                    {
                        acDoc.Editor.WriteMessage("Null selection.\n"); return;
                    }
                }
                else
                {
                    acDoc.Editor.WriteMessage("Selection cancelled.\n"); return;
                }
            }
        }
Esempio n. 2
0
 private void buttonSelect_Click(object sender, EventArgs e)
 {
     using (EditorUserInteraction UI = _randomPaintingService.Ed.StartUserInteraction(this))
     {
         _randomPaintingService.PromptExtents();
     }
 }
Esempio n. 3
0
        OnRunTest(object sender, EventArgs e)
        {
            /// start user interaction object so that this form
            /// does not interfere with user selection in editor
            EditorUserInteraction userInteraction = m_editor.StartUserInteraction(this);

            SelectionMethod selMethod = (SelectionMethod)m_puMainSelectionMethod.SelectedIndex;

            if (selMethod == SelectionMethod.kUser)
            {
                SelectionUser();
            }
            else if (selMethod == SelectionMethod.kAll)
            {
                SelectionAll();
            }
            else if (selMethod == SelectionMethod.kImplied)
            {
                SelectionImplied();
            }
            else if (selMethod == SelectionMethod.kCrossing)
            {
                SelectionCrossing();
            }
            else if (selMethod == SelectionMethod.kCrossingPolygon)
            {
                SelectionCrossingPolygon();
            }
            else if (selMethod == SelectionMethod.kFence)
            {
                SelectionFence();
            }
            else if (selMethod == SelectionMethod.kLast)
            {
                SelectionLast();
            }
            else if (selMethod == SelectionMethod.kPrevious)
            {
                SelectionPrevious();
            }
            else if (selMethod == SelectionMethod.kWindow)
            {
                SelectionWindow();
            }
            else if (selMethod == SelectionMethod.kWindowPolygon)
            {
                SelectionWindowPolygon();
            }
            else
            {
                Debug.Assert(false);
            }

            userInteraction.End();
        }
Esempio n. 4
0
 private void buttonSelect_Click(object sender, EventArgs e)
 {
     using (EditorUserInteraction UI = _imagePaintingService.Doc.Editor.StartUserInteraction(this))
     {
         try
         {
             _imagePaintingService.PromptExtents();
             setUserRect();
         }
         catch { }
     }
 }
Esempio n. 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            using (EditorUserInteraction edUsrInt = ed.StartUserInteraction(this))
            {
                Point3d pt = GetPoint("\nPlease select point : ");
                this.InputText.Text = "(" + pt.X.ToString() + "," + pt.Y.ToString() + "," + pt.Z.ToString() + ")";
                edUsrInt.End();
                this.Focus();
            }
        }
Esempio n. 6
0
        private void BTN_UPTOP_Click(object sender, EventArgs e)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            using (EditorUserInteraction edUsrInt = ed.StartUserInteraction(this))
            {
                Point3d pt = GetPoint("\n选择点:");
                pointUpT = pt;
                this.INPUT_UPTOP.Text = "(" + pt.X.ToString() + "," + pt.Y.ToString() + "," + pt.Z.ToString() + ")";
                edUsrInt.End(); // End the UserInteraction.
                this.Focus();
            }
        }
Esempio n. 7
0
        //点击“切入到 AutoCAD 拾取点”按钮窗体自动隐藏,程序焦点切换到 AutoCAD 主界面
        private void button1_Click(object sender, EventArgs e)
        {
            using (EditorUserInteraction edUsrInt = BaseData.ed.StartUserInteraction(this)){
                //交互过程
                Point3d pt = InteractionUtil.getPoint("选择点");
//                _textBox = textBox1;
//                _textBox.Text  = "(" + pt.X + "," + pt.Y + "," + pt.Z + ")";
                this.textBox1.Text = "(" + pt.X + "," + pt.Y + "," + pt.Z + ")";
                //交互结束
                edUsrInt.End();
                Focus();
            }
        }
Esempio n. 8
0
        private void btnDrawShapes_Click(object sender, EventArgs e)
        {
            Editor            ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            PromptPointResult result;

            using (EditorUserInteraction UI = ed.StartUserInteraction(this))
            {
                result = ed.GetPoint("Açılım şablonun çizileceği yer: ");
            }
            if (result.Status == PromptStatus.OK)
            {
                DWGUtility.DrawShape(GetSelected(), result.Value, 75);

                MessageBox.Show("Açılımı şablon çerçevesi içine çizin ve tekrar bu diyalog kutusuna dönüp çizimden al düğmesini tıklayın." + Environment.NewLine + "Çizimden alırken poz şeklini çerçevesi ile birlikte seçin.", "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            SetShape();
        }
Esempio n. 9
0
        private void btnPickSpacing_Click(object sender, EventArgs e)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            using (EditorUserInteraction UI = ed.StartUserInteraction(this))
            {
                double length;
                if (GetDistance("\nStart point: ", "\nEnd point: ", out length) == PromptStatus.OK)
                {
                    double spa = 0;
                    if (double.TryParse(txtPosSpacing.Text, out spa) && spa > double.Epsilon)
                    {
                        int num = 1 + (int)Math.Ceiling(length / spa);
                        txtPosCount.Text = num.ToString();
                    }
                }
            }
        }
Esempio n. 10
0
        private void GetLengthFromMeasurement(TextBox txt)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            using (EditorUserInteraction UI = ed.StartUserInteraction(this))
            {
                string length  = "";
                double length1 = 0;
                if (GetDistance("\nFirst point: ", "\nSecond point: ", out length1) == PromptStatus.OK)
                {
                    length = length1.ToString("F0");
                    double length2 = 0;
                    if (GetDistance("\n" + length + "-... First point: ", "\n" + length + "-... Second point: ", out length2, true) == PromptStatus.OK)
                    {
                        length += "~" + length2.ToString("F0");
                    }
                    txt.Text = length;
                    CheckPosLength(txt);
                }
            }
        }
Esempio n. 11
0
        m_btnEntChoose_Click(object sender, EventArgs e)
        {
            Editor ed = AcadApp.Application.DocumentManager.MdiActiveDocument.Editor;

            EditorUserInteraction userInteraction = ed.StartUserInteraction(this);

            try
            {
                PromptEntityResult res = ed.GetEntity("\nSelect first entity");
                if (res.Status != PromptStatus.OK)
                {
                    return;
                }
                ObjectId objId1 = res.ObjectId;

                res = ed.GetEntity("\nSelect second entity");
                if (res.Status != PromptStatus.OK)
                {
                    return;
                }
                ObjectId objId2 = res.ObjectId;

                m_obj1 = m_trHlpr.Transaction.GetObject(objId1, OpenMode.ForRead);
                m_obj2 = m_trHlpr.Transaction.GetObject(objId2, OpenMode.ForRead);

                PopulateCompareBox(m_compareBx1, objId1, string.Empty);
                PopulateCompareBox(m_compareBx2, objId2, string.Empty);

                Compare();
            }
            /// dont leave editor paralysed if user cancels out
            finally
            {
                userInteraction.End();
            }
        }
Esempio n. 12
0
File: Ac.cs Progetto: 15831944/Geo7
 public EditorUserInteractionWrapper(EditorUserInteraction userInteraction)
 {
     this.interaction = userInteraction;
 }
Esempio n. 13
0
        private void btnPickNumber_Click(object sender, EventArgs e)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            using (EditorUserInteraction UI = ed.StartUserInteraction(this))
            {
                TypedValue[] tvs = new TypedValue[] {
                    new TypedValue((int)DxfCode.Operator, "<OR"),
                    new TypedValue((int)DxfCode.Start, "TEXT"),
                    new TypedValue((int)DxfCode.Start, "MTEXT"),
                    new TypedValue((int)DxfCode.Start, "DIMENSION"),
                    new TypedValue((int)DxfCode.Operator, "OR>")
                };
                PromptSelectionResult res = ed.GetSelection(new SelectionFilter(tvs));
                if (res.Status == PromptStatus.OK && res.Value.Count > 0)
                {
                    PromptIntegerOptions nopts = new PromptIntegerOptions("\nCarpan: ");
                    nopts.AllowNegative = false;
                    nopts.AllowZero     = false;
                    nopts.DefaultValue  = 1;
                    PromptIntegerResult nres = ed.GetInteger(nopts);
                    if (nres.Status == PromptStatus.OK)
                    {
                        string   multiplierString = (nres.Value == 1 ? "" : nres.Value.ToString() + "*");
                        Database db = HostApplicationServices.WorkingDatabase;
                        using (Transaction tr = db.TransactionManager.StartTransaction())
                        {
                            try
                            {
                                boundDimensions.Clear();
                                int total = 0;
                                foreach (SelectedObject sobj in res.Value)
                                {
                                    string   text = "";
                                    DBObject obj  = tr.GetObject(sobj.ObjectId, OpenMode.ForRead);
                                    if (obj is DBText)
                                    {
                                        DBText dobj = obj as DBText;
                                        text = dobj.TextString;
                                    }
                                    else if (obj is MText)
                                    {
                                        MText dobj = obj as MText;
                                        text = dobj.Text;
                                    }
                                    else if (obj is Dimension)
                                    {
                                        boundDimensions.Add(sobj.ObjectId);
                                    }
                                    if (!string.IsNullOrEmpty(text))
                                    {
                                        text = text.TrimStart('(').TrimEnd(')');
                                        int num = 0;
                                        if (int.TryParse(text, out num))
                                        {
                                            total += num;
                                        }
                                    }
                                }
                                string countText = "";
                                if (total != 0)
                                {
                                    countText = multiplierString + total.ToString();
                                }
                                if (boundDimensions.Count > 0)
                                {
                                    countText = (total == 0 ? "" : countText + "+") + multiplierString + "<>";
                                }
                                txtPosCount.Text = countText;
                            }
                            catch (System.Exception ex)
                            {
                                MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 14
0
        private void GetLengthFromEntity(TextBox txt)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            using (EditorUserInteraction UI = ed.StartUserInteraction(this))
            {
                PromptEntityOptions opts = new PromptEntityOptions("\nSelect entity: ");
                opts.SetRejectMessage("\nSelect a LINE, ARC, TEXT, MTEXT, POLYLINE or DIMENSION entity.");
                opts.AddAllowedClass(typeof(Line), false);
                opts.AddAllowedClass(typeof(Arc), false);
                opts.AddAllowedClass(typeof(DBText), false);
                opts.AddAllowedClass(typeof(MText), false);
                opts.AddAllowedClass(typeof(Dimension), false);
                opts.AddAllowedClass(typeof(Polyline), false);
                PromptEntityResult per = ed.GetEntity(opts);

                if (per.Status == PromptStatus.OK)
                {
                    ObjectId id = per.ObjectId;
                    Database db = HostApplicationServices.WorkingDatabase;
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        try
                        {
                            DBObject obj = tr.GetObject(per.ObjectId, OpenMode.ForRead);
                            if (obj is Line)
                            {
                                Line dobj = obj as Line;
                                txt.Text = dobj.Length.ToString();
                            }
                            else if (obj is Arc)
                            {
                                Arc dobj = obj as Arc;
                                txt.Text = dobj.Length.ToString();
                            }
                            else if (obj is DBText)
                            {
                                DBText dobj = obj as DBText;
                                txt.Text = dobj.TextString;
                            }
                            else if (obj is MText)
                            {
                                MText dobj = obj as MText;
                                txt.Text = dobj.Text;
                            }
                            else if (obj is Dimension)
                            {
                                Dimension dobj = obj as Dimension;
                                txt.Text = dobj.Measurement.ToString();
                            }
                            else if (obj is Polyline)
                            {
                                Polyline dobj = obj as Polyline;
                                txt.Text = dobj.Length.ToString();
                            }
                            CheckPosLength(txt);
                        }
                        catch (System.Exception ex)
                        {
                            System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "RebarPos", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }
Esempio n. 15
0
        private void btnAlign_Click(object sender, EventArgs e)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            using (EditorUserInteraction UI = ed.StartUserInteraction(this))
            {
                PromptEntityOptions opts = new PromptEntityOptions("\nSelect entity: ");
                opts.AllowNone = false;
                opts.SetRejectMessage("\nSelect a LINE, ARC or POLYLINE entity.");
                opts.AddAllowedClass(typeof(Curve), false);
                PromptEntityResult per = ed.GetEntity(opts);
                if (per.Status == PromptStatus.OK)
                {
                    Point3d  pt = per.PickedPoint;
                    ObjectId id = per.ObjectId;

                    bool     posUp = false;
                    Vector3d dir = new Vector3d(), up = new Vector3d(), normal = new Vector3d();
                    Database db = HostApplicationServices.WorkingDatabase;
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        try
                        {
                            RebarPos pos = (RebarPos)tr.GetObject(m_Pos, OpenMode.ForRead);

                            Curve curve = (Curve)tr.GetObject(id, OpenMode.ForRead);
                            pt     = curve.GetClosestPointTo(pt, curve.GetPlane().Normal, false);
                            dir    = curve.GetFirstDerivative(pt);
                            dir    = dir * pos.DirectionVector.Length / dir.Length;
                            normal = pos.NormalVector;
                            normal = normal * pos.DirectionVector.Length / normal.Length;
                            up     = dir.CrossProduct(normal);
                            up     = up * pos.DirectionVector.Length / up.Length;

                            posUp = (dir.DotProduct(pos.UpVector) > 0);
                        }
                        catch (System.Exception ex)
                        {
                            System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "RebarPos", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        }
                    }

                    double offset = 0.0;
                    double offset1 = -0.75, offset2 = 1.75;
                    if (posUp)
                    {
                        AlignPos(pt + offset1 * up, dir, up, normal);
                        offset = offset2;
                    }
                    else
                    {
                        AlignPos(pt + offset2 * up, dir, up, normal);
                        offset = offset1;
                    }

                    PromptKeywordOptions kopts = new PromptKeywordOptions("\nDiğer tarafa yerleştirilsin mi? [Evet/Hayır] <Hayir>: ", "Yes No");
                    kopts.AllowNone = true;
                    PromptResult kres = ed.GetKeywords(kopts);
                    if (kres.Status == PromptStatus.None || kres.StringResult == "Yes")
                    {
                        AlignPos(pt + offset * up, dir, up, normal);
                        ed.UpdateScreen();
                    }
                }
            }
        }
Esempio n. 16
0
        private void ButtonSelect_Click(object sender, RoutedEventArgs e)
        {
            Document acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            PromptSelectionResult selRes;

            using (EditorUserInteraction preventFlikkering = acDoc.Editor.StartUserInteraction(Autodesk.AutoCAD.ApplicationServices.Core.Application.MainWindow.Handle))
            {
                selRes = acDoc.Editor.GetSelection();
                preventFlikkering.End();
            }

            using (Transaction trans = acCurDb.TransactionManager.StartTransaction())
            {
                if (selRes.Status == PromptStatus.OK)
                {
                    SelectionSet acSet = selRes.Value;
                    if (acSet[0] != null)
                    {
                        if (trans.GetObject(acSet[0].ObjectId, OpenMode.ForRead) is Entity acEnt)
                        {
                            if (acEnt.GetType() == typeof(BlockReference))
                            {
                                BlockReference selectedBlock = acEnt as BlockReference;

                                LabelBlock.Content = selectedBlock.Name;
                                hBlock             = selectedBlock.Handle;

                                AttributeCollection attCol = selectedBlock.AttributeCollection;
                                if (attCol.Count != 0)
                                {
                                    List <string> attList = new List <string>();
                                    foreach (ObjectId att in attCol)
                                    {
                                        using (AttributeReference attRef = trans.GetObject(att, OpenMode.ForRead) as AttributeReference)
                                        {
                                            attList.Add(attRef.Tag);
                                        }
                                    }
                                    ComboAttribute.ItemsSource = attList;
                                }
                                else
                                {
                                    acDoc.Editor.WriteMessage("Selected block did not contain any attributes.\n"); return;
                                }
                            }
                            else
                            {
                                acDoc.Editor.WriteMessage("Selected entity was not a block.\n"); return;
                            }
                        }
                        else
                        {
                            acDoc.Editor.WriteMessage("Selected entity was not an entity.\n"); return;
                        }
                    }
                    else
                    {
                        acDoc.Editor.WriteMessage("Null selection.\n"); return;
                    }
                }
                else
                {
                    acDoc.Editor.WriteMessage("Selection cancelled.\n"); return;
                }
            }
        }
Esempio n. 17
0
        private void btnSelectShapes_Click(object sender, EventArgs e)
        {
            PosShape copy = GetSelected();

            if (copy == null || copy.IsBuiltIn)
            {
                return;
            }

            // Select shapes
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            using (EditorUserInteraction UI = ed.StartUserInteraction(this))
            {
                TypedValue[] tvs = new TypedValue[] {
                    new TypedValue((int)DxfCode.Operator, "<OR"),
                    new TypedValue((int)DxfCode.Start, "LINE"),
                    new TypedValue((int)DxfCode.Start, "ARC"),
                    new TypedValue((int)DxfCode.Start, "CIRCLE"),
                    new TypedValue((int)DxfCode.Start, "TEXT"),
                    new TypedValue((int)DxfCode.Operator, "OR>")
                };
                SelectionFilter       filter = new SelectionFilter(tvs);
                PromptSelectionResult result = ed.GetSelection(filter);

                if (result.Status != PromptStatus.OK || result.Value.Count == 0)
                {
                    return;
                }

                int fieldCount = 1;
                copy.Items.Clear();
                Database db = HostApplicationServices.WorkingDatabase;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    try
                    {
                        foreach (SelectedObject sel in result.Value)
                        {
                            DBObject obj = tr.GetObject(sel.ObjectId, OpenMode.ForRead);

                            bool   visible = true;
                            Entity en      = obj as Entity;
                            if (en != null)
                            {
                                LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(en.LayerId, OpenMode.ForRead);

                                if (ltr != null)
                                {
                                    visible = ltr.IsPlottable;
                                }
                            }

                            if (obj is Line)
                            {
                                Line line = obj as Line;

                                copy.Items.Add(new PosShape.ShapeLine(line.Color, line.StartPoint.X, line.StartPoint.Y, line.EndPoint.X, line.EndPoint.Y, visible));
                            }
                            else if (obj is Arc)
                            {
                                Arc arc = obj as Arc;
                                copy.Items.Add(new PosShape.ShapeArc(arc.Color, arc.Center.X, arc.Center.Y, arc.Radius, arc.StartAngle, arc.EndAngle, visible));
                            }
                            else if (obj is Circle)
                            {
                                Circle circle = obj as Circle;
                                copy.Items.Add(new PosShape.ShapeCircle(circle.Color, circle.Center.X, circle.Center.Y, circle.Radius, visible));
                            }
                            else if (obj is DBText)
                            {
                                DBText text = obj as DBText;
                                if (text.TextString == "A" && fieldCount < 1)
                                {
                                    fieldCount = 1;
                                }
                                if (text.TextString == "B" && fieldCount < 2)
                                {
                                    fieldCount = 2;
                                }
                                if (text.TextString == "C" && fieldCount < 3)
                                {
                                    fieldCount = 3;
                                }
                                if (text.TextString == "D" && fieldCount < 4)
                                {
                                    fieldCount = 4;
                                }
                                if (text.TextString == "E" && fieldCount < 5)
                                {
                                    fieldCount = 5;
                                }
                                if (text.TextString == "F" && fieldCount < 6)
                                {
                                    fieldCount = 6;
                                }
                                double x = text.Position.X;
                                double y = text.Position.Y;
                                if (text.AlignmentPoint.X != 0.0 || text.AlignmentPoint.Y != 0.0)
                                {
                                    x = text.AlignmentPoint.X;
                                    y = text.AlignmentPoint.Y;
                                }
                                copy.Items.Add(new PosShape.ShapeText(text.Color, x, y, text.Height, text.WidthFactor, text.TextString, "romans.shx", text.HorizontalMode, text.VerticalMode, visible));
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "RebarPos", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    }
                }

                udFields.Value = fieldCount;
            }

            SetShape();
        }
Esempio n. 18
0
        private void ButtonSelect_Click(object sender, RoutedEventArgs e)
        {
            Document acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            PromptSelectionResult selRes;

            using (EditorUserInteraction preventFlikkering = acDoc.Editor.StartUserInteraction(Autodesk.AutoCAD.ApplicationServices.Core.Application.MainWindow.Handle))
            {
                selRes = acDoc.Editor.GetSelection();
                preventFlikkering.End();
            }

            using (Transaction trans = acCurDb.TransactionManager.StartTransaction())
            {
                if (selRes.Status == PromptStatus.OK)
                {
                    SelectionSet acSet = selRes.Value;
                    if (acSet[0] != null)
                    {
                        if (trans.GetObject(acSet[0].ObjectId, OpenMode.ForRead) is Entity acEnt)
                        {
                            if (acEnt.GetType() == typeof(BlockReference))
                            {
                                BlockReference selectedBlock = acEnt as BlockReference;

                                //hBlock = selectedBlock.Handle;

                                AttributeCollection attCol = selectedBlock.AttributeCollection;
                                if (attCol.Count != 0)
                                {
                                    foreach (ObjectId att in attCol)
                                    {
                                        using (AttributeReference attRef = trans.GetObject(att, OpenMode.ForRead) as AttributeReference)
                                        {
                                            acDoc.Editor.WriteMessage(selectedBlock.Handle.Value.ToString());
                                            System.Data.DataColumn col = new System.Data.DataColumn(selectedBlock.Name + "-" + selectedBlock.Handle.Value + "-" + attRef.Tag, typeof(string));
                                            col.DefaultValue = "";
                                            DT.Columns.Add(col);
                                        }
                                    }
                                    Spreadsheet.ItemsSource = null;
                                    Spreadsheet.ItemsSource = DT.DefaultView;
                                }
                                else
                                {
                                    acDoc.Editor.WriteMessage("Selected block did not contain any attributes.\n"); return;
                                }
                            }
                            else
                            {
                                acDoc.Editor.WriteMessage("Selected entity was not a block.\n"); return;
                            }
                        }
                        else
                        {
                            acDoc.Editor.WriteMessage("Selected entity was not an entity.\n"); return;
                        }
                    }
                    else
                    {
                        acDoc.Editor.WriteMessage("Null selection.\n"); return;
                    }
                }
                else
                {
                    acDoc.Editor.WriteMessage("Selection cancelled.\n"); return;
                }
            }
        }
Esempio n. 19
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            DBObjectCollection EntityCollection;
            Editor             ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            using (EditorUserInteraction edUsrInt = ed.StartUserInteraction(this))
            {
                //交互过程
                FilterType   TextType = FilterType.Text;
                FilterType[] Types    = new FilterType[1];
                Types[0]         = TextType;
                EntityCollection = Selection.GetSelection(Types);
                edUsrInt.End(); //交互结束.
                this.Focus();
            }

            Database db = HostApplicationServices.WorkingDatabase;//打开当前文档的数据库

            if (rbTail.Checked == true)
            {
                using (Transaction transaction = db.TransactionManager.StartTransaction())
                {
                    foreach (Entity ent in EntityCollection)
                    {
                        DBText text = (DBText)transaction.GetObject(ent.ObjectId, OpenMode.ForWrite, true);
                        if (tbTailLoc.Text == "")
                        {
                            tbTailLoc.Text = "0";
                        }
                        text.TextString = text.TextString.Insert(text.TextString.Length - int.Parse(tbTailLoc.Text), tbTailAdd.Text);
                    }
                    transaction.Commit();
                }
            }
            if (rbAdd.Checked == true)
            {
                using (Transaction transaction = db.TransactionManager.StartTransaction())
                {
                    foreach (Entity ent in EntityCollection)
                    {
                        DBText text = (DBText)transaction.GetObject(ent.ObjectId, OpenMode.ForWrite, true);
                        if (tbAddLoc.Text == "")
                        {
                            tbAddLoc.Text = "0";
                        }
                        text.TextString = text.TextString.Insert(int.Parse(tbAddLoc.Text), tbAddAdd.Text);
                    }
                    transaction.Commit();
                }
            }
            if (rbSub.Checked == true)
            {
                using (Transaction transaction = db.TransactionManager.StartTransaction())
                {
                    foreach (Entity ent in EntityCollection)
                    {
                        DBText text = (DBText)transaction.GetObject(ent.ObjectId, OpenMode.ForWrite, true);
                        text.TextString = text.TextString.Replace(tbSubFind.Text, tbSubAdd.Text);
                    }
                    transaction.Commit();
                }
            }
        }