示例#1
0
        public void Cmd_ShowBounds()
        {
            if (!LicensingAgent.Check())
            {
                return;
            }

            if (!LicensingAgent.Check())
            {
                return;
            }
            var acCurDoc = Application.DocumentManager.MdiActiveDocument;
            var acCurDb  = acCurDoc.Database;
            var acCurEd  = acCurDoc.Editor;

            var objIds  = acCurEd.GetAllSelection(false);
            var boolRes = acCurEd.GetBool("Save bounds? ");

            if (boolRes == null)
            {
                return;
            }

            var append = boolRes.Value;

            using (var acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                var sol = acTrans.GetBoundingBox(objIds, acCurDb);

                sol.Transparency = new Transparency(75);
                sol.Color        = Colors.LayerColorBounds;

                TransientAgent.Add(sol);
                TransientAgent.Draw();

                if (append)
                {
                    acCurDb.AppendEntity(sol);
                }
                else
                {
                    sol.Dispose();
                }

                TransientAgent.Clear();


                acTrans.Commit();
            }
        }
示例#2
0
        public void Cmd_WeldMark()
        {
            if (!LicensingAgent.Check())
            {
                return;
            }
            var acCurDoc = Application.DocumentManager.MdiActiveDocument;
            var acCurDb  = acCurDoc.Database;

            _ = acCurDoc.Editor;

            try
            {
                Entity jigEnt = WeldJig.Jig(out var arrowStart, out var symStart);
                var    jigId  = ObjectId.Null;

                if (jigEnt == null)
                {
                    //jigEnt.Dispose();
                    return;
                }

                jigId = acCurDb.AppendEntity(jigEnt);
                Line line       = null;
                var  lineId     = ObjectId.Null;
                var  leftFacing = false;

                using (var acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    var arrowPt = new Point2d(arrowStart.X, arrowStart.Y);
                    var symPt   = new Point2d(symStart.X, symStart.Y);

                    var angle = arrowPt.AngleBetween(symPt);

                    var dDimScale =
                        (double)Application.GetSystemVariable("DIMSCALE");
                    var length = SettingsUser.WeldSymbolLength * dDimScale;

                    if (angle > 90 || angle < -90)
                    {
                        length     = -length;
                        leftFacing = true;
                    }

                    line = new Line(symStart, new Point3d(symStart.X + length, symStart.Y, 0));

                    lineId = acCurDb.AppendEntity(line, acTrans);


                    acTrans.Commit();
                }

                var weldGui = new WeldGui(line.StartPoint, line.EndPoint);
                weldGui.LeftFacing = leftFacing;

                var result = weldGui.ShowDialog();

                TransientAgent.Clear();

                using (var acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    if (result == DialogResult.OK)
                    {
                        foreach (var ent in weldGui.drawnEnts)
                        {
                            acCurDb.AppendEntity(ent, acTrans);
                        }
                    }
                    else
                    {
                        var jigDel = acTrans.GetObject(jigId, OpenMode.ForWrite) as Entity;
                        if (jigDel != null)
                        {
                            jigDel.Erase();
                            jigDel.Dispose();
                        }

                        var lineDel = acTrans.GetObject(lineId, OpenMode.ForWrite) as Entity;
                        if (lineDel != null)
                        {
                            lineDel.Erase();
                            lineDel.Dispose();
                        }

                        line.Dispose();
                    }

                    acTrans.Commit();
                }

                weldGui.Dispose();

                Utils.SetFocusToDwgView();
            }
            catch (Exception ex)
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString());
            }
        }