- 积分
- 381
- 明经币
- 个
- 注册时间
- 2013-9-13
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
下列代码是想实现 先删除一条直线再画一条包含文本的复杂AutoCAD线型 的直线,可是代码执行后还是一条直线没有显示包含文本的复杂AutoCAD线型 ,求高手看看
private void btn_addlinetype_Click(object sender, EventArgs e)
{
try
{
if (txt_LineContent.Text != "")
{
MessageBox.Show("请在AutoCAD2010 中选择要修改的线段,选择完成后请单击---鼠标右键---返回界面", "选择线段", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.WindowState = FormWindowState.Minimized;// goto跳回语句
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
using (Transaction trans = doc.TransactionManager.StartTransaction())
{
Loop: PromptSelectionResult psr = ed.GetSelection();
if (psr.Status == PromptStatus.OK)
{
if (MessageBox.Show("是否确定选择线段?是 表示确定,否 表示重新选择!", "选择提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
goto Loop;//goto跳回到选择点
}
if (psr.Value.Count == 1)
{
foreach (ObjectId GetSelectId in psr.Value.GetObjectIds())
{
Entity ent = trans.GetObject(GetSelectId, OpenMode.ForWrite) as Entity;
string TypeName = ent.GetType().Name.ToString();
if (TypeName == "Line")
{
Line ln = ent as Line;
StartPoint = ln.StartPoint;
EndPoint = ln.EndPoint;
ent.Erase();
ed.UpdateScreen();
}
}
}
else
{
MessageBox.Show("不能选择多条线段或者不选,只能选择一条,请重新选择", "选择线段", MessageBoxButtons.OK, MessageBoxIcon.Information);
ed.UpdateScreen();
goto Loop;//goto跳回到选择点
}
}
trans.Commit();
ed.UpdateScreen();
//ObjectId ltId = m_LoadLineTypeName(ed, "ZIGZAG");
CreateComplexLinetype(doc, ed);
this.Show();
}
docLock.Dispose();
}
else
{
MessageBox.Show("线型内容不能为空,请输入内容!", "输入线型内容", MessageBoxButtons.OK, MessageBoxIcon.Information);
txt_LineContent.Focus();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Point3d StartPoint=new Point3d();
Point3d EndPoint = new Point3d();
public void CreateComplexLinetype(Document doc, Editor ed)
{
try
{
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// 我们使用文本样式表来访问"Standard"文本样式,用于文本部分
TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
// 获取线型表
LinetypeTable lt = (LinetypeTable)tr.GetObject(db.LinetypeTableId, OpenMode.ForWrite, true);
// 创建新的线型表记录...
LinetypeTableRecord ltr = new LinetypeTableRecord();
// ... 设置线型表记录的属性
ltr.Name = "COLD_WATER_SUPPLY";
ltr.AsciiDescription =
"Cold water supply ---- RS ---- RS ---- RS ----";
ltr.PatternLength = 0.9;
ltr.NumDashes = 3;
// 短划线 #1
ltr.SetDashLengthAt(0, 0.5);
// 短划线 #2
ltr.SetDashLengthAt(1, -0.2);
ltr.SetShapeStyleAt(1, tt["Standard"]);
ltr.SetShapeNumberAt(1, 0);
ltr.SetShapeOffsetAt(1, new Vector2d(-0.1, -0.05));
ltr.SetShapeScaleAt(1, 0.1);
ltr.SetShapeIsUcsOrientedAt(1, false);
ltr.SetShapeRotationAt(1, 0);
ltr.SetTextAt(1, "RS");
// 短划线 #3
ltr.SetDashLengthAt(2, -0.2);
// 把新线型添加到线型表
ObjectId ltId = lt.Add(ltr);
tr.AddNewlyCreatedDBObject(ltr, true);
// 使用这个线型创建一条测试直线
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
Line line = new Line(StartPoint,EndPoint);
line.SetDatabaseDefaults(db);
line.LinetypeId = ltId;
btr.AppendEntity(line);
tr.AddNewlyCreatedDBObject(line, true);
tr.Commit();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
|
|