赞
踩
什么是块?
块由多个在逻辑上相关的图形对象所定义的整体。
块的优点有哪些
统一作业标准、提高作业效率
压缩图形文件
便于修改和维护
块的分类
块的分类
简单块、属性块、动态块
块的操作主要由哪些?
块的定义(命令Block)
块的插入(命令Insert)
块的编辑
块的操作方法
块是存储于块表记录中的实体对象集合;模型空间是存储于块表记录中的一种特殊的块;普通块中实体操作方法与模型空间中实体操作一致。
6.如何用程序来定义块
[CommandMethod("blockCreate02")] public void BlockCreate02() { AddEntityByDB aedb = new AddEntityByDB(); Database db = HostApplicationServices.WorkingDatabase; String blockName = "door"; List<Entity> list = new List<Entity>(); //创建图形,设置门框的左边线 Point3d pt1 = Point3d.Origin; Point3d pt2 = new Point3d(0, 1, 0); Point3d pt3 = new Point3d(1, 0, 0); Line leftLine = new Line(pt1, pt2); Line rightLine = new Line(pt1, pt3); Arc arc = new Arc(new Point3d(0, 0, 0), 1, 0, Math.PI / 2.0); list.Add(leftLine); list.Add(rightLine); list.Add(arc); //调用抽取的公共代码块 AddBlockThroughDB(db, blockName, list); } /** * 以事务的方式,创建块对象 * */ public void AddBlockThroughDB(Database db, String blockName, List<Entity> ents) { Transaction trans = db.TransactionManager.StartTransaction(); BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForWrite); if (!bt.Has(blockName)) { BlockTableRecord btr = new BlockTableRecord(); btr.Name = blockName; for (int ii = 0; ii < ents.Count; ii++) { Entity ent = ents[ii]; btr.AppendEntity(ent); } bt.Add(btr); trans.AddNewlyCreatedDBObject(btr, true); trans.Commit(); } }
[CommandMethod("InsertDoor")] public void InsertDoor() { Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead); BlockTableRecord space = db.CurrentSpaceId.GetObject(OpenMode.ForWrite) as BlockTableRecord; //判断名为“door”的块是否存在 if(! bt["door"].IsNull) { BlockReference br = new BlockReference(Point3d.Origin, bt["door"]); br.ScaleFactors = new Scale3d(2.0);//设置尺寸为原来2倍 space.AppendEntity(br); trans.AddNewlyCreatedDBObject(br, true); trans.Commit(); } else { return; } } }
软件中的属性块操作
1)属性的模式(可见方式、验证方式等)
2)属性提示
3)属性标签名(Tag)
4)属性的默认值
5)属性文字的插入点、宽高度、旋转角、对齐
属性字段的定义步骤
1)创建AttributeDefinition对象,并设置属性值。
2)将创建的属性字段作为块中的实体,通过块表记录类的成员函数AppendEntity 将其附加到块表记录中。
属性块的定义实现代码
[CommandMethod("makeAttDoor")] public void makeAttDoor() { Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord btr = new BlockTableRecord(); btr.Name = "DOOR"; Line line = new Line(new Point3d(0, 0, 0), new Point3d(0, 1, 0)); Arc arc = new Arc(new Point3d(0, 0, 0), 1, 0, Math.PI / 2.0); btr.AppendEntity(line); btr.AppendEntity(arc); //属性添加 AttributeDefinition cjAd = new AttributeDefinition(Point3d.Origin, "喜临门", "厂家", "请输入厂家", ObjectId.Null); AttributeDefinition jgAd = new AttributeDefinition(Point3d.Origin + new Vector3d(0, 0.25, 0), "2000", "价格", "请输入价格", ObjectId.Null); cjAd.Height = 0.15; jgAd.Height = 0.15; btr.AppendEntity(cjAd); btr.AppendEntity(jgAd); bt.Add(btr); trans.AddNewlyCreatedDBObject(btr, true); trans.Commit(); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。