请大虾帮忙看看属性块的属性设置问题
private void button3_Click_1(object sender, EventArgs e){
Database db = HostApplicationServices.WorkingDatabase;
ObjectId blkid;
//外框长度
int ol = 0;
//外框高度
int ow = 0;
//内框长度
int il = 0;
//内框高度
int iw = 0;
//内外框距
int oi = 0;
//装订边距
int CON_ZD = 25;
//反签区边框
int CON_FL = 120;
int CON_FW = 24;
//创建块定义
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord btr = new BlockTableRecord();
btr.Name = "CNPTDwgFrameBlock";
if (comboBox1.Text == "A1")
{
ol = 1189;
ow = 841;
}
//下外框
Line line1 = new Line(new Point3d(), new Point3d(ol, 0, 0));
//需要先定义图层?
//line1.Layer = "AM_BOR";
btr.AppendEntity(line1);
//左外框
Line line2 = new Line(new Point3d(), new Point3d(0, ow, 0));
btr.AppendEntity(line2);
//上外框
Line line3 = new Line(new Point3d(0, ow, 0), new Point3d(ol, ow, 0));
btr.AppendEntity(line3);
//右外框
Line line4 = new Line(new Point3d(ol, 0, 0), new Point3d(ol, ow, 0));
btr.AppendEntity(line4);
if (comboBox1.Text == "A1")
{
oi = 10;
il = 1189 - oi - CON_ZD;
iw = 841 - oi * 2;
}
//下内框
Line line5 = new Line(new Point3d(CON_ZD, oi, 0), new Point3d(CON_ZD + il, oi, 0));
btr.AppendEntity(line5);
//左内框
Line line6 = new Line(new Point3d(CON_ZD, oi, 0), new Point3d(CON_ZD, oi + iw, 0));
btr.AppendEntity(line6);
//上内框
Line line7 = new Line(new Point3d(CON_ZD, oi + iw, 0), new Point3d(CON_ZD + il, oi + iw, 0));
btr.AppendEntity(line7);
//右内框
Line line8 = new Line(new Point3d(CON_ZD + il, oi, 0), new Point3d(CON_ZD + il, oi + iw, 0));
btr.AppendEntity(line8);
//反签区
//下边框
Line line9 = new Line(new Point3d(CON_ZD, oi + iw - CON_FW, 0), new Point3d(CON_ZD + CON_FL, oi + iw - CON_FW, 0));
btr.AppendEntity(line9);
//右边框
Line line10 = new Line(new Point3d(CON_ZD + CON_FL, oi + iw - CON_FW, 0), new Point3d(CON_ZD + CON_FL, oi + iw, 0));
btr.AppendEntity(line10);
//反签区内容
AttributeDefinition ad = new AttributeDefinition();
ad.Constant = false;
ad.Tag = "The Sign Area";
ad.Prompt = "反签区";
ad.TextString = "反签区Value";
ad.Position = new Point3d(CON_ZD + CON_FL, oi + iw, 0);
ad.Height = 22;
ad.Rotation = 180;
btr.AppendEntity(ad);
//添加块表记录到块表
blkid = bt.Add(btr);
trans.AddNewlyCreatedDBObject(btr, true);
trans.Commit();
}
// 创建块参照
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord mbtr = trans.GetObject(bt,OpenMode.ForWrite) as BlockTableRecord;
BlockTableRecord btr = trans.GetObject(blkid, OpenMode.ForRead) as BlockTableRecord;
// 通过块定义添加块参照
BlockReference br = new BlockReference(new Point3d(0, 0, 0), blkid);
/**/
/**/
//把块参照添加到块表记录
Object blkrefid = mbtr.AppendEntity(br);
/**/
foreach (ObjectId id in btr)
{
if (id.ObjectClass.Equals(RXClass.GetClass(typeof(AttributeDefinition))))
{
AttributeDefinition ad = trans.GetObject(id, OpenMode.ForRead) as AttributeDefinition;
AttributeReference ar = new AttributeReference(ad.Position, ad.TextString, ad.Tag, new ObjectId());
br.AttributeCollection.AppendAttribute(ar);
}
}
/**/
// 通过事务添加块参照到数据库
trans.AddNewlyCreatedDBObject(br, true);
/**/
/**/
trans.Commit();
}
//自动缩放至显示全部图形
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
doc.SendStringToExecute("'_zoom _e\n", false, false, true);
//关闭对话窗口
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
//问题:属性块的内容虽然显示出来了,但是属性块的文字没有按照我设定的高度和角度显示。
正确的
错误的
问题已解决,请看我的另一个帖子《请教关于C#开发ACAD2010生成的属性块显示延迟的问题》
页:
[1]