- 积分
- 162
- 明经币
- 个
- 注册时间
- 2015-4-14
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2015-5-11 14:12:57
|
显示全部楼层
public ObjectId MakeDoor()
{
ObjectId blockId;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
Point3d pt1 = Point3d.Origin;
Line bottomLine = new Line(pt1, pt1.PolarPoint(0, 0.3));
Line bottomLine1 = new Line(pt1,pt1.PolarPoint(0,-0.3));
blockId = db.AddBlockTableRecord("DOOR", bottomLine, bottomLine1);
trans.Commit();
}
return blockId;
}
AttributeDefinition attHeight;
AttributeDefinition attStyle;
public void AddDoor()
{
Database db = HostApplicationServices.WorkingDatabase;
ObjectId blockId = MakeDoor();//创建表示门的DOOR块定义
using (Transaction trans = db.TransactionManager.StartTransaction())
{
//表示门符号的属性定义
AttributeDefinition attSYM = new AttributeDefinition(Point3d.Origin, "1", "CBR", "输入门的符号", ObjectId.Null);
//设置属性定义的通用样式
SetStyleForAtt(attSYM, false);
//设置属性的对齐点
attSYM.AlignmentPoint = new Point3d(0.0, 0.15, 0.0);
//表示门宽度的属性定义
AttributeDefinition attWidth = new AttributeDefinition(Point3d.Origin, "1m", "DKSBM", "输入门的宽度", ObjectId.Null);
SetStyleForAtt(attWidth, false);
attWidth.AlignmentPoint = new Point3d(0.0, -0.15, 0.0);
//表示门高度的属性定义
attHeight = new AttributeDefinition(Point3d.Origin, "2m", "DKMC", "输入门的高度", ObjectId.Null);
SetStyleForAtt(attHeight, false );
attHeight.AlignmentPoint = new Point3d(0.0, 0.35, 0.0);
// attHeight.Visible = false;
//表示门宽式样的属性定义
attStyle = new AttributeDefinition(Point3d.Origin, "TWO PANEL", "AREA", "输入门的式样", ObjectId.Null);
SetStyleForAtt(attStyle, false );
attStyle.AlignmentPoint = new Point3d(0.7, 0.0, 0.0);
blockId.AddAttsToBlock(attSYM, attWidth, attHeight,attStyle);
trans.Commit();
}
}
private void SetStyleForAtt(AttributeDefinition att, bool invisible)
{
att.Height = 0.15;//属性文字的高度
//属性文字的水平对齐方式为居中
att.HorizontalMode = TextHorizontalMode.TextCenter;
//属性文字的垂直对齐方式为居中
att.VerticalMode = TextVerticalMode.TextVerticalMid;
att.Invisible = invisible; //属性文字的可见性
}
[CommandMethod("InsertDkbs")]
public void InsertDkbs()
{
ObjectId id = MakeDoor();
AddDoor();
//adKzsx(id);
Point3d pt = Pick1("\n指定位置");
Line li = new Line(pt, new Point3d(0, 0, 0));
String cbf = GetString("\n名字");
String dksbm = GetString("\n编号");
Database db = HostApplicationServices.WorkingDatabase;
ObjectId spaceId = db.CurrentSpaceId;//获取当前空间(模型空间或图纸空间)
using (Transaction trans = db.TransactionManager.StartTransaction())
{
//表示属性的字典对象
Dictionary<string, string> atts = new Dictionary<string, string>();
atts.Add("CBR", cbf);
atts.Add("DKSBM", dksbm);
atts.Add("DKMC", "");
atts.Add("AREA", "");
//在当前空间加入块参照
ObjectId obj = spaceId.InsertBlockReference("0", "DOOR", pt, new Scale3d(2), 0, atts);
adKzsx(obj);
trans.Commit();
}
}
[CommandMethod("addeDKMC")]
public void addeDKMC()
{
string dkmc;
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
//提示用户选择要更新的块
PromptEntityOptions opt = new PromptEntityOptions("请选择一个块参数");
opt.SetRejectMessage("你选择的不是块");
opt.AddAllowedClass(typeof(BlockReference), true);
PromptEntityResult result = ed.GetEntity(opt);
if (result.Status != PromptStatus.OK) return;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
ObjectId obj = result.ObjectId;
Entity ent = null;
ent = (Entity)trans.GetObject(obj, OpenMode.ForRead);
ResultBuffer resBuf5 = ent.GetXDataForApplication("DKMC");
if (resBuf5 != null)
{
System.Collections.IEnumerator iter = resBuf5.GetEnumerator();
while (iter.MoveNext())
{
TypedValue tmpVal = (TypedValue)iter.Current;
dkmc = tmpVal.Value.ToString();
Dictionary<string, string> atts = new Dictionary<string, string>();
atts.Add("DKMC", dkmc);
result.ObjectId.UpdateAttributesInBlock(atts);
}
}
trans.Commit();
}
}
[CommandMethod("addeArea")]
public void addeArea()
{
string area;
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
//提示用户选择要更新的块
PromptEntityOptions opt = new PromptEntityOptions("请选择一个块参数");
opt.SetRejectMessage("你选择的不是块");
opt.AddAllowedClass(typeof(BlockReference), true);
PromptEntityResult result = ed.GetEntity(opt);
if (result.Status != PromptStatus.OK) return;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
ObjectId obj = result.ObjectId;
Entity ent = null;
ent = (Entity)trans.GetObject(obj, OpenMode.ForRead);
ResultBuffer resBuf7 = ent.GetXDataForApplication("Area");
if (resBuf7 != null)
{
System.Collections.IEnumerator iter = resBuf7.GetEnumerator();
while (iter.MoveNext())
{
TypedValue tmpVal = (TypedValue)iter.Current;
area = tmpVal.Value.ToString();
Dictionary<string, string> atts = new Dictionary<string, string>();
atts.Add("AREA", area );
result.ObjectId.UpdateAttributesInBlock(atts);
}
}
trans.Commit();
}
}
群里的大哥帮忙发的菜鸟的代码,根据这代码改好了。可以实现这些功能了,要用到菜鸟书里的DotNetARX.dll,我已经买了他的书了,很好狠强大, |
|