Esempio n. 1
0
        Stream(ArrayList data, PromptEditorOptions opts)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(PromptEditorOptions)));

            PromptCornerOptions promptCornerOpts = opts as PromptCornerOptions;

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

            PromptStringOptions promptStrOpts = opts as PromptStringOptions;

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

            PromptKeywordOptions promptKwordOpts = opts as PromptKeywordOptions;

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

            PromptNumericalOptions promptNumpericalOpts = opts as PromptNumericalOptions;

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

            PromptEntityOptions promptEntOpts = opts as PromptEntityOptions;

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

            PromptAngleOptions promptAngleOpts = opts as PromptAngleOptions;

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

            PromptDragOptions promptDragOpts = opts as PromptDragOptions;

            if (promptDragOpts != null)
            {
                Stream(data, promptDragOpts);
                return;
            }
        }
        // Lệnh thêm một liên kết
        protected void AddLink(string nameOfTheLink, string nameOfBlock)
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            // Thêm vật 1
            if (!SeclectTwoEntityAndOnePoint(nameOfTheLink, out PromptEntityResult obj1, out PromptEntityResult obj2, out Point3d point))
            {
                ed.WriteMessage("\nDa huy lenh them " + nameOfTheLink + ".");
                return;
            }

            //Thêm vật 2
            if (nameOfBlock != "Hinged" && nameOfBlock != "Culit" && nameOfBlock != "Slip" && nameOfBlock != "Fixed")
            {
                ed.WriteMessage("\nDa huy lenh them " + nameOfTheLink + ".");
                return;
            }

            //Thêm góc nghiêng
            double angle = 0;

            if (nameOfBlock != "Hinged")
            {
                PromptAngleOptions pdo = new PromptAngleOptions("\nNhap goc nghieng cua lien ket:");
                pdo.AllowArbitraryInput = true;
                pdo.AllowNone           = true;
                pdo.AllowZero           = true;
                pdo.DefaultValue        = 0;
                pdo.UseDefaultValue     = true;
                PromptDoubleResult result = ed.GetAngle(pdo);
                if (result.Status != PromptStatus.OK)
                {
                    ed.WriteMessage("\nDa huy lenh them " + nameOfTheLink + ".");
                    return;
                }
                angle = result.Value;
            }

            // Thêm vật vào bản vẽ
            string partDwg = @"Drawings\" + nameOfBlock + ".dwg";

            if (Common.InsertDrawing(partDwg, point, angle, out ObjectId IdEntity) == false)
            {
                ed.WriteMessage("\nDa huy lenh them " + nameOfTheLink + ".");
                return;
            }

            SetXData(IdEntity, obj1.ObjectId, obj2.ObjectId);
        }
Esempio n. 3
0
        Stream(ArrayList data, PromptAngleOptions opts)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(PromptAngleOptions)));

            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 zero", opts.AllowZero));
            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("Use angle base", opts.UseAngleBase));
            data.Add(new Snoop.Data.Bool("Use base point", opts.UseBasePoint));
            data.Add(new Snoop.Data.Bool("Use dashed line", opts.UseDashedLine));
            data.Add(new Snoop.Data.Bool("Use default value", opts.UseDefaultValue));
        }
Esempio n. 4
0
        public void MoveEntity()
        {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;

            Database acCurDb = acDoc.Database;

            Editor acEd = acDoc.Editor;

            PromptPointOptions acPPointOpts = new PromptPointOptions("");

            acPPointOpts.Message = "\n请输入一个点";

            PromptPointResult acPPointRes = acEd.GetPoint(acPPointOpts);

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

            PromptAngleOptions acPAngleOpts = new PromptAngleOptions("");

            acPAngleOpts.Message = "\n请指定角度";

            PromptDoubleResult acPDblRes = acEd.GetAngle(acPAngleOpts);

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

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Polyline acPolyline = GetPolyline() as Polyline;


                Matrix3d mtrix = Matrix3d.Displacement(acPPointRes.Value - Point3d.Origin) *
                                 Matrix3d.Rotation(acPDblRes.Value - Math.PI * 0.5, Vector3d.ZAxis, Point3d.Origin);

                acPolyline.TransformBy(mtrix);

                acBlkTblRec.AppendEntity(acPolyline);
                acTrans.AddNewlyCreatedDBObject(acPolyline, true);

                acTrans.Commit();
            }
        }
Esempio n. 5
0
        public void AngleTest()
        {
            Editor             ed   = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptAngleOptions opt1 = new PromptAngleOptions("Enter start angle of the arc");

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

            //USAGE OF INPUT CONTEXT REACTORS
            ed.PromptingForAngle += new PromptAngleOptionsEventHandler(handle_promptangleOptions);
            ed.PromptedForAngle  += new PromptDoubleResultEventHandler(handle_promptAngleResult);

            PromptDoubleResult startAngle = ed.GetAngle(opt1);

            ed.PromptingForAngle -= new PromptAngleOptionsEventHandler(handle_promptangleOptions);
            ed.PromptedForAngle  -= new PromptDoubleResultEventHandler(handle_promptAngleResult);


            opt1.Message = "Enter end angle of the arc";
            PromptDoubleResult endAngle = ed.GetAngle(opt1);

            PromptDoubleOptions opt2 = new PromptDoubleOptions("Enter the radius of the arc(double)");

            opt2.Message = "Enter the radius of the arc(double)";
            PromptDoubleResult radius = ed.GetDouble(opt2);

            if (startAngle.Status == PromptStatus.OK && endAngle.Status == PromptStatus.OK && radius.Status == PromptStatus.OK)
            {
                Point3d  center = new Point3d(30.0, 19.0, 0.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 (Arc arc1 = new Arc(center, radius.Value, startAngle.Value, endAngle.Value))
                    {
                        btr.AppendEntity(arc1);
                        tm.AddNewlyCreatedDBObject(arc1, true);
                    }
                    myT.Commit();
                }
            }
            else
            {
                ed.WriteMessage("Arc cannot be constructed");
            }
        }
Esempio n. 6
0
        SideType InputProcessSide(ProcessObject obj)
        {
            // TODO попытка после нажатия кнопки переключитьсся на окно автокада - не получилось нихуйа

            //EditorUserInteraction edInt = ed.StartUserInteraction(Program.ps as System.Windows.Forms.Control);
            //Program.ps.Visible = false;
            //Program.ed.UpdateScreen();
            //[System.Runtime.InteropServices.DllImport("user32.dll")]
            //static extern int SetActiveWindow(IntPtr hwnd);
            //SetActiveWindow(doc.Window.Handle);

            PromptAngleOptions promptOptions = new PromptAngleOptions("\nВыберите направление внешней нормали к объекту");

            //                AcEd.PromptPointOptions ptOpt = new AcEd.PromptPointOptions("\nВыберите направление внешней нормали к объекту");

            promptOptions.BasePoint     = obj.ProcessCurve.GetPointAtDist(obj.Length / 2);
            promptOptions.UseBasePoint  = true;
            promptOptions.UseDashedLine = true;

            PromptDoubleResult promptResult = Editor.GetAngle(promptOptions);

            //                AcEd.PromptPointResult resPt2 = ed.GetPoint(ptOpt);

            //Program.ps.Visible = true;
            //            edInt.End();
            if (promptResult.Status == PromptStatus.OK)
            {
                double angle = 0;
                switch (obj.ObjectType)
                {
                case ObjectType.Line:
                    angle = obj.ProcessLine.Angle;
                    break;

                case ObjectType.Arc:
                    angle = (obj.ProcessArc.StartAngle + obj.ProcessArc.TotalAngle / 2 + cPI2) % c2PI;
                    break;

                case ObjectType.Polyline:
                    angle = obj.ProcessCurve.GetFirstDerivative(promptOptions.BasePoint).GetAngleTo(Vector3d.XAxis);
                    break;
                }
                return(Math.Sin(promptResult.Value - angle) > 0 ? SideType.Left : SideType.Right);
            }
            else
            {
                return(SideType.None);
            }
        }
Esempio n. 7
0
        public void AngleTest()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptAngleOptions opt1 = new PromptAngleOptions("Enter start angle of the arc");

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

            //USAGE OF INPUT CONTEXT REACTORS
            ed.PromptingForAngle += new PromptAngleOptionsEventHandler(handle_promptangleOptions);
            ed.PromptedForAngle += new PromptDoubleResultEventHandler(handle_promptAngleResult);

            PromptDoubleResult startAngle = ed.GetAngle(opt1);

            ed.PromptingForAngle -= new PromptAngleOptionsEventHandler(handle_promptangleOptions);
            ed.PromptedForAngle -= new PromptDoubleResultEventHandler(handle_promptAngleResult);

            opt1.Message = "Enter end angle of the arc";
            PromptDoubleResult endAngle = ed.GetAngle(opt1);

            PromptDoubleOptions opt2 = new PromptDoubleOptions("Enter the radius of the arc(double)");
            opt2.Message = "Enter the radius of the arc(double)";
            PromptDoubleResult radius = ed.GetDouble(opt2);

            if(startAngle.Status == PromptStatus.OK && endAngle.Status == PromptStatus.OK && radius.Status == PromptStatus.OK)
            {
                Point3d center = new Point3d(30.0, 19.0, 0.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 (Arc arc1 = new Arc(center, radius.Value, startAngle.Value, endAngle.Value))
                    {
                        btr.AppendEntity(arc1);
                        tm.AddNewlyCreatedDBObject(arc1, true);
                    }
                    myT.Commit();
                }

            }
            else
            {
                ed.WriteMessage("Arc cannot be constructed");
            }
        }
Esempio n. 8
0
        protected bool GetEntityPointAngle(string nameOfObject, out ObjectId objId, out Point3d point, out double angle)
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            objId = ObjectId.Null;
            point = default;
            angle = 0;

            PromptEntityResult obj = ed.GetEntity("\nChon vat ma " + nameOfObject + " tac dong vao");

            if (obj.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them " + nameOfObject + ".");
                return(false);
            }

            PromptPointResult _point = ed.GetPoint(new PromptPointOptions("\nChon diem dat cua " + nameOfObject));

            if (_point.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them " + nameOfObject + ".");
                return(false);
            }

            PromptAngleOptions pdo = new PromptAngleOptions("\nNhap goc nghieng:");

            pdo.AllowArbitraryInput = true;
            pdo.AllowNone           = true;
            pdo.AllowZero           = true;
            pdo.DefaultValue        = 0;
            pdo.UseDefaultValue     = true;
            PromptDoubleResult _angle = ed.GetAngle(pdo);

            if (_angle.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them " + nameOfObject + ".");
                return(false);
            }

            objId = obj.ObjectId;
            point = _point.Value;
            angle = _angle.Value;

            return(true);
        }
Esempio n. 9
0
        /// <summary>
        /// Prompts the user to input an angle.
        /// </summary>
        /// <param name="message">Message to display in the command line.</param>
        /// <returns>The angle input by the user.</returns>
        public static double GetAngle(string message, ref PromptStatus status, AngleMode mode)
        {
            PromptAngleOptions options = new PromptAngleOptions(System.Environment.NewLine + message);
            Editor             command = Application.DocumentManager.MdiActiveDocument.Editor;

            PromptDoubleResult result = command.GetAngle(options);

            status = result.Status;

            double angle = result.Value;

            if (mode == AngleMode.Degrees)
            {
                angle = angle * 180 / Math.PI;
            }

            return(angle);
        }
Esempio n. 10
0
        //插入索引符号
        //[CommandMethod("I1")]
        public void I1()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;

            ed.WriteMessage("百福工具箱——插入索引符号");

            PromptPointOptions ppo = new PromptPointOptions("\n请选择插入点");
            PromptPointResult  ppr = ed.GetPoint(ppo);

            if (ppr.Status == PromptStatus.OK)
            {
                Point3d            insertPt = ppr.Value;
                PromptAngleOptions pao      = new PromptAngleOptions("\n请输入索引符号的指向角度")
                {
                    AllowArbitraryInput = true,
                    DefaultValue        = 0
                };
            }
        }
Esempio n. 11
0
        private static void GetAngleWithKeywords()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var ed  = doc.Editor;

            var pao = new PromptAngleOptions(
                messageAndKeywords: "\n指定对角点或[栏选(F) / 圈围(WP) / 圈交(CP)]:",
                globalKeywords: "栏选1 圈围2 圈交3");

            // 在界面中选择一个角度
            var pdr = ed.GetAngle(pao);

            MessageBox.Show(pdr.Status.ToString());
            if (pdr.Status == PromptStatus.Keyword)
            {
                MessageBox.Show($"用户输入的关键字为“{pdr.StringResult}”"); // 用户在命令行中输入的关键字

                // 根据用户在命令行中输入的不同的关键字,进行对应的处理
                switch (pdr.StringResult)
                {
                case "栏选1":
                    break;

                case "圈围2":

                    break;

                case "圈交3":

                    break;

                default:     // 如果用户不输入任何关键字,则StringResult属性的值为null

                    break;
                }
            }
            else if (pdr.Status == PromptStatus.OK)    // 用户选择结束
            {
                MessageBox.Show(pdr.Value.ToString()); // 用户在界面中选择的角度值
            }
        }
Esempio n. 12
0
        public void CreateUcsxAxis()
        {
            Database           db  = HostApplicationServices.WorkingDatabase;
            Editor             ed  = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptAngleOptions opt = new PromptAngleOptions("指定绕 X 轴的旋转角度");

            opt.UseDefaultValue = true;
            opt.DefaultValue    = Math.PI / 2;
            PromptDoubleResult res = ed.GetAngle(opt);
            Double             ang = res.Value;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                Vector3d xAxis = db.Ucsxdir;
                Vector3d yAxis = db.Ucsydir.RotateBy(ang, xAxis);
                Vector3d zAxis = xAxis.CrossProduct(yAxis);
                Point3d  org   = db.Ucsorg;
                Matrix3d mT    = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, org, xAxis, yAxis, zAxis);
                ed.CurrentUserCoordinateSystem = mT;
                trans.Commit();
            }
        }
Esempio n. 13
0
        static void InsertHeadSideWall(int coverage)
        {
            Editor().WriteMessage("\nInserting head...");

            ObjectId layerId = Layer.Ensure("HeadCoverage", ColorIndices.Yellow);

            Layer.Show(layerId);
            object osmode    = Application.GetSystemVariable("OSMODE");
            object orthomode = Application.GetSystemVariable("ORTHOMODE");

            Application.SetSystemVariable("OSMODE", 65);
            Application.SetSystemVariable("ORTHOMODE", 1);

            var pointResult = Editor().GetPoint("Where to place head");

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

            var options = new PromptAngleOptions("Angle of sidewall spray (press F8 to turn ORTHO off)")
            {
                BasePoint    = pointResult.Value,
                UseBasePoint = true
            };

            var angleResult = Editor().GetAngle(options);

            if (angleResult.Status == PromptStatus.OK)
            {
                HeadBuilder.Insert(coverage, pointResult.Value, angleResult.Value);
            }

            Layer.Hide(layerId);
            Application.SetSystemVariable("OSMODE", osmode);
            Application.SetSystemVariable("ORTHOMODE", orthomode);
        }
        public void DrawArrow()
        {
            //箭头图形
            Polyline pl = MakeArrow();

            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            //插入点
            var ppr = ed.GetPoint(new PromptPointOptions("\n指定点"));

            if (ppr.Status == PromptStatus.OK)
            {
                Point3d pt = ppr.Value;

                //插入角度
                var pao = new PromptAngleOptions("\n请输入一个角度");
                pao.BasePoint    = pt;
                pao.UseBasePoint = true;
                var par = ed.GetAngle(pao);
                if (par.Status == PromptStatus.OK)
                {
                    var angle = par.Value;

                    //缩放比例
                    var pdr = ed.GetDouble(new PromptDoubleOptions("\n请输入比例:"));
                    if (pdr.Status == PromptStatus.OK)
                    {
                        var scale = pdr.Value;

                        //是否镜像
                        var pko = new PromptKeywordOptions("\n是否反向");
                        pko.Keywords.Add("正向", "Y", "正向(Y)");
                        pko.Keywords.Add("反向", "N", "反向(N)");
                        pko.Keywords.Default = "正向";
                        var pkr = ed.GetKeywords(pko);

                        //旋转、缩放、平移矩阵
                        var mt = Matrix3d.Displacement(pt.GetAsVector())
                                 * Matrix3d.Scaling(scale, Point3d.Origin)
                                 * Matrix3d.Rotation(angle, Vector3d.ZAxis, Point3d.Origin);

                        if (pkr.Status == PromptStatus.OK)
                        {
                            if (pkr.StringResult == "反向")
                            {
                                var v   = Vector3d.XAxis.RotateBy(angle + Math.PI / 2, Vector3d.ZAxis);
                                var l3d = new Line3d(Point3d.Origin, v);
                                //旋转、进行、缩放、平移矩阵
                                mt = Matrix3d.Displacement(pt.GetAsVector())
                                     * Matrix3d.Scaling(scale, Point3d.Origin)
                                     * Matrix3d.Mirroring(l3d)
                                     * Matrix3d.Rotation(angle, Vector3d.ZAxis, Point3d.Origin);
                            }
                        }
                        //几何变换
                        pl.TransformBy(mt);

                        Database db = HostApplicationServices.WorkingDatabase;
                        //添加图形
                        using (var tr = db.TransactionManager.StartTransaction())
                        {
                            var id = db.AddToCurrentSpace(pl);
                            tr.Commit();
                        }
                    }
                }
            }
        }
Esempio n. 15
0
        public void SecondObject()
        {
            var db     = HostApplicationServices.WorkingDatabase;
            var doc    = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.GetDocument(db);
            var editor = doc.Editor;

            var startPointInput = new PromptPointOptions("\nSelect starting point:");

            startPointInput.AllowNone = false;
            Point3d startPoint = editor.GetPoint(startPointInput).Value;

            var arrowAngleInput = new PromptAngleOptions("\nSpecify arrow angle:");

            arrowAngleInput.AllowNone = false;

            double arrowAngle = editor.GetAngle(arrowAngleInput).Value;


            var transaction = db.TransactionManager.StartTransaction();

            using (transaction)
            {
                var horizontalLine = new Line(new Point3d(startPoint.X - 1, startPoint.Y, startPoint.Z), new Point3d(startPoint.X + 1.5, startPoint.Y, startPoint.Z));
                var verticalLine   = new Line(new Point3d(startPoint.X, startPoint.Y, startPoint.Z), new Point3d(startPoint.X, startPoint.Y - 1.5, startPoint.Z));

                var lineLeft   = new Line(new Point3d(startPoint.X - 0.5, startPoint.Y - 0.25, startPoint.Z), new Point3d(startPoint.X - 0.5, startPoint.Y + 0.25, startPoint.Z));
                var lineRight  = new Line(new Point3d(startPoint.X + 0.5, startPoint.Y - 0.25, startPoint.Z), new Point3d(startPoint.X + 0.5, startPoint.Y + 0.25, startPoint.Z));
                var lineBottom = new Line(new Point3d(startPoint.X - 0.25, startPoint.Y - 0.25, startPoint.Z), new Point3d(startPoint.X + 0.25, startPoint.Y - 0.25, startPoint.Z));

                var circle = new Circle(new Point3d(startPoint.X, startPoint.Y - 2.25, startPoint.Z), new Vector3d(0, 0, 1), 0.75);

                var innerCircle = new Circle(new Point3d(startPoint.X, startPoint.Y - 2.25, startPoint.Z), new Vector3d(0, 0, 1), 0.125);

                // Drawing arrow
                // Lower left line
                var startXLeft = innerCircle.Center.X - (Math.Cos(arrowAngle) * innerCircle.Radius);
                var startYLeft = innerCircle.Center.Y - (Math.Sin(arrowAngle) * innerCircle.Radius);
                var endXLeft   = startXLeft - (Math.Cos(arrowAngle) * 0.5); // 0.5 - line length
                var endYLeft   = startYLeft - (Math.Sin(arrowAngle) * 0.5);

                var innerLineLeft = new Line(
                    new Point3d(startXLeft, startYLeft, innerCircle.Center.Z),
                    new Point3d(endXLeft, endYLeft, innerCircle.Center.Z)
                    );

                // Upper right line
                var startXRight = innerCircle.Center.X + (Math.Cos(arrowAngle) * innerCircle.Radius);
                var startYRight = innerCircle.Center.Y + (Math.Sin(arrowAngle) * innerCircle.Radius);
                var endXRight   = startXRight + (Math.Cos(arrowAngle) * 0.25);
                var endYRight   = startYRight + (Math.Sin(arrowAngle) * 0.25);

                var innerLineRight = new Line(
                    new Point3d(startXRight, startYRight, innerCircle.Center.Z),
                    new Point3d(endXRight, endYRight, innerCircle.Center.Z)
                    );

                // Triangle
                var triangleLineLength = 0.25;
                var triangleHeight     = Math.Sqrt(Math.Pow(triangleLineLength, 2) - Math.Pow(triangleLineLength / 2, 2));

                var innerTriangleLine1 = new Line(
                    new Point3d(
                        innerLineRight.EndPoint.X - (triangleLineLength / 2 * Math.Sin(arrowAngle)),
                        innerLineRight.EndPoint.Y + (triangleLineLength / 2 * Math.Cos(arrowAngle)),
                        innerLineRight.EndPoint.Z),
                    new Point3d(
                        innerLineRight.EndPoint.X + (triangleLineLength / 2 * Math.Sin(arrowAngle)),
                        innerLineRight.EndPoint.Y - (triangleLineLength / 2 * Math.Cos(arrowAngle)),
                        innerLineRight.EndPoint.Z)
                    );

                var innerTriangleLine2 = new Line(
                    innerTriangleLine1.StartPoint,
                    new Point3d(
                        endXRight + (Math.Cos(arrowAngle) * triangleHeight),
                        endYRight + (Math.Sin(arrowAngle) * triangleHeight),
                        innerTriangleLine1.StartPoint.Z)
                    );

                var innerTriangleLine3 = new Line(
                    innerTriangleLine1.EndPoint,
                    innerTriangleLine2.EndPoint
                    );



                var record = (BlockTableRecord)transaction.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

                record.AppendEntity(horizontalLine);
                transaction.AddNewlyCreatedDBObject(horizontalLine, true);

                record.AppendEntity(verticalLine);
                transaction.AddNewlyCreatedDBObject(verticalLine, true);

                record.AppendEntity(lineLeft);
                record.AppendEntity(lineRight);
                record.AppendEntity(lineBottom);
                transaction.AddNewlyCreatedDBObject(lineLeft, true);
                transaction.AddNewlyCreatedDBObject(lineRight, true);
                transaction.AddNewlyCreatedDBObject(lineBottom, true);

                record.AppendEntity(circle);
                transaction.AddNewlyCreatedDBObject(circle, true);

                record.AppendEntity(innerCircle);
                record.AppendEntity(innerLineLeft);
                record.AppendEntity(innerLineRight);
                transaction.AddNewlyCreatedDBObject(innerCircle, true);
                transaction.AddNewlyCreatedDBObject(innerLineLeft, true);
                transaction.AddNewlyCreatedDBObject(innerLineRight, true);

                record.AppendEntity(innerTriangleLine1);
                record.AppendEntity(innerTriangleLine2);
                record.AppendEntity(innerTriangleLine3);
                transaction.AddNewlyCreatedDBObject(innerTriangleLine1, true);
                transaction.AddNewlyCreatedDBObject(innerTriangleLine2, true);
                transaction.AddNewlyCreatedDBObject(innerTriangleLine3, true);

                transaction.Commit();
            }
        }
Esempio n. 16
0
        public void Array()
        {
            Document acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; //Valitaan avoinna oleva dokumentti
            Database acCurDb = acDoc.Database;

            using (Transaction trans = acCurDb.TransactionManager.StartTransaction())
            {
                PromptSelectionResult selRes = acDoc.Editor.GetSelection();

                if (selRes.Status == PromptStatus.OK)
                {
                    SelectionSet acSet = selRes.Value;

                    if (acSet[0] != null)
                    {
                        Entity acEnt = trans.GetObject(acSet[0].ObjectId, OpenMode.ForWrite) as Entity;
                        if (acEnt != null)
                        {
                            if (acEnt.GetType() != typeof(DBText))
                            {
                                return;
                            }
                            DBText text   = acEnt as DBText;
                            int    number = int.Parse(text.TextString);

                            PromptDistanceOptions distOpt   = new PromptDistanceOptions("\nOffset");
                            PromptDoubleResult    doubleRes = acDoc.Editor.GetDistance(distOpt);

                            if (doubleRes.Status == PromptStatus.OK)
                            {
                                double             offset = doubleRes.Value;
                                PromptAngleOptions angOpt = new PromptAngleOptions("\nAngle");
                                angOpt.UseDashedLine = true;
                                angOpt.BasePoint     = text.Position;
                                doubleRes            = acDoc.Editor.GetAngle(angOpt);

                                if (doubleRes.Status == PromptStatus.OK)
                                {
                                    double angle = doubleRes.Value;
                                    PromptIntegerResult intRes = acDoc.Editor.GetInteger(new PromptIntegerOptions("\nCount"));
                                    if (intRes.Status == PromptStatus.OK)
                                    {
                                        int count = intRes.Value;

                                        BlockTable blkTable = trans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                                        BlockTableRecord blkRec;
                                        blkRec = trans.GetObject(blkTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;


                                        for (int i = 1; i <= count; i++)
                                        {
                                            DBText newText   = new DBText();
                                            int    increment = number + i;

                                            newText.Color       = text.Color;
                                            newText.Height      = text.Height;
                                            newText.Layer       = text.Layer;
                                            newText.TextStyleId = text.TextStyleId;
                                            newText.Rotation    = text.Rotation;

                                            newText.TextString = increment.ToString();
                                            newText.Position   = new Point3d(text.Position.X + Math.Cos(angle) * offset * i, text.Position.Y + Math.Sin(angle) * offset * i, text.Position.Z);

                                            blkRec.AppendEntity(newText);
                                            trans.AddNewlyCreatedDBObject(newText, true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                trans.Commit();
            }
        }
        //Block Insertor
        static public void InsestBlock(BlockModel objBlockModel)
        {
            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            //InsertionState
            BlockInsetions insState = BlockInsetions.Insert;

            //Variables
            Point3d p3dInsetion     = new Point3d();
            Point3d p3dMatrixCorner = new Point3d();


            //Get objId
            ObjectId objId = ArCaRefMgrController.GetBlockId(objBlockModel);
            //Create BlockReference
            BlockReference blockRef = new BlockReference(new Point3d(), objId);
            //Get BlockPropertyModel
            BlockPropModel objBloPro = objBlockModel.LstBlockProp[0];

            //Set properties in BlockRefernce
            blockRef.Rotation     = ArCaUtils.DegreeToRadian(objBloPro.Angle);
            blockRef.ScaleFactors = new Scale3d(objBloPro.SclX, objBloPro.SclY, objBloPro.SclZ);

            //Mirror Settings
            bool bTop  = true;
            bool bLeft = true;

            //Strategy for Preview in PointMonitor
            _PointMonitorStrategy = new PointMonitorStrategy(delegate(object sender, PointMonitorEventArgs e)
            {
                try
                {
                    switch (insState)
                    {
                    case BlockInsetions.Insert:
                        blockRef.Position = e.Context.ComputedPoint;
                        e.Context.DrawContext.Geometry.Draw(blockRef);
                        break;

                    case BlockInsetions.Rotate:
                        blockRef.Rotation = Vector3d.XAxis.GetAngleTo(p3dInsetion.GetVectorTo(e.Context.ComputedPoint), Vector3d.ZAxis);
                        e.Context.DrawContext.Geometry.Draw(blockRef);
                        break;

                    case BlockInsetions.Scale:
                        blockRef.ScaleFactors = new Scale3d(p3dInsetion.DistanceTo(e.Context.ComputedPoint));
                        e.Context.DrawContext.Geometry.Draw(blockRef);
                        break;

                    case BlockInsetions.Mirror:

                        if (e.Context.ComputedPoint.X < p3dInsetion.X && bLeft)
                        {
                            blockRef.ScaleFactors = new Scale3d(-(blockRef.ScaleFactors.X), blockRef.ScaleFactors.Y, blockRef.ScaleFactors.Z);
                            bLeft = false;
                        }
                        else if (e.Context.ComputedPoint.X > p3dInsetion.X && !bLeft)
                        {
                            blockRef.ScaleFactors = new Scale3d(-(blockRef.ScaleFactors.X), blockRef.ScaleFactors.Y, blockRef.ScaleFactors.Z);
                            bLeft = true;
                        }
                        if (e.Context.ComputedPoint.Y < p3dInsetion.Y && bTop)
                        {
                            blockRef.ScaleFactors = new Scale3d(blockRef.ScaleFactors.X, -(blockRef.ScaleFactors.Y), blockRef.ScaleFactors.Z);
                            bTop = false;
                        }
                        else if (e.Context.ComputedPoint.Y > p3dInsetion.Y && !bTop)
                        {
                            blockRef.ScaleFactors = new Scale3d(blockRef.ScaleFactors.X, -(blockRef.ScaleFactors.Y), blockRef.ScaleFactors.Z);
                            bTop = true;
                        }
                        e.Context.DrawContext.Geometry.Draw(blockRef);
                        break;

                    case BlockInsetions.Matrix:
                        //Get pt array
                        Point3dCollection pt3DColl = Utils.ArCaUtils.GetPtArray(p3dInsetion, e.Context.ComputedPoint, objBloPro.MatrixHeight, objBloPro.MatrixWidth);
                        double iLimitator          = objBloPro.MatrixMaxQuant;
                        foreach (Point3d pt3D in pt3DColl)
                        {
                            //Insert Block
                            blockRef.Position = pt3D;
                            e.Context.DrawContext.Geometry.Draw(blockRef);
                            //Limitator to evoid chash in machine
                            iLimitator--;
                            if (iLimitator < 1)
                            {
                                break;
                            }
                        }
                        break;
                    }
                }
                catch (System.Exception ex)
                {
                }
            });

            //add pointMonitor
            ed.PointMonitor += new PointMonitorEventHandler(PointMonitor);

            //Looping for Insertion in Loop
            do
            {
                //***Insertion point***
                insState = BlockInsetions.Insert;

                PromptPointOptions opcPt = new PromptPointOptions("\nClick on the insertion point: ");
                opcPt.AllowNone = false;
                PromptPointResult ProPtRes = ed.GetPoint(opcPt);

                if (ProPtRes.Status != PromptStatus.OK)
                {
                    //Command Canceled
                    break;
                }

                p3dInsetion     = ProPtRes.Value;
                p3dMatrixCorner = ProPtRes.Value;

                //***ROTATE***
                if (objBloPro.Rotate)
                {
                    insState = BlockInsetions.Rotate;

                    PromptAngleOptions opcAng = new PromptAngleOptions("\nDefine the rotation angle: ");
                    opcAng.AllowNone    = true;
                    opcAng.UseBasePoint = true;
                    opcAng.BasePoint    = p3dInsetion;
                    opcAng.DefaultValue = 0;
                    PromptDoubleResult ProAngRes = ed.GetAngle(opcAng);

                    if (ProAngRes.Status == PromptStatus.Cancel)
                    {
                        //Command Canceled, exit to "Loopin"
                        break;
                    }
                }

                //***SCALE***
                if (objBloPro.Scale)
                {
                    insState = BlockInsetions.Scale;

                    PromptDistanceOptions opcScl = new PromptDistanceOptions("\nDefine the scale factor: ");
                    opcScl.AllowNone    = true;
                    opcScl.UseBasePoint = true;
                    opcScl.BasePoint    = p3dInsetion;
                    opcScl.DefaultValue = 1;
                    PromptDoubleResult ProSclRes = ed.GetDistance(opcScl);

                    if (ProSclRes.Status == PromptStatus.Cancel)
                    {
                        //Command Canceled, exit to "Loopin"
                        break;
                    }
                }

                //***MIRROR***
                if (objBloPro.Mirror)
                {
                    insState = BlockInsetions.Mirror;

                    PromptPointOptions opcMatCor = new PromptPointOptions("\nClick on the point that define the mirror direction: ");
                    opcMatCor.AllowNone    = false;
                    opcMatCor.UseBasePoint = true;
                    opcMatCor.BasePoint    = p3dInsetion;
                    PromptPointResult ProMatCorRes = ed.GetPoint(opcMatCor);

                    if (ProMatCorRes.Status != PromptStatus.OK)
                    {
                        //Command Canceled, exit to "Loopin"
                        break;
                    }
                }

                //***MATRIX***
                if (objBloPro.Matrix)
                {
                    insState = BlockInsetions.Matrix;

                    PromptPointOptions opcMatCor = new PromptPointOptions("\nClick on the corner point of the matrix: ");
                    opcMatCor.AllowNone = false;
                    PromptPointResult ProMatCorRes = ed.GetPoint(opcMatCor);

                    if (ProMatCorRes.Status != PromptStatus.OK)
                    {
                        //Command Canceled, exit to "Loopin"
                        break;
                    }

                    p3dMatrixCorner = ProMatCorRes.Value;
                }

                //***Insertion of Block***
                //Get pt array
                Point3dCollection pt3DColl   = Utils.ArCaUtils.GetPtArray(p3dInsetion, p3dMatrixCorner, objBloPro.MatrixHeight, objBloPro.MatrixWidth);
                double            iLimitator = objBloPro.MatrixMaxQuant;
                foreach (Point3d pt3D in pt3DColl)
                {
                    //Set Position
                    blockRef.Position = pt3D;
                    //We need clone the block reference to obtain a block wiht other objectID in each iteration
                    BlockReference blockRefClone = blockRef.Clone() as BlockReference;
                    //Insert Block
                    Utils.ArCaUtils.InserBlock(db, objBloPro.Explode, blockRefClone);
                    //Limitator to evoid chash in machine
                    iLimitator--;
                    if (iLimitator < 1)
                    {
                        break;
                    }
                }
            } while (objBloPro.Loop);

            //remove pointMonitor
            ed.PointMonitor -= new PointMonitorEventHandler(PointMonitor);
        }
Esempio n. 18
0
        public void TestMethod()
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Polyline: ");

            peo.SetRejectMessage("\nNot a polyline");
            peo.AddAllowedClass(typeof(Polyline), true);
            var per = ed.GetEntity(peo);

            if (per.Status != PromptStatus.OK)
            {
                return;
            }
            ObjectId plOid = per.ObjectId;

            PromptPointResult ppr = ed.GetPoint(
                new PromptPointOptions("\nPick an internal point: "));

            if (ppr.Status != PromptStatus.OK)
            {
                return;
            }
            Point3d            testPoint = ppr.Value;
            PromptAngleOptions pao       = new PromptAngleOptions("\nSpecify ray direction: ")
            {
                BasePoint    = testPoint,
                UseBasePoint = true
            };
            var rayAngle = ed.GetAngle(pao);

            if (rayAngle.Status != PromptStatus.OK)
            {
                return;
            }
            Point3d tempPoint = testPoint.Add(Vector3d.XAxis);

            tempPoint = tempPoint.RotateBy(rayAngle.Value, Vector3d.ZAxis, testPoint);
            Vector3d rayDir = tempPoint - testPoint;

            ClearTransientGraphics();
            _markers = new DBObjectCollection();
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                Curve plCurve = trans.GetObject(plOid, OpenMode.ForRead) as Curve;
                for (int cnt = 0; cnt < 2; cnt++)
                {
                    if (cnt == 1)
                    {
                        rayDir = rayDir.Negate();
                    }
                    using (Ray ray = new Ray())
                    {
                        ray.BasePoint = testPoint;
                        ray.UnitDir   = rayDir;
                        Point3dCollection intersectionPts = new Point3dCollection();
                        plCurve.IntersectWith(ray, Intersect.OnBothOperands, intersectionPts,
                                              IntPtr.Zero, IntPtr.Zero);
                        foreach (Point3d pt in intersectionPts)
                        {
                            Circle marker = new Circle(pt, Vector3d.ZAxis, 0.2);
                            _markers.Add(marker);
                            IntegerCollection col = new IntegerCollection();
                            GI.TransientManager.CurrentTransientManager.AddTransient(
                                marker,
                                GI.TransientDrawingMode.Highlight, 128, col);
                            ed.WriteMessage("\n" + pt.ToString());
                        }
                    }
                }
                trans.Commit();
            }
        }
Esempio n. 19
0
        public override void Add()
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            var intensity1 = ed.GetString(new PromptStringOptions("Nhap gia tri luc cua diem dau tien"));

            if (intensity1.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc.");
                return;
            }

            var intensity2 = ed.GetString(new PromptStringOptions("Nhap gia tri luc cua diem sau"));

            if (intensity2.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc.");
                return;
            }

            PromptEntityResult objectId = ed.GetEntity("\nChon vat ma luc phan bo tac dong vao");

            if (objectId.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc phan bo.");
                return;
            }

            PromptPointResult point1 = ed.GetPoint(new PromptPointOptions("\nChon cac diem dat luc dau tien"));

            if (point1.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc phan bo.");
                return;
            }

            PromptPointResult point2 = ed.GetPoint(new PromptPointOptions("\nChon cac diem dat luc thu hai"));

            if (point2.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc phan bo.");
                return;
            }

            PromptAngleOptions pdo = new PromptAngleOptions("\nNhap goc nghieng:");

            pdo.AllowArbitraryInput = true;
            pdo.AllowNone           = true;
            pdo.AllowZero           = true;
            pdo.DefaultValue        = 0;
            pdo.UseDefaultValue     = true;
            PromptDoubleResult angle = ed.GetAngle(pdo);

            if (angle.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc phan bo. Vi khong lay duoc goc.");
                return;
            }

            string partDwg = @"Drawings\DistributedLoad.dwg";

            ////////////////////////
            Point3d point  = new Point3d((point1.Value.X + point2.Value.X) / 2, (point1.Value.Y + point2.Value.Y) / 2, 0);
            double  length = Math.Sqrt(Math.Pow(point1.Value.X - point2.Value.X, 2) + Math.Pow(point1.Value.Y - point2.Value.Y, 1));

            if (Math.Round(length, Common.numberOfMathRound) == 0)
            {
                ed.WriteMessage("\nDa huy lenh them luc phân bo. Vì kich thuoc khong the trung nhau.");
                return;
            }
            Scale3d scale = new Scale3d(Common.scale, length / Common.lengthOfDistributedLoad, 1);

            if (Common.InsertDrawing(partDwg, scale, point, angle.Value, out ObjectId idDistributedLoad) == false)
            {
                ed.WriteMessage("\nDa huy lenh them luc phân bo. Vi khong the ve duoc ban ve.");
                return;
            }

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Common.AddRegAppTableRecord("Data_MechanicalCalculation");
                TypedValue   typedValue = new TypedValue(1000, intensity1 + "," + intensity2 + "," + objectId.ToString() + "," + point1.Value.X + "," + point1.Value.Y + "," + point2.Value.X + "," + point2.Value.Y);
                ResultBuffer rb         = new ResultBuffer(new TypedValue(1001, "Data_MechanicalCalculation"), typedValue);
                tr.GetObject(idDistributedLoad, OpenMode.ForWrite).XData = rb;
                rb.Dispose();
                tr.Commit();
            }
        }
Esempio n. 20
0
 private static void handle_promptangleOptions(object sender, PromptAngleOptionsEventArgs e)
 {
     useThisAngleOption = e.Options;
 }
Esempio n. 21
0
 private static void handle_promptangleOptions(object sender, PromptAngleOptionsEventArgs e)
 {
     useThisAngleOption = e.Options;
 }