- UID
- 14
- 积分
- 8264
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-4
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
How to create MLeader objects in .Net? By Philippe Leefsma
Below are two samples that illustrates MLeader creation in C#:
The first creates a MLeader with a MText content:
- [CommandMethod("netTextMLeader")]
- public static void netTextMLeader()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- using (Transaction Tx = db.TransactionManager.StartTransaction())
- {
- BlockTable table = Tx.GetObject(
- db.BlockTableId,
- OpenMode.ForRead)
- as BlockTable;
- BlockTableRecord model = Tx.GetObject(
- table[BlockTableRecord.ModelSpace],
- OpenMode.ForWrite)
- as BlockTableRecord;
- MLeader leader = new MLeader();
- leader.SetDatabaseDefaults();
- leader.ContentType = ContentType.MTextContent;
- MText mText = new MText();
- mText.SetDatabaseDefaults();
- mText.Width = 100;
- mText.Height = 50;
- mText.SetContentsRtf("MLeader");
- mText.Location = new Point3d(4, 2, 0);
- leader.MText = mText;
- int idx = leader.AddLeaderLine(new Point3d(1, 1, 0));
- leader.AddFirstVertex(idx, new Point3d(0, 0, 0));
- model.AppendEntity(leader);
- Tx.AddNewlyCreatedDBObject(leader, true);
- Tx.Commit();
- }
- }
-
he second creates a MLeader with a Block content. It also handles the case where the MLeader block contains attributes and set them to a default value:
- [CommandMethod("netBlockMLeader")]
- public static void netBlockMLeader()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- using (Transaction Tx = db.TransactionManager.StartTransaction())
- {
- BlockTable table = Tx.GetObject(
- db.BlockTableId,
- OpenMode.ForRead)
- as BlockTable;
- BlockTableRecord model = Tx.GetObject(
- table[BlockTableRecord.ModelSpace],
- OpenMode.ForWrite)
- as BlockTableRecord;
- if (!table.Has("BlkLeader"))
- {
- ed.WriteMessage(
- "\nYou need to define a \"BlkLeader\" first...");
- return;
- }
- MLeader leader = new MLeader();
- leader.SetDatabaseDefaults();
- leader.ContentType = ContentType.BlockContent;
- leader.BlockContentId = table["BlkLeader"];
- leader.BlockPosition = new Point3d(4, 2, 0);
- int idx = leader.AddLeaderLine(new Point3d(1, 1, 0));
- leader.AddFirstVertex(idx, new Point3d(0, 0, 0));
- //Handle Block Attributes
- int AttNumber = 0;
- BlockTableRecord blkLeader = Tx.GetObject(
- leader.BlockContentId,
- OpenMode.ForRead)
- as BlockTableRecord;
- //Doesn't take in consideration oLeader.BlockRotation
- Matrix3d Transfo = Matrix3d.Displacement(
- leader.BlockPosition.GetAsVector());
- foreach (ObjectId blkEntId in blkLeader)
- {
- AttributeDefinition AttributeDef = Tx.GetObject(
- blkEntId,
- OpenMode.ForRead)
- as AttributeDefinition;
- if (AttributeDef != null)
- {
- AttributeReference AttributeRef =
- new AttributeReference();
- AttributeRef.SetAttributeFromBlock(
- AttributeDef,
- Transfo);
- AttributeRef.Position =
- AttributeDef.Position.TransformBy(Transfo);
- AttributeRef.TextString = "Attrib #" + (++AttNumber);
- leader.SetBlockAttribute(blkEntId, AttributeRef);
- }
- }
- model.AppendEntity(leader);
- Tx.AddNewlyCreatedDBObject(leader, true);
- Tx.Commit();
- }
- }
|
评分
-
查看全部评分
|