Beispiel #1
0
        public void AddGradientHatch()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            //创建一个三角形
            Polyline triangle = new Polyline();

            triangle.CreatePolygon(new Point2d(550, 200), 3, 30);
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //将三角形添加到模型空间中
                ObjectId triangleId = db.AddToModelSpace(triangle);
                //创建一个ObjectId集合类对象,用于存储填充边界的ObjectId
                ObjectIdCollection ids = new ObjectIdCollection
                {
                    triangleId             //将三角形的ObjectId添加到边界集合中
                };
                Hatch hatch = new Hatch(); //创建填充对象
                //创建两个Color类变量,分别表示填充的起始颜色(红)和结束颜色(蓝)
                Color color1 = Color.FromColorIndex(ColorMethod.ByLayer, 1);
                Color color2 = Color.FromColor(System.Drawing.Color.Blue);
                //创建渐变填充,与边界无关联
                hatch.CreateGradientHatch(HatchGradientName.Cylinder, color1, color2, false);
                //为填充添加边界(三角形)
                hatch.AppendLoop(HatchLoopTypes.Default, ids);
                hatch.EvaluateHatch(true); //计算并显示填充对象
                trans.Commit();            //提交更改
            }
        }
        /// <summary>
        /// Adds the predefined hatch.
        /// </summary>
        /// <param name="trans">The trans.</param>
        /// <param name="points">The points.</param>
        /// <param name="layername">The layername.</param>
        /// <param name="isClosed">if set to <c>true</c> [is closed].</param>
        /// <param name="patternName">Name of the pattern.</param>
        /// <returns></returns>
        public static ObjectId AddPredefinedHatch(Transaction trans, Point2dCollection points, string layername, bool isClosed, string patternName)
        {
            //_logger.Debug("Start AddPredefinedHatch");
            ObjectId id = ObjectId.Null;

            Autodesk.AutoCAD.DatabaseServices.Database           db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            using (Hatch hatch = new Hatch())
            {
                hatch.SetDatabaseDefaults();
                hatch.Layer = layername;

                id = AddToDatabase(db, hatch, trans);

                hatch.UpgradeOpen();
                //hatch.HatchStyle = HatchStyle.Outer;
                hatch.Associative  = true;
                hatch.PatternScale = 100.0;
                hatch.SetHatchPattern(HatchPatternType.PreDefined, patternName);

                double buldge = 0.0;

                HatchLoop loop = new HatchLoop(HatchLoopTypes.Polyline);
                foreach (Point2d pt in points)
                {
                    BulgeVertex bv = new BulgeVertex(pt, buldge);
                    loop.Polyline.Add(bv);
                }
                hatch.AppendLoop(loop);
                hatch.EvaluateHatch(true);
            }
            //_logger.Debug("End AddPredefinedHatch");
            return(id);
        }
        /// <summary>
        /// 创建填充实体
        /// </summary>
        /// <param name="poly">多线段参数</param>
        /// <param name="patternScale">填充比例</param>
        /// <returns>填充对象</returns>
        public static Hatch GetHatch(this Polyline poly, double patternScale = 1)
        {
            var pts = poly.GetVertexs();

            var distinctPts = pts.Distinct(new PointEqual()).ToList();

            var point2dCollection = new Point2dCollection();

            distinctPts.ForEach(m =>
            {
                point2dCollection.Add(new Point2d(m.X, m.Y));
            });

            point2dCollection.Add(new Point2d(distinctPts[0].X, distinctPts[0].Y));

            var hatch = new Hatch();

            var dbCollection = new DoubleCollection()
            {
                0
            };

            hatch.AppendLoop(HatchLoopTypes.Polyline, point2dCollection, dbCollection);

            hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");

            hatch.PatternScale = patternScale;

            hatch.ColorIndex = GColor.Green;

            hatch.EvaluateHatch(true);

            return(hatch);
        }
Beispiel #4
0
        public void AddHatch()
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                Hatch hatch = new Hatch(); //创建填充对象
                hatch.ToSpace();
                hatch.PatternScale = 0.5;  //设置填充图案的比例
                string patterName = DBHelper.CurrentPattern;
                //根据上面的填充图案名创建图案填充,类型为预定义,与边界关联
                hatch.CreateHatch(HatchPatternType.PreDefined, patterName, true);
                for (int i = 0; i < this.objco.Count; i++)
                {
                    if (i == 0)
                    {
                        //为填充添加外边界(正六边形)
                        hatch.AppendLoop(HatchLoopTypes.Outermost, objco[i]);
                    }
                    else
                    {
                        //为填充添加外边界(正六边形)
                        hatch.AppendLoop(HatchLoopTypes.Default, objco[i]);
                    }
                }
                hatch.EvaluateHatch(true); //计算并显示填充对象
                trans.Commit();            //提交更改
            }
        }
Beispiel #5
0
        private void AddHatchingArrow(IList <Entity> entity)
        {
            using (var transaction = CADProxy.Database.TransactionManager.StartTransaction())
            {
                var polyline = new Polyline();
                polyline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
                polyline.AddVertexAt(0, new Point2d(1.5, 1.5), 0, 0, 0);
                polyline.AddVertexAt(0, new Point2d(0, 1.5), 0, 0, 0);
                polyline.Closed = true;

                var blockTableRecord = transaction.GetObject(CADProxy.Database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                var objIds           = new ObjectIdCollection()
                {
                    blockTableRecord.AppendEntity(polyline)
                };
                transaction.AddNewlyCreatedDBObject(polyline, true);

                var hatch = new Hatch();
                hatch.SetDatabaseDefaults();
                hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                hatch.Associative = false;
                hatch.AppendLoop((int)HatchLoopTypes.Default, objIds);
                hatch.EvaluateHatch(true);

                polyline.Erase();

                entity.Add(hatch);
            }
        }
        /// <summary>
        /// 图案填充 无颜色
        /// </summary>
        /// <param name="db">图形数据库</param>
        /// <param name="patternName">图案名称</param>
        /// <param name="scale">填充比例</param>
        /// <param name="degree">旋转角度</param>
        /// <param name="entid">边界图形的ObjectId</param>
        /// <returns></returns>
        public static ObjectId HatchEnity(this Database db, string patternName, double scale, double degree, ObjectId entid)
        {
            ObjectId hatchId = ObjectId.Null;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                // 声明一个图案填充对象
                Hatch hatch = new Hatch();
                // 设置填充比例
                hatch.PatternScale = scale;
                // 设置填充类型和图案名称
                hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANGLE");
                // 加入图形数据库
                BlockTable       bt  = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                hatchId = btr.AppendEntity(hatch);
                trans.AddNewlyCreatedDBObject(hatch, true);

                // 设置填充角度
                hatch.PatternAngle = degree;
                // 设置关联
                hatch.Associative = true;
                // 设置边界图形和填充方式

                ObjectIdCollection obIds = new ObjectIdCollection();
                obIds.Add(entid);
                hatch.AppendLoop(HatchLoopTypes.Outermost, obIds);
                // 计算填充并显示
                hatch.EvaluateHatch(true);
                // 提交事务
                trans.Commit();
            }
            return(hatchId);
        }
Beispiel #7
0
        public HatchDrawingObject CreateHatch(string patternName)
        {
            Transaction      trans = _database.TransactionManager.TopTransaction;
            BlockTableRecord btr   = _database.GetModelSpace(true);

            Hatch    oHatch = new Hatch();
            Vector3d normal = Vector3d.ZAxis;

            oHatch.Normal       = normal;
            oHatch.Elevation    = 0.0;
            oHatch.PatternScale = 1.0;
            oHatch.SetHatchPattern(HatchPatternType.PreDefined, patternName);

            btr.AppendEntity(oHatch);
            trans.AddNewlyCreatedDBObject(oHatch, true);

            oHatch.Associative = true;
            ObjectIdCollection acObjIdColl = new ObjectIdCollection();

            acObjIdColl.Add(BaseObject);
            oHatch.AppendLoop(HatchLoopTypes.Default, acObjIdColl);
            oHatch.EvaluateHatch(true);

            return(new HatchDrawingObject(oHatch));
        }
Beispiel #8
0
        private static void FillContour(BlockSectionKP bs, Polyline plExtern, BlockTableRecord cs, Transaction t)
        {
            var h = new Hatch();

            h.SetDatabaseDefaults();
            h.Layer      = OptionsKPBS.Instance.LayerBSContourGNS;
            h.LineWeight = LineWeight.LineWeight015;
            h.Linetype   = SymbolUtilityServices.LinetypeContinuousName;
            h.Color      = GetFillColor(bs); // Color.FromRgb(250, 250, 250);
            //h.Transparency = new Transparency(80);
            h.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
            cs.AppendEntity(h);
            t.AddNewlyCreatedDBObject(h, true);
            h.Associative = true;
            h.HatchStyle  = HatchStyle.Normal;

            // добавление контура полилинии в гштриховку
            var ids = new ObjectIdCollection();

            ids.Add(plExtern.Id);
            h.AppendLoop(HatchLoopTypes.Default, ids);
            h.EvaluateHatch(true);

            var orders = cs.DrawOrderTableId.GetObject(OpenMode.ForWrite) as DrawOrderTable;

            orders.MoveToBottom(new ObjectIdCollection(new[] { h.Id }));
        }
Beispiel #9
0
        /// <summary>
        /// 绘制填充
        /// </summary>
        /// <param name="db">CAD数据库</param>
        /// <param name="pl">外轮廓多线</param>
        /// <param name="href">填充参考样式</param>
        /// <param name="scale">填充比例,默认=1</param>
        /// <returns>返回填充对象</returns>
        public static Hatch PlotH(Database db, Polyline pl, Hatch href, double scale = 1)
        {
            Hatch hatch1 = new Hatch();

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable       blockTbl   = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                                                           OpenMode.ForWrite) as BlockTableRecord;

                hatch1.SetHatchPattern(href.PatternType, href.PatternName);
                modelSpace.AppendEntity(hatch1);
                tr.AddNewlyCreatedDBObject(hatch1, true);
                hatch1.PatternScale = href.PatternScale;
                hatch1.Layer        = "填充";
                hatch1.Associative  = true;
                hatch1.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection {
                    pl.ObjectId
                });
                hatch1.EvaluateHatch(true);


                hatch1.PatternScale = href.PatternScale;
                hatch1.SetHatchPattern(hatch1.PatternType, hatch1.PatternName);


                tr.Commit();
            }
            return(hatch1);
        }
Beispiel #10
0
        public static Hatch CreateHatch(ObjectId ID, string Type, Color C)
        {
            var Return = new Hatch();

            using (Transaction T = Doc.TransactionManager.StartTransaction())
            {
                var BT  = T.GetObject(DB.BlockTableId, OpenMode.ForRead) as BlockTable;
                var BTR = T.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Return.SetDatabaseDefaults();

                var OC = new ObjectIdCollection();
                OC.Add(ID);

                Return.SetDatabaseDefaults();
                Return.SetHatchPattern(HatchPatternType.PreDefined, Type);
                Return.Associative = true;
                Return.AppendLoop(HatchLoopTypes.Default, OC);
                Return.EvaluateHatch(true);
                Return.Color = C;

                BTR.AppendEntity(Return);
                T.AddNewlyCreatedDBObject(Return, true);
                T.Commit();
            }

            return(Return);
        }
        private void AddHatchingArrow(IList <Entity> entityList)
        {
            var hatch = new Hatch();

            using (var tr = CADProxy.Database.TransactionManager.StartTransaction())
            {
                var bd = new Polyline();
                bd.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
                bd.AddVertexAt(0, new Point2d(-2.5, 3), 0, 0, 0);
                bd.AddVertexAt(0, new Point2d(2.5, 3), 0, 0, 0);
                bd.Closed = true;
                BlockTable       bt  = tr.GetObject(CADProxy.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord btr = tr.GetObject(CADProxy.Database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                var bdId             = btr.AppendEntity(bd);
                tr.AddNewlyCreatedDBObject(bd, true);
                ObjectIdCollection ObjIds = new ObjectIdCollection
                {
                    bdId
                };

                hatch.SetDatabaseDefaults();
                hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                hatch.Associative = false;
                hatch.AppendLoop((int)HatchLoopTypes.Default, ObjIds);
                hatch.EvaluateHatch(true);
                bd.Erase();
            }
            entityList.Add(hatch);
        }
Beispiel #12
0
        public static Hatch NewHatch(ObjectIdCollection ids)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                //-------------------------------
                // 获取模型空间
                //-------------------------------
                BlockTable blockTbl = tr.GetObject(
                    db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(
                    blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;


                //-------------------------------
                // 创建填充对象
                //-------------------------------
                Hatch hatch = new Hatch();
                modelSpace.AppendEntity(hatch);
                tr.AddNewlyCreatedDBObject(hatch, true);

                hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
                hatch.Associative = true;

                hatch.AppendLoop(HatchLoopTypes.Outermost, ids);
                hatch.EvaluateHatch(true);

                //
                tr.Commit();
                return(hatch);
            }
        }
Beispiel #13
0
        public void AddHatch()
        {
            Document mdiActiveDocument = Application.DocumentManager.MdiActiveDocument;
            Database database          = mdiActiveDocument.Database;

            using (Transaction transaction = database.TransactionManager.StartTransaction())
            {
                BlockTable       blockTable       = (BlockTable)transaction.GetObject(database.BlockTableId, 0);
                BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], 1);
                Circle           circle           = new Circle();
                circle.SetDatabaseDefaults();
                Circle  circle2 = circle;
                Point3d center;
                center..ctor(3.0, 3.0, 0.0);
                circle2.Center = center;
                circle.Radius  = 10000.0;
                blockTableRecord.AppendEntity(circle);
                transaction.AddNewlyCreatedDBObject(circle, true);
                ObjectIdCollection objectIdCollection = new ObjectIdCollection();
                objectIdCollection.Add(circle.ObjectId);
                Hatch hatch = new Hatch();
                blockTableRecord.AppendEntity(hatch);
                transaction.AddNewlyCreatedDBObject(hatch, true);
                hatch.SetDatabaseDefaults();
                hatch.SetHatchPattern(1, "ANSI31");
                hatch.Associative = true;
                hatch.AppendLoop(16, objectIdCollection);
                hatch.EvaluateHatch(true);
                transaction.Commit();
            }
        }
Beispiel #14
0
        /// <summary>
        ///     Adds the predefined hatch.
        /// </summary>
        /// <param name="trans">The trans.</param>
        /// <param name="points">The points.</param>
        /// <param name="layername">The layername.</param>
        /// <param name="isClosed">if set to <c>true</c> [is closed].</param>
        /// <param name="patternName">Name of the pattern.</param>
        /// <returns></returns>
        public static ObjectId AddPredefinedHatch(Transaction trans, Point2dCollection points, string layername,
                                                  bool isClosed, string patternName)
        {
            PGA.MessengerManager.MessengerManager.AddLog("Start AddPredefinedHatch");
            var id = ObjectId.Null;
            var db = Application.DocumentManager.MdiActiveDocument.Database;
            var tm = db.TransactionManager;

            using (var hatch = new Hatch())
            {
                hatch.SetDatabaseDefaults();
                hatch.Layer = layername;

                id = AddToDatabase(db, hatch, trans);

                hatch.UpgradeOpen();
                //hatch.HatchStyle = HatchStyle.Outer;
                hatch.Associative  = true;
                hatch.PatternScale = 100.0;
                hatch.SetHatchPattern(HatchPatternType.PreDefined, patternName);

                var buldge = 0.0;

                var loop = new HatchLoop(HatchLoopTypes.Polyline);
                foreach (var pt in points)
                {
                    var bv = new BulgeVertex(pt, buldge);
                    loop.Polyline.Add(bv);
                }
                hatch.AppendLoop(loop);
                hatch.EvaluateHatch(true);
            }
            PGA.MessengerManager.MessengerManager.AddLog("End AddPredefinedHatch");
            return(id);
        }
Beispiel #15
0
        HatchAssoc()
        {
            m_db = Utils.Db.GetCurDwg();

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = m_db.TransactionManager;
            using (Autodesk.AutoCAD.DatabaseServices.Transaction tr = tm.StartTransaction()) {
                // make boundary triangle
                Polyline pline1 = new Polyline();
                pline1.ColorIndex = 211;
                pline1.AddVertexAt(0, new Point2d(0.0, 0.0), 0.0, 0.0, 0.0);
                pline1.AddVertexAt(0, new Point2d(30.0, 0.0), 0.0, 0.0, 0.0);
                pline1.AddVertexAt(0, new Point2d(15.0, 30.0), 0.0, 0.0, 0.0);
                pline1.Closed = true;
                Utils.Db.TransformToWcs(pline1, m_db);
                Utils.SymTbl.AddToCurrentSpace(pline1, m_db, tr);

                // offset the triangle and add those entities to the db
                DBObjectCollection offsetCurves = pline1.GetOffsetCurves(5.0);
                Utils.SymTbl.AddToCurrentSpace(offsetCurves, m_db, tr);

                ObjectIdCollection boundaryIds1 = new ObjectIdCollection();
                boundaryIds1.Add(pline1.ObjectId);

                ObjectIdCollection boundaryIds2 = new ObjectIdCollection();
                foreach (Entity tmpEnt in offsetCurves)
                {
                    boundaryIds2.Add(tmpEnt.ObjectId);
                }

                Hatch hatch = new Hatch();
                hatch.ColorIndex = 141;

                Utils.Db.TransformToWcs(hatch, m_db);   // NOTE: need to transform to correct plane *BEFORE* setting pattern and boundary info

                hatch.PatternAngle = Utils.Ge.kRad0;
                hatch.PatternScale = 4.0;
                hatch.SetHatchPattern(HatchPatternType.PreDefined, "STARS");

                hatch.HatchStyle = HatchStyle.Normal;
                Utils.SymTbl.AddToCurrentSpace(hatch, m_db, tr);

                // To make an associative hatch we have to first add it to the database (above).
                // When we call AppendLoop(), it will add the Persistent Reactor that keeps the
                // boundary associative.
                hatch.Associative = true;
                hatch.AppendLoop(HatchLoopTypes.Default, boundaryIds1);
                if (boundaryIds2.Count > 0)
                {
                    hatch.AppendLoop(HatchLoopTypes.Default, boundaryIds2);
                }

                hatch.EvaluateHatch(false);

                tr.Commit();
            }
        }
Beispiel #16
0
        public static void DrawHatch(HatchInfo info)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db  = HostApplicationServices.WorkingDatabase;
            var ed  = doc.Editor;

            using (doc.LockDocument())
            {
                var op = new PromptPointOptions(Environment.NewLine + "请在要填充的区域内部选择一点");
                op.AllowNone = true;
                var result = ed.GetPoint(op);
                if (result.Status == PromptStatus.OK)
                {
                    var lines = ed.TraceBoundary(result.Value, true).Cast <Polyline>();
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        var space = (BlockTableRecord)tr.GetObject(doc.Database.CurrentSpaceId, OpenMode.ForWrite);
                        using (var ent = new Hatch())
                        {
                            ent.SetDatabaseDefaults();
                            ent.SetHatchPattern((HatchPatternType)Enum.Parse(typeof(HatchPatternType), info.PatternType), info.PatternName);
                            ent.PatternScale  = info.PatternScale;
                            ent.PatternAngle  = info.PatternAngle * (Math.PI / 180); //角度转弧度 度数 * (π / 180) = 弧度
                            ent.PatternSpace  = info.PatternSpace;
                            ent.PatternDouble = info.PatternDouble;
                            ent.HatchStyle    = (HatchStyle)Enum.Parse(typeof(HatchStyle), info.HatchStyle);
                            ent.ColorIndex    = info.ColorIndex;
                            ent.Associative   = info.Associative;
                            LayerManager.SetLayer(ent, info.LayerName, tr);
                            foreach (var one in lines)
                            {
                                var id = space.AppendEntity(one);
                                tr.AddNewlyCreatedDBObject(one, true);
                                ent.AppendLoop(HatchLoopTypes.Outermost, new ObjectIdCollection()
                                {
                                    id
                                });
                            }
                            ent.EvaluateHatch(true);
                            space.AppendEntity(ent);
                            tr.AddNewlyCreatedDBObject(ent, true);

                            foreach (var one in lines)
                            {
                                one.Erase();
                            }

                            tr.Commit();
                            DataManager.WriteDictionary(ent.Id, info.Data);
                        }
                    }
                }
            }
        }
Beispiel #17
0
        public static Polyline PlotLayerOne(Database db, Point2d p1, Point2d p2, Hatch href, double offset = 0, double tk = 100, double scale = 1, bool isVetica = false)
        {
            Hatch    hat = new Hatch();
            Polyline PL  = new Polyline();
            Line     ori = new Line(p1.Convert3D(), p2.Convert3D());

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable       blockTbl   = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                                                           OpenMode.ForWrite) as BlockTableRecord;


                if (isVetica)
                {
                    PL.AddVertexAt(0, p1.Convert2D(0, -offset), 0, 0, 0);
                    PL.AddVertexAt(1, p2.Convert2D(0, -offset), 0, 0, 0);
                    PL.AddVertexAt(2, p2.Convert2D(0, -tk - offset), 0, 0, 0);
                    PL.AddVertexAt(3, p1.Convert2D(0, -tk - offset), 0, 0, 0);
                }
                else
                {
                    Line lineup = (Line)ori.GetOffsetCurves(-offset)[0];
                    PL.AddVertexAt(0, lineup.StartPoint.Convert2D(), 0, 0, 0);
                    PL.AddVertexAt(1, lineup.EndPoint.Convert2D(), 0, 0, 0);
                    Line linetmp = (Line)ori.GetOffsetCurves(-tk - offset)[0];
                    PL.AddVertexAt(2, linetmp.EndPoint.Convert2D(), 0, 0, 0);
                    PL.AddVertexAt(3, linetmp.StartPoint.Convert2D(), 0, 0, 0);
                }
                PL.Closed = true;
                PL.Layer  = "细线";
                modelSpace.AppendEntity(PL);
                tr.AddNewlyCreatedDBObject(PL, true);


                hat.SetHatchPattern(href.PatternType, href.PatternName);
                modelSpace.AppendEntity(hat);
                tr.AddNewlyCreatedDBObject(hat, true);
                hat.PatternScale = href.PatternScale;
                hat.Layer        = "填充";
                hat.Associative  = true;
                hat.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection {
                    PL.ObjectId
                });
                hat.EvaluateHatch(true);

                hat.PatternScale = href.PatternScale;
                hat.SetHatchPattern(hat.PatternType, hat.PatternName);
                tr.Commit();
            }


            return(PL);
        }
Beispiel #18
0
        public Oid CreateEntity(Database database)
        {
            var exterior = this.exterior;
            var ringType = exterior.Item;

            switch (ringType)
            {
            case LinearRingType lrt:
                DirectPositionListType dplt;
                if ((dplt = lrt.Items[0] as DirectPositionListType) != null)
                {
                    var points = dplt.GetPoints();

                    Point2dCollection points2d = new Point2dCollection();
                    DoubleCollection  dc       = new DoubleCollection();
                    //-1 beacuse the last point is a repetition of first
                    for (int i = 0; i < points.Length; i++)
                    {
                        points2d.Add(points[i].To2D());
                        dc.Add(0.0);
                    }

                    //Polyline pline = new Polyline(points.Length);
                    ////-1 beacuse the last point is a repetition of first
                    //for (int i = 0; i < points.Length - 1; i++)
                    //    pline.AddVertexAt(pline.NumberOfVertices, points[i].To2D(), 0, 0, 0);
                    //pline.Closed = true;
                    //Oid plineId = pline.AddEntityToDbModelSpace(database);

                    Hatch hatch = new Hatch();
                    hatch.Normal       = new Vector3d(0.0, 0.0, 1.0);
                    hatch.Elevation    = 0.0;
                    hatch.PatternScale = 1.0;
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                    Oid hatchId = hatch.AddEntityToDbModelSpace(database);

                    hatch.AppendLoop(HatchLoopTypes.Default, points2d, dc);
                    hatch.EvaluateHatch(true);

                    return(hatchId);
                }
                else
                {
                    throw new System.Exception(
                              $"Unexpected type in PolygonType.exterior.Item.Items[0]: {lrt.Items[0].GetType().Name}");
                }

            case RingType rt:
                throw new System.NotImplementedException();

            default:
                throw new System.Exception($"Unexpected type in PolygonType.exterior.Item: {ringType.GetType().Name}");
            }
        }
Beispiel #19
0
 public static Hatch CreateHatch(this List<Point2d> pts)
 {
     pts = pts.DistinctPoints();
     var ptCol = new Point2dCollection(pts.ToArray());
     ptCol.Add(pts[0]);
     var dCol = new DoubleCollection(new double[pts.Count]);
     var h = new Hatch();
     h.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
     h.AppendLoop(HatchLoopTypes.Default, ptCol, dCol);
     h.EvaluateHatch(false);
     return h;
 }
Beispiel #20
0
        public static void CheckHatch()
        {
            var drawingDb = Application.DocumentManager.MdiActiveDocument.Database;
            var editor    = Application.DocumentManager.MdiActiveDocument.Editor;

            editor.WriteMessage("\n选择一条或几条闭合曲线:\n");
            var result = editor.GetSelection();

            if (result.Status != PromptStatus.OK)
            {
                return;
            }
            var hatchloopIds = result.Value.GetObjectIds();

            using (var transaction = drawingDb.TransactionManager.StartTransaction())
            {
                var modelspaceId = SymbolUtilityServices.GetBlockModelSpaceId(drawingDb);

                Hatch hat = new Hatch();
                hat.SetDatabaseDefaults(drawingDb);
                hat.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
                hat.HatchObjectType = HatchObjectType.HatchObject;

                // Add the hatch to the model space
                // and the transaction
                var      modelspace = (BlockTableRecord)transaction.GetObject(modelspaceId, OpenMode.ForWrite);
                ObjectId hatId      = modelspace.AppendEntity(hat);
                transaction.AddNewlyCreatedDBObject(hat, true);

                // Add the hatch loop and complete the hatch
                hat.Associative  = false;
                hat.PatternScale = 20;
                hat.HatchStyle   = HatchStyle.Normal;
                foreach (ObjectId id in hatchloopIds)
                {
                    var loopType = HatchLoopTypes.Outermost;
                    var entity   = transaction.GetObject(id, OpenMode.ForRead);
                    if (entity is DBText)
                    {
                        loopType = HatchLoopTypes.Textbox;
                    }

                    var ids = new ObjectIdCollection();
                    ids.Add(id);
                    hat.AppendLoop(loopType, ids); // error here....
                }

                hat.EvaluateHatch(true);
                transaction.Commit();
            }
        }
        //[CommandMethod("PGA-Hatch")]
        static public void TestHatch(Polyline poly)
        {
            if (poly == null)
            {
                throw new ArgumentNullException(nameof(poly));
            }

            Document doc = Active.Document;

            global::Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;
            Editor ed = doc.Editor;

            try
            {
                using (Transaction Tx = db.TransactionManager.StartTransaction())
                {
                    ObjectId ModelSpaceId =
                        SymbolUtilityServices.GetBlockModelSpaceId(db);

                    BlockTableRecord btr = Tx.GetObject(ModelSpaceId,
                                                        OpenMode.ForWrite) as BlockTableRecord;



                    ObjectIdCollection ObjIds = new ObjectIdCollection();
                    ObjIds.Add(poly.Id);

                    Hatch    oHatch = new Hatch();
                    Vector3d normal = new Vector3d(0.0, 0.0, 1.0);
                    oHatch.Normal       = normal;
                    oHatch.Elevation    = 0.0;
                    oHatch.PatternScale = 2.0;
                    oHatch.SetHatchPattern(HatchPatternType.PreDefined, "ZIGZAG");
                    oHatch.ColorIndex = poly.Color.ColorIndex;
                    oHatch.Layer      = poly.Layer;

                    btr.AppendEntity(oHatch);
                    Tx.AddNewlyCreatedDBObject(oHatch, true);
                    //this works ok
                    oHatch.Associative = true;
                    oHatch.AppendLoop((int)HatchLoopTypes.Default, ObjIds);
                    oHatch.EvaluateHatch(true);

                    Tx.Commit();
                }
            }
            catch (System.Exception ex)
            {
                // throw;
            }
        }
Beispiel #22
0
        public void Create(Point2d ptCell, [NotNull] BlockTableRecord cs, [NotNull] Transaction t)
        {
            var cellWidth  = ColorBookHelper.CellWidth;
            var cellHeight = ColorBookHelper.CellHeight;
            var margin     = ColorBookHelper.Margin;
            var marginHalf = margin * 0.5;

            var ptText = new Point3d(ptCell.X + cellWidth * 0.5, ptCell.Y - ColorBookHelper.TextHeight - margin, 0);

            var pl = new Polyline(4);

            pl.AddVertexAt(0, new Point2d(ptCell.X + margin, ptText.Y - marginHalf), 0, 0, 0);
            pl.AddVertexAt(1, new Point2d(ptCell.X + cellWidth - margin, ptText.Y - marginHalf), 0, 0, 0);
            pl.AddVertexAt(2, new Point2d(ptCell.X + cellWidth - margin, ptCell.Y - cellHeight + margin), 0, 0, 0);
            pl.AddVertexAt(3, new Point2d(ptCell.X + margin, ptCell.Y - cellHeight + margin), 0, 0, 0);
            pl.Closed = true;
            pl.SetDatabaseDefaults();
            pl.Color = Color;

            cs.AppendEntity(pl);
            t.AddNewlyCreatedDBObject(pl, true);

            var h = new Hatch();

            h.SetDatabaseDefaults();
            h.SetHatchPattern(HatchPatternType.PreDefined, "Solid");
            h.Annotative = AnnotativeStates.False;

            cs.AppendEntity(h);
            t.AddNewlyCreatedDBObject(h, true);

            h.Associative = true;
            h.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection(new[] { pl.Id }));
            h.Color = Color;
            h.EvaluateHatch(true);

            var text = new DBText();

            text.SetDatabaseDefaults();
            text.HorizontalMode = TextHorizontalMode.TextCenter;
            text.Annotative     = AnnotativeStates.False;
            text.Height         = ColorBookHelper.TextHeight;
            text.AlignmentPoint = ptText;
            text.AdjustAlignment(cs.Database);
            text.TextStyleId = ColorBookHelper.IdTextStylePik;
            text.TextString  = Name;

            cs.AppendEntity(text);
            t.AddNewlyCreatedDBObject(text, true);
        }
Beispiel #23
0
        public void AHA()
        {
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

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

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

                using (Polyline polyline = new Polyline())
                {
                    polyline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
                    polyline.AddVertexAt(0, new Point2d(2, 0), 0, 0, 0);
                    polyline.AddVertexAt(0, new Point2d(2, 1), 0, 0, 0);
                    polyline.AddVertexAt(0, new Point2d(0, 1), 0, 0, 0);
                    polyline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);

                    // Add the new circle object to the block table record and the transaction
                    acBlkTblRec.AppendEntity(polyline);
                    acTrans.AddNewlyCreatedDBObject(polyline, true);

                    // Adds the circle to an object id array
                    ObjectIdCollection acObjIdColl = new ObjectIdCollection();
                    acObjIdColl.Add(polyline.ObjectId);

                    // Create the hatch object and append it to the block table record
                    using (Hatch acHatch = new Hatch())
                    {
                        acBlkTblRec.AppendEntity(acHatch);
                        acTrans.AddNewlyCreatedDBObject(acHatch, true);

                        // Set the properties of the hatch object
                        // Associative must be set after the hatch object is appended to the
                        // block table record and before AppendLoop
                        acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
                        acHatch.Associative = true;
                        acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
                        acHatch.EvaluateHatch(true);
                    }
                }

                // Save the new object to the database
                acTrans.Commit();
            }
        }
Beispiel #24
0
        public static Hatch CreateHatch(this List <Point2d> pts)
        {
            pts = pts.DistinctPoints();
            var ptCol = new Point2dCollection(pts.ToArray())
            {
                pts[0]
            };
            var dCol = new DoubleCollection(new double[pts.Count]);
            var h    = new Hatch();

            h.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
            h.AppendLoop(HatchLoopTypes.Default, ptCol, dCol);
            h.EvaluateHatch(false);
            return(h);
        }
Beispiel #25
0
        /// <summary>
        /// 添加圆面域
        /// </summary>
        public static void AddCircleQuyu(int ColorIndex, double B_x, double B_y, double R, string Filltype, Document acDoc, Database acCurDb)
        {
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                //以读打开Block表
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             OpenMode.ForRead) as BlockTable;
                //以写方式打开Block表的Model空间记录
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;

                //创建一个圆作为填充的封闭边界
                using (Circle acCirc = new Circle())
                {
                    acCirc.Center     = new Point3d(B_x, B_y, 0);
                    acCirc.Radius     = R;
                    acCirc.ColorIndex = ColorIndex;
                    //将圆添加到块表记录和事务
                    acBlkTblRec.AppendEntity(acCirc);
                    acTrans.AddNewlyCreatedDBObject(acCirc, true);
                    //将圆的ObjectId添加到对象id数组
                    ObjectIdCollection acObjIdColl = new ObjectIdCollection();
                    acObjIdColl.Add(acCirc.ObjectId);
                    //创建填充对象并添加到块表记录,然后设置其属性

                    using (Hatch acHatch = new Hatch())
                    {
                        acBlkTblRec.AppendEntity(acHatch);
                        acTrans.AddNewlyCreatedDBObject(acHatch, true);

                        // Set the properties of the hatch object
                        // Associative must be set after the hatch object is appended to the
                        // block table record and before AppendLoop
                        acHatch.PatternScale = 6;
                        acHatch.SetHatchPattern(HatchPatternType.PreDefined, Filltype);

                        acHatch.Associative = true;
                        acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
                        acHatch.EvaluateHatch(true);
                        acHatch.ColorIndex = ColorIndex;
                    }
                }
                //保存新对象到数据库
                acTrans.Commit();
            }
        }
Beispiel #26
0
        /// <summary>
        /// Создание ассоциативной штриховки по полилинии
        /// Полилиния должна быть в базе чертежа
        /// </summary>
        public static Hatch?CreateAssociativeHatch(
            [NotNull] Curve loop,
            [NotNull] BlockTableRecord cs,
            [NotNull] Transaction t,
            double scale,
            string pattern           = "SOLID",
            [CanBeNull] string layer = null,
            LineWeight lw            = LineWeight.LineWeight015)
        {
            var h = new Hatch();

            if (layer != null)
            {
                Layers.LayerExt.CheckLayerState(layer);
                h.Layer = layer;
            }

            h.LineWeight   = lw;
            h.Linetype     = SymbolUtilityServices.LinetypeContinuousName;
            h.PatternScale = scale;
            h.SetHatchPattern(HatchPatternType.PreDefined, pattern);
            cs.AppendEntity(h);
            t.AddNewlyCreatedDBObject(h, true);
            h.Associative = true;
            h.HatchStyle  = HatchStyle.Normal;

            // добавление контура полилинии в гштриховку
            var ids = new ObjectIdCollection {
                loop.Id
            };

            try
            {
                h.AppendLoop(HatchLoopTypes.Default, ids);
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex, $"CreateAssociativeHatch");
                h.Erase();
                return(null);
            }

            h.EvaluateHatch(true);
            var orders = (DrawOrderTable)cs.DrawOrderTableId.GetObject(OpenMode.ForWrite);

            orders.MoveToBottom(new ObjectIdCollection(new[] { h.Id }));
            return(h);
        }
Beispiel #27
0
        public void Create(Point2d ptCell, BlockTableRecord cs, Transaction t)
        {
            var cellWidth = ColorBookHelper.CellWidth;
            var cellHeight = ColorBookHelper.CellHeight;
            var margin = ColorBookHelper.Margin;
            var marginHalf = margin * 0.5;

            Point3d ptText = new Point3d(ptCell.X + cellWidth * 0.5, ptCell.Y - ColorBookHelper.TextHeight-margin, 0);

            Polyline pl = new Polyline(4);
            pl.AddVertexAt(0, new Point2d(ptCell.X+margin, ptText.Y- marginHalf), 0, 0, 0);
            pl.AddVertexAt(1, new Point2d(ptCell.X+cellWidth- margin, ptText.Y- marginHalf), 0, 0, 0);
            pl.AddVertexAt(2, new Point2d(ptCell.X + cellWidth-margin, ptCell.Y-cellHeight+margin), 0, 0, 0);
            pl.AddVertexAt(3, new Point2d(ptCell.X+margin, ptCell.Y - cellHeight+margin), 0, 0, 0);
            pl.Closed = true;
            pl.SetDatabaseDefaults();
            pl.Color = Color;

            cs.AppendEntity(pl);
            t.AddNewlyCreatedDBObject(pl, true);

            Hatch h = new Hatch();
            h.SetDatabaseDefaults();
            h.SetHatchPattern(HatchPatternType.PreDefined, "Solid");
            h.Annotative = AnnotativeStates.False;

            cs.AppendEntity(h);
            t.AddNewlyCreatedDBObject(h, true);

            h.Associative = true;
            h.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection(new[] { pl.Id }));
            h.Color = Color;
            h.EvaluateHatch(true);

            DBText text = new DBText();
            text.SetDatabaseDefaults();
            text.HorizontalMode = TextHorizontalMode.TextCenter;
            text.Annotative = AnnotativeStates.False;
            text.Height = ColorBookHelper.TextHeight;
            text.AlignmentPoint = ptText;
            text.AdjustAlignment(cs.Database);
            text.TextStyleId = ColorBookHelper.IdTextStylePik;
            text.TextString = Name;

            cs.AppendEntity(text);
            t.AddNewlyCreatedDBObject(text, true);
        }
Beispiel #28
0
        public void AddHatch()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            //创建一个正六边形
            Polyline polygon = new Polyline();

            polygon.CreatePolygon(new Point2d(500, 200), 6, 30);
            //创建一个圆
            Circle circle = new Circle
            {
                Center = new Point3d(500, 200, 0),
                Radius = 10
            };

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //将正六边形和圆添加到模型空间中
                ObjectId polygonId = db.AddToModelSpace(polygon);
                ObjectId circleId  = db.AddToModelSpace(circle);
                //创建一个ObjectId集合类对象,用于存储填充边界的ObjectId
                ObjectIdCollection ids = new ObjectIdCollection
                {
                    polygonId//将正六边形的ObjectId添加到边界集合中
                };
                Hatch hatch = new Hatch
                {
                    PatternScale = 0.5 //设置填充图案的比例
                };                     //创建填充对象
                //创建填充图案选项板
                HatchPalletteDialog dlg = new HatchPalletteDialog();
                //显示填充图案选项板
                bool isOK = dlg.ShowDialog();
                //如果用户选择了填充图案,则设置填充图案名为所选的图案名,否则为当前图案名
                string patterName = isOK ? dlg.GetPattern() : HatchTools.CurrentPattern;
                //根据上面的填充图案名创建图案填充,类型为预定义,与边界关联
                hatch.CreateHatch(HatchPatternType.PreDefined, patterName, true);
                //为填充添加外边界(正六边形)
                hatch.AppendLoop(HatchLoopTypes.Outermost, ids);
                ids.Clear();       //清空集合以添加新的边界
                ids.Add(circleId); //将圆的ObjectId添加到边界集合中
                //为填充添加内边界(圆)
                hatch.AppendLoop(HatchLoopTypes.Default, ids);
                hatch.EvaluateHatch(true); //计算并显示填充对象
                trans.Commit();            //提交更改
            }
        }
Beispiel #29
0
        public void ViktorSquare()
        {
            CreateLayer($"Square_{i}");
            var form = new VSquare();

            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            Point2d point1 = form.Point1;
            Point2d point2 = form.Point2;
            Point2d point3 = form.Point3;
            Point2d point4 = form.Point4;

            using (var transaction = database.TransactionManager.StartTransaction())
            {
                ObjectIdCollection acObjIdColl = new ObjectIdCollection();
                Hatch acHatch    = new Hatch();
                var   blockTable = (BlockTable)transaction.GetObject(database.BlockTableId, OpenMode.ForRead);
                var   record     = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                using (Polyline square = new Polyline())
                {
                    square.AddVertexAt(0, point1, 0, 0, 0);
                    square.AddVertexAt(1, point2, 0, 0, 0);
                    square.AddVertexAt(2, point3, 0, 0, 0);
                    square.AddVertexAt(3, point4, 0, 0, 0);
                    square.AddVertexAt(4, point1, 0, 0, 0);
                    record.AppendEntity(square);
                    transaction.AddNewlyCreatedDBObject(square, true);
                    acObjIdColl.Add(square.ObjectId);
                    record.AppendEntity(acHatch);
                    transaction.AddNewlyCreatedDBObject(acHatch, true);
                    acHatch.SetDatabaseDefaults();
                    acHatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                    acHatch.Color       = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 255, 255);
                    acHatch.Associative = true;
                    acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
                    acHatch.EvaluateHatch(true);
                }
                transaction.Commit();
                editor.WriteMessage("\n Квадрат создан успешно.");
            }
            i++;
        }
        /// <summary>
        /// 图案填充
        /// </summary>
        /// <param name="db">图形数据库</param>
        /// <param name="loopTypes"></param>
        /// <param name="patternName">图案名称</param>
        /// <param name="scale">填充比例</param>
        /// <param name="degree">旋转角度</param>
        /// <param name="entid">边界图形的ObjectId</param>
        /// <returns></returns>
        public static ObjectId HatchEnity(this Database db, List <HatchLoopTypes> loopTypes, string patternName, double scale, double degree, params ObjectId[] entid) // 一个方法只能传递一个可变参数 且需要放在最后
        {
            ObjectId hatchId = ObjectId.Null;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                // 声明一个图案填充对象
                Hatch hatch = new Hatch();
                // 设置填充比例
                hatch.PatternScale = scale;
                // 设置填充类型和图案名称
                hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANGLE");
                // 加入图形数据库
                BlockTable       bt  = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                hatchId = btr.AppendEntity(hatch);
                trans.AddNewlyCreatedDBObject(hatch, true);

                // 设置填充角度
                hatch.PatternAngle = degree;
                // 设置关联
                hatch.Associative = true;
                // 设置边界图形和填充方式


                ObjectIdCollection obIds = new ObjectIdCollection();
                // 依次添加图形填充样式
                for (int i = 0; i < entid.Length; i++)
                {
                    obIds.Clear();
                    obIds.Add(entid[i]);
                    hatch.AppendLoop(loopTypes[i], obIds);
                }


                // 计算填充并显示
                hatch.EvaluateHatch(true);
                // 提交事务
                trans.Commit();
            }
            return(hatchId);
        }
Beispiel #31
0
        public static Hatch?CreateHatch([CanBeNull] this List <PolylineVertex> pts)
        {
            if (pts?.Any() != true)
            {
                return(null);
            }
            if (!pts[0].Pt.IsEqualTo(pts[pts.Count - 1].Pt))
            {
                pts.Add(pts[0]);
            }

            var ptCol = new Point2dCollection(pts.Select(s => s.Pt).ToArray());
            var dCol  = new DoubleCollection(pts.Select(s => s.Bulge).ToArray());
            var h     = new Hatch();

            h.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
            h.AppendLoop(HatchLoopTypes.Default, ptCol, dCol);
            h.EvaluateHatch(false);
            return(h);
        }
Beispiel #32
0
        /// <summary>
        /// 填充
        /// </summary>
        /// <param name="hatch"></param>
        /// <param name="填充图案名称"></param>
        /// <param name="块表记录"></param>
        /// <param name="tr"></param>
        /// <param name="objectIds"></param>
        public void CreateHatch(string hatchname, BlockTableRecord record, Transaction tr, List <ObjectId> objectIds)
        {
            Hatch hatch = new Hatch();

            record.AppendEntity(hatch);
            tr.AddNewlyCreatedDBObject(hatch, true);
            hatch.SetHatchPattern(HatchPatternType.PreDefined, hatchname);
            hatch.Associative = true;
            ObjectIdCollection ids = new ObjectIdCollection();

            foreach (var id in objectIds)
            {
                ids.Add(id);
                hatch.AppendLoop(HatchLoopTypes.Outermost, ids);
                hatch.EvaluateHatch(true);
                hatch.PatternScale = 1;
                ids.Clear();
            }

            tr.Commit();
        }
Beispiel #33
0
        /// <summary>
        /// Создание ассоциативной штриховки по полилинии
        /// Полилиния должна быть в базе чертежа
        /// </summary>        
        public static Hatch CreateAssociativeHatch(Curve loop, BlockTableRecord cs, Transaction t,
            string pattern = "SOLID", string layer = null, LineWeight lw = LineWeight.LineWeight015)
        {
            var h = new Hatch();
            h.SetDatabaseDefaults();
            if (layer != null)
            {
                Layers.LayerExt.CheckLayerState(layer);
                h.Layer = layer;
            }
            h.LineWeight = lw;
            h.Linetype = SymbolUtilityServices.LinetypeContinuousName;
            h.SetHatchPattern(HatchPatternType.PreDefined, pattern);
            cs.AppendEntity(h);
            t.AddNewlyCreatedDBObject(h, true);
            h.Associative = true;
            h.HatchStyle = HatchStyle.Normal;

            // добавление контура полилинии в гштриховку
            var ids = new ObjectIdCollection();
            ids.Add(loop.Id);
            try
            {
                h.AppendLoop(HatchLoopTypes.Default, ids);
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex, $"CreateAssociativeHatch");
                h.Erase();
                return null;
            }
            h.EvaluateHatch(true);

            var orders = cs.DrawOrderTableId.GetObject(OpenMode.ForWrite) as DrawOrderTable;
            orders.MoveToBottom(new ObjectIdCollection(new[] { h.Id }));

            return h;
        }
Beispiel #34
0
        public void CreateNewHatch(BlockTableRecord btr)
        {
            var h = new Hatch();

             h.Annotative = AnnotativeStates.False;
             h.Layer = Layer;
             h.Color = Color;
             h.LineWeight = Lineweight;
             h.SetHatchPattern(PatternType, PatternName);
             h.PatternAngle = PatternAngle;
             h.PatternScale = PatternScale;
             h.SetHatchPattern(PatternType, PatternName);

             Id = btr.AppendEntity(h);
             btr.Database.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(h, true);

             if (IdsAssociate != null && IdsAssociate.Count > 0)
             {
            h.Associative = true;
            h.AppendLoop(HatchLoopTypes.Default, IdsAssociate);
            h.EvaluateHatch(false);
             }
        }
Beispiel #35
0
        /// <summary>
        /// Generates and adds a series of <see cref="Hatch"/> objects to the supplied <see cref="BlockTableRecord"/>
        /// </summary>
        /// <returns>The selected color as a<see cref="Autodesk.AutoCAD.Colors.Color"/></returns>
        private static void CreateHatchesForConcentricCircles(BlockTableRecord blockTableRecord, ObjectIdCollection objectIdCollection, Transaction transaction)
        {
            var rand = new Random();
            var previousPattern = string.Empty;

            for (var i = 0; i < objectIdCollection.Count - 1; i++)
            {
                var r = Convert.ToByte((i + 1)*rand.Next(0, 25));
                var g = Convert.ToByte((i + 1)*rand.Next(0, 25));
                var b = Convert.ToByte((i + 1)*rand.Next(0, 25));

                using (var hatch = new Hatch())
                {
                    blockTableRecord.AppendEntity(hatch);
                    transaction.AddNewlyCreatedDBObject(hatch, true);

                    var pattern = GetRandomHatchPatternName();

                    //ensure pattern isn't repeated by from previous hatch
                    // in production quality code I would move this behavior to avoid violating SRP/SoC
                    while (pattern.Equals(previousPattern, StringComparison.InvariantCultureIgnoreCase))
                    {
                        pattern = GetRandomHatchPatternName();
                    }

                    previousPattern = pattern;

                    hatch.SetHatchPattern(HatchPatternType.PreDefined, pattern);
                    hatch.Color = Color.FromRgb(r, g, b);

                    // Associative must be set after the hatch object is appended to the block table record and before AppendLoop
                    hatch.Associative = true;

                    // Take the current circle and the next to create a HatchLoop
                    hatch.AppendLoop(HatchLoopTypes.Outermost, new ObjectIdCollection {objectIdCollection[i]});
                    hatch.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection {objectIdCollection[i + 1]});
                    hatch.EvaluateHatch(true);
                }
            }
        }
        private void сreateHatch(Extents3d extText, BlockTableRecord btr)
        {
            if (extText.Diagonal() < 100)
            {
                return;
            }
            // Отступ контура штриховки от границ текста
            Extents3d ext = new Extents3d(new Point3d(extText.MinPoint.X - 10, extText.MinPoint.Y - 10, 0),
                                          new Point3d(extText.MaxPoint.X + 10, extText.MaxPoint.Y + 10, 0));
            var h = new Hatch();
            h.SetDatabaseDefaults(btr.Database);
            if (!panelBtr.CaptionLayerId.IsNull)
                h.LayerId = panelBtr.CaptionLayerId;
            h.LineWeight = LineWeight.LineWeight015;
            h.Linetype = SymbolUtilityServices.LinetypeContinuousName;
            h.Color = Color.FromRgb(250, 250, 250);
            h.Transparency = new Transparency(80);
            h.SetHatchPattern(HatchPatternType.PreDefined, "ANGLE");
            h.PatternScale = 25.0;
            btr.AppendEntity(h);
            var t = btr.Database.TransactionManager.TopTransaction;
            t.AddNewlyCreatedDBObject(h, true);
            h.Associative = true;
            h.HatchStyle = HatchStyle.Normal;

            // Полилиния по контуру текста
            Polyline pl = new Polyline();
            pl.SetDatabaseDefaults(btr.Database);
            pl.LineWeight = LineWeight.LineWeight015;
            pl.Linetype = SymbolUtilityServices.LinetypeContinuousName;
            pl.ColorIndex = 256; // ПоСлою
            if (!panelBtr.CaptionLayerId.IsNull)
                pl.LayerId = panelBtr.CaptionLayerId;
            pl.AddVertexAt(0, ext.MinPoint.Convert2d(), 0, 0, 0);
            pl.AddVertexAt(0, new Point2d(ext.MaxPoint.X, ext.MinPoint.Y), 0, 0, 0);
            pl.AddVertexAt(0, ext.MaxPoint.Convert2d(), 0, 0, 0);
            pl.AddVertexAt(0, new Point2d(ext.MinPoint.X, ext.MaxPoint.Y), 0, 0, 0);
            pl.Closed = true;

            ObjectId idPl = btr.AppendEntity(pl);
            t.AddNewlyCreatedDBObject(pl, true);

            // добавление контура полилинии в гштриховку
            var ids = new ObjectIdCollection();
            ids.Add(idPl);
            h.AppendLoop(HatchLoopTypes.Default, ids);
            h.EvaluateHatch(true);

            // Замена текстов - чтобы они стали поверх штриховки.
            panelBtr.IdCaptionMarkSb = replaceText(panelBtr.IdCaptionMarkSb, btr);
            panelBtr.IdCaptionPaint = replaceText(panelBtr.IdCaptionPaint, btr);
        }
Beispiel #37
0
        public void Figura4()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.GetDocument(db);
            Editor ed = doc.Editor;

            PromptDoubleOptions GetSpindulys = new PromptDoubleOptions("\nĮveskite didžiausio apskritimo spindulį");
            double Spindulys;
            GetSpindulys.AllowNegative = false;
            GetSpindulys.AllowZero = false;
            GetSpindulys.AllowZero = false;
            PromptDoubleResult GetSpindulysRezultatas = ed.GetDouble(GetSpindulys);
            Spindulys = GetSpindulysRezultatas.Value;

            PromptDoubleOptions GetPlotis = new PromptDoubleOptions("\nĮveskite apskirtimo spindulio mažėjimą");
            double Plotis;
            GetPlotis.AllowNegative = false;
            GetPlotis.AllowZero = false;
            GetPlotis.AllowZero = false;
            PromptDoubleResult GetPlotisRezultatas = ed.GetDouble(GetPlotis);
            Plotis = GetPlotisRezultatas.Value;

            PromptPointOptions GetTaskas = new PromptPointOptions("\nPasirinkite centro tašką");
            Point3d Taskas;
            GetTaskas.AllowNone = false;
            PromptPointResult GetTaskasRezultatas = ed.GetPoint(GetTaskas);
            Taskas = GetTaskasRezultatas.Value;

            Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
            {
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                int i = 1;
                while(Spindulys > 0)
                {
                    Circle Apskritimas = new Circle(Taskas, new Vector3d(0, 0, 1), Spindulys);
                    btr.AppendEntity(Apskritimas);
                    tr.AddNewlyCreatedDBObject(Apskritimas, true);

                    Hatch hatch = new Hatch();
                    btr.AppendEntity(hatch);
                    tr.AddNewlyCreatedDBObject(hatch, true);

                    ObjectIdCollection ID = new ObjectIdCollection();
                    ID.Add(Apskritimas.ObjectId);
                    hatch.HatchStyle = HatchStyle.Ignore;
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                    hatch.Associative = true;
                    hatch.AppendLoop(HatchLoopTypes.Outermost, ID);
                    hatch.EvaluateHatch(true);
                    hatch.ColorIndex = i++;

                    Spindulys -= Plotis;
                }
                tr.Commit();
            }
        }
Beispiel #38
0
        public void Figura2()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.GetDocument(db);
            Editor ed = doc.Editor;

            PromptDoubleOptions GetSpindulys = new PromptDoubleOptions("\nĮveskite detalės spindulį");
            double Spindulys;
            GetSpindulys.AllowNegative = false;
            GetSpindulys.AllowZero = false;
            GetSpindulys.AllowNone = false;
            PromptDoubleResult GetSpindulysRezultatas = ed.GetDouble(GetSpindulys);
            Spindulys = GetSpindulysRezultatas.Value;

            PromptPointOptions GetTaskas = new PromptPointOptions("\nPasirinkite centro tašką");
            Point3d Taskas;
            GetTaskas.AllowNone = false;
            PromptPointResult GetTaskasRezultatas = ed.GetPoint(GetTaskas);
            Taskas = GetTaskasRezultatas.Value;

            Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
            {
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);

                //Apskritimas
                Circle Apskritimas = new Circle(Taskas, new Vector3d(0, 0, 1), Spindulys);
                btr.AppendEntity(Apskritimas);
                tr.AddNewlyCreatedDBObject(Apskritimas, true);

                //Linijos
                Polyline3d polyline = new Polyline3d();
                btr.AppendEntity(polyline);
                tr.AddNewlyCreatedDBObject(polyline, true);
                PolylineVertex3d vex3d = new PolylineVertex3d();

                // Linija NR1 (centrine)
                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y + Spindulys / 6, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y - Spindulys / 6, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y - Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y - Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y - Spindulys / 2 + Spindulys / 6, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y - Spindulys / 2 - Spindulys / 6, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y - Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y - Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y - Spindulys / 2 - Spindulys / 1.5, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                polyline = new Polyline3d();
                btr.AppendEntity(polyline);
                tr.AddNewlyCreatedDBObject(polyline, true);

                // Linija NR2 (virsutine)
                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y + Spindulys / 2 + Spindulys / 5, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y + Spindulys / 2 - Spindulys / 5, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y + Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y + Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y + Spindulys / 2 + Spindulys / 1.5, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                polyline = new Polyline3d();
                btr.AppendEntity(polyline);
                tr.AddNewlyCreatedDBObject(polyline, true);

                // Linija NR3 (kaire)
                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 2, Taskas.Y + Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 2, Taskas.Y - Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 2 - Spindulys / 2 - Spindulys / 4, Taskas.Y - Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                //Apskritimas FIll Viduryje
                Circle ApskritimasFillMIni = new Circle(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y - Spindulys / 2, 0), new Vector3d(0, 0, 1), Spindulys / 8);
                btr.AppendEntity(ApskritimasFillMIni);
                tr.AddNewlyCreatedDBObject(ApskritimasFillMIni, true);

                Hatch hatch = new Hatch();
                btr.AppendEntity(hatch);
                tr.AddNewlyCreatedDBObject(hatch, true);

                ObjectIdCollection ID = new ObjectIdCollection();
                ID.Add(ApskritimasFillMIni.ObjectId);
                hatch.HatchStyle = HatchStyle.Ignore;
                hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                hatch.Associative = true;
                hatch.AppendLoop(HatchLoopTypes.Outermost, ID);
                hatch.EvaluateHatch(true);

                //Trikampis
                Solid trikampis = new Solid(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y, 0), new Point3d(Taskas.X, Taskas.Y + Spindulys / 6, 0), new Point3d(Taskas.X, Taskas.Y - Spindulys / 6, 0));
                btr.AppendEntity(trikampis);
                tr.AddNewlyCreatedDBObject(trikampis, true);

                tr.Commit();
            }
        }