Example #1
0
        /// <summary>
        /// 创建填充。
        /// </summary>
        /// <param name="pattern"></param>
        /// <param name="loops"></param>
        /// <param name="type"></param>
        /// <param name="scale"></param>
        /// <param name="otherSetting"></param>
        /// <param name="db"></param>
        /// <param name="space"></param>
        /// <returns></returns>
        public static ObjectId CreateHatch(string pattern, ObjectIdCollection loops,
                                           HatchPatternType type       = HatchPatternType.PreDefined, double scale = 1,
                                           Action <Hatch> otherSetting = null, string space = null)
        {
            var hatch = new Hatch();
            var id    = hatch.ToSpace(loops[0].Database, space);

            using (var trans = id.Database.TransactionManager.StartTransaction())
            {
                hatch = trans.GetObject(id, OpenMode.ForWrite) as Hatch;

                hatch.PatternScale = scale;
                hatch.SetHatchPattern(type, pattern);

                foreach (ObjectId loopId in loops)
                {
                    hatch.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection()
                    {
                        loopId
                    });
                }

                otherSetting?.Invoke(hatch);
                trans.Commit();
            }

            return(id);
        }
Example #2
0
        /// <summary>
        /// 创建填充。
        /// </summary>
        /// <param name="pattern"></param>
        /// <param name="loops"></param>
        /// <param name="type"></param>
        /// <param name="scale"></param>
        /// <param name="otherSetting"></param>
        /// <param name="db"></param>
        /// <param name="space"></param>
        /// <returns></returns>
        public static ObjectId CreateHatch(string pattern, Polyline[] loops,
                                           HatchPatternType type       = HatchPatternType.PreDefined, double scale = 1,
                                           Action <Hatch> otherSetting = null, Database db = null, string space = null)
        {
            var hatch = new Hatch();
            var id    = hatch.ToSpace(db, space);

            using (var trans = id.Database.TransactionManager.StartTransaction())
            {
                hatch = trans.GetObject(id, OpenMode.ForWrite) as Hatch;

                hatch.PatternScale = scale;
                hatch.SetHatchPattern(type, pattern);

                foreach (var loop in loops)
                {
                    var hatchLoop = new HatchLoop(HatchLoopTypes.Polyline);
                    for (var i = 0; i < loop.NumberOfVertices; i++)
                    {
                        hatchLoop.Polyline.Add(
                            new BulgeVertex(loop.GetPoint2dAt(i), loop.GetBulgeAt(i)));
                    }
                    hatch.AppendLoop(hatchLoop);
                }

                otherSetting?.Invoke(hatch);
                trans.Commit();
            }

            return(id);
        }
 // 由边界对象集合数组、图案填充类型、填充图案名称、填充角度和填充比例创建图案填充的函数.
 // partType:0为预定义图案;1为用户定义图案;2为自定义图案.
 public static ObjectId AddHatch(ObjectIdCollection[] objIds, HatchPatternType patType, string patName, double patternAngle, double patternScale)
 {
     try
     {
         Hatch ent = new Hatch();
         ent.HatchObjectType = HatchObjectType.HatchObject;
         Database db = HostApplicationServices.WorkingDatabase;
         using (Transaction trans = db.TransactionManager.StartTransaction())
         {
             BlockTable       bt    = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
             BlockTableRecord btr   = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
             ObjectId         entId = btr.AppendEntity(ent);
             trans.AddNewlyCreatedDBObject(ent, true);
             ent.PatternAngle = patternAngle;
             ent.PatternScale = patternScale;
             ent.SetHatchPattern(patType, patName);
             ent.Associative = true;
             for (int i = 0; i < objIds.Length; i++)
             {
                 ent.InsertLoopAt(i, HatchLoopTypes.Default, objIds[i]);
             }
             trans.Commit();
             return(entId);
         }
     }
     catch
     {
         ObjectId nullId = ObjectId.Null;
         return(nullId);
     }
 }
Example #4
0
        // 由图案填充类型、填充图案名称、
        // 填充角度和填充比例创建图案填充的函数.
        // partType:0为预定义图案;1为用户定义图案;2为自定义图案.
        private ObjectId AddHatch(out Hatch hatchEnt, HatchPatternType patType,
                                  String patName, Double patternAngle, Double patternScale)
        {
            Hatch ent = new Hatch();

            ent.HatchObjectType = HatchObjectType.HatchObject;
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)trans.GetObject
                                    (db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject
                                           (bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                ObjectId entId = btr.AppendEntity(ent);
                trans.AddNewlyCreatedDBObject(ent, true);
                ent.SetDatabaseDefaults();
                ent.PatternAngle = patternAngle;
                ent.PatternScale = patternScale;
                ent.SetHatchPattern(patType, patName);
                hatchEnt = ent;
                trans.Commit();
                return(entId);
            }
        }
Example #5
0
        public static void CreateHatch(this Hatch hatch, HatchPatternType type, string patternName, bool associative)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            hatch.SetDatabaseDefaults();
            hatch.SetHatchPattern(type, patternName);
            hatch.Associative = associative ? true : false;
        }
Example #6
0
        /// <summary>
        /// 创建图案填充
        /// </summary>
        /// <param name="hatch">填充对象</param>
        /// <param name="patternType">填充图案类型</param>
        /// <param name="patternName">填充图案名</param>
        /// <param name="associative">填充是否与边界关联</param>
        public static void CreateHatch(this Hatch hatch, HatchPatternType patternType, string patternName, bool associative)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            hatch.SetDatabaseDefaults();//设置填充的默认值
            //设置填充的类型和填充图案名
            hatch.SetHatchPattern(patternType, patternName);
            db.AddToModelSpace(hatch);//将填充添加到模型空间
            //设置填充与边界是否关联
            hatch.Associative = associative ? true : false;
        }
Example #7
0
 public HatchInfo(Hatch h)
 {
     Id = h.Id;
     if (h.Associative)
     {
         IdsAssociate = h.GetAssociatedObjectIds();
     }
     PatternName  = h.PatternName;
     PatternScale = h.PatternScale;
     PatternAngle = h.PatternAngle;
     PatternType  = h.PatternType;
     Layer        = h.Layer;
     Color        = h.Color;
     Lineweight   = h.LineWeight;
 }