public void AddMLeader() { Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { //创建3个点,分别表示引线的终点和两个头点 Point3d ptEnd = new Point3d(90, 0, 0); Point3d pt1 = new Point3d(80, 20, 0); Point3d pt2 = new Point3d(100, 20, 0); MText mtext = new MText { Contents = "多重引线示例" //文本内容 }; //新建多行文本 MLeader mleader = new MLeader(); //创建多重引线 //为多重引线添加引线束,引线束由基线和一些单引线构成 int leaderIndex = mleader.AddLeader(); //在引线束中添加一单引线 int lineIndex = mleader.AddLeaderLine(leaderIndex); mleader.AddFirstVertex(lineIndex, pt1); //在单引线中添加引线头点 mleader.AddLastVertex(lineIndex, ptEnd); //在单引线中添加引线终点 //在引线束中再添加一单引线,并只设置引线头点 lineIndex = mleader.AddLeaderLine(leaderIndex); mleader.AddFirstVertex(lineIndex, pt2); //设置多重引线的注释为多行文本 mleader.ContentType = ContentType.MTextContent; mleader.MText = mtext; //将多重引线添加到模型空间 db.AddToModelSpace(mleader); trans.Commit(); } }
/// <summary> /// Create an AutoCAD's MLeader's object by two points and text's string /// </summary> /// <param name="place_point"></param> /// <param name="leader_line_start"></param> /// <param name="leader_text"></param> /// <param name="text_width"></param> /// <param name="text_height"></param> public static void CreateMLeaderByPoint(Autodesk.AutoCAD.DynamoNodes.Document doc_dyn, ds.Point place_point, ds.Point leader_line_start, string leader_text, double TextRotation = 0d, double LandingGap = 0.04, double text_width = 5, double text_height = 0.2, double arrow_size = 0.5) { /* Help docs * http://bushman-andrey.blogspot.com/2013/01/blog-post.html * https://adn-cis.org/kak-sozdat-multivyinosku-v-.net.html * https://adn-cis.org/forum/index.php?topic=10503.msg49118#msg49118 */ Document doc = doc_dyn.AcDocument; //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(); var temp_leader = leader.AddLeader(); //leader.SetArrowSize(0, arrow_size); leader.ArrowSize = arrow_size; leader.AddLeaderLine(temp_leader); leader.AddFirstVertex(temp_leader, new Point3d(place_point.X, place_point.Y, 0.0)); leader.AddLastVertex(temp_leader, new Point3d(leader_line_start.X, leader_line_start.Y, 0.0)); leader.SetDatabaseDefaults(); leader.ContentType = ContentType.MTextContent; leader.SetTextAttachmentType( Autodesk.AutoCAD.DatabaseServices.TextAttachmentType.AttachmentBottomLine, Autodesk.AutoCAD.DatabaseServices.LeaderDirectionType.LeftLeader); MText mText = new MText(); mText.SetDatabaseDefaults(); mText.Width = text_width; mText.Height = text_height; mText.SetContentsRtf(leader_text); mText.Rotation = TextRotation; leader.MText = mText; leader.LandingGap = LandingGap; mText.BackgroundFill = false; model.AppendEntity(leader); Tx.AddNewlyCreatedDBObject(leader, true); Tx.Commit(); } }
public void AddRoadMLeader() { Database db = HostApplicationServices.WorkingDatabase; //获取符号为点的箭头块的ObjectId ObjectId arrowId = db.GetArrowObjectId(DimArrowBlock.Dot); //如果当前图形中还未加入上述箭头块,则加入并获取其ObjectId if (arrowId == ObjectId.Null) { DimTools.ArrowBlock = DimArrowBlock.Dot; arrowId = db.GetArrowObjectId(DimArrowBlock.Dot); } //创建一个点列表,在其中添加4个要标注的点 List <Point3d> pts = new List <Point3d>(); pts.Add(new Point3d(150, 0, 0)); pts.Add(new Point3d(150, 15, 0)); pts.Add(new Point3d(150, 18, 0)); pts.Add(new Point3d(150, 20, 0)); //各标注点对应的文字 List <string> contents = new List <string> { "道路中心线", "机动车道", "人行道", "绿化带" }; using (Transaction trans = db.TransactionManager.StartTransaction()) { for (int i = 0; i < pts.Count; i++) //遍历标注点 { MText txt = new MText(); //创建多行文本 txt.Contents = contents[i]; //文本内容 MLeader mleader = new MLeader(); //创建多重引线 //为多重引线添加引线束,引线束由基线和一些单引线构成 int leaderIndex = mleader.AddLeader(); //在引线束中添加一单引线,并设置引线头点和终点 int lineIndex = mleader.AddLeaderLine(leaderIndex); mleader.AddFirstVertex(lineIndex, pts[i]); mleader.AddLastVertex(lineIndex, pts[0].PolarPoint(Math.PI / 2, 20 + (i + 1) * 5)); mleader.ArrowSymbolId = arrowId;//设置单引线的箭头块ObjectId //设置多重引线的注释为多行文本 mleader.ContentType = ContentType.MTextContent; mleader.MText = txt; db.AddToModelSpace(mleader); mleader.ArrowSize = 1; //多重引线箭头大小 mleader.DoglegLength = 0; //多重引线基线长度设为0 //将基线连接到引线文字的下方并且绘制下划线 mleader.TextAttachmentType = TextAttachmentType.AttachmentBottomLine; } trans.Commit(); } }
public MLeaderJig(string contents) : base(new MLeader()) { // Store the string passed in m_contents = contents; // Create a point collection to store our vertices m_pts = new Point3dCollection(); // Create mleader and set defaults MLeader ml = Entity as MLeader; ml.SetDatabaseDefaults(); ml.Layer = "DIM"; // Set up the MText contents ml.ContentType = ContentType.MTextContent; MText mt = new MText(); mt.SetDatabaseDefaults(); mt.Contents = m_contents; mt.TextStyleId = GeneralMenu.GetTextstyleId("ESI-STD"); ml.MText = mt; ml.TextColor = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 32); //ml.TextAlignmentType = TextAlignmentType.LeftAlignment; //ml.TextAttachmentType = TextAttachmentType.AttachmentTopOfTop; //// Set the frame and landing properties //ml.EnableDogleg = true; //ml.EnableFrameText = true; //ml.EnableLanding = true; ml.SetTextAttachmentType(TextAttachmentType.AttachmentMiddleOfTop, LeaderDirectionType.LeftLeader); ml.SetTextAttachmentType(TextAttachmentType.AttachmentMiddleOfBottom, LeaderDirectionType.RightLeader); // Reduce the standard landing gap ml.LandingGap = .125; // Add a leader, but not a leader line (for now) m_leaderIndex = ml.AddLeader(); m_leaderLineIndex = -1; }
protected override bool WorldDraw(WorldDraw draw) { var wg = draw.Geometry; if (wg != null) { ObjectId arrId = AutocadHelpers.GetArrowObjectId(ArrowName); var mtxt = new MText(); mtxt.SetDatabaseDefaults(); mtxt.Contents = MlText; mtxt.Location = _secondPoint; mtxt.Annotative = AnnotativeStates.True; mtxt.TransformBy(AcApp.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem); _mleader = new MLeader(); var ldNum = _mleader.AddLeader(); _mleader.AddLeaderLine(ldNum); _mleader.SetDatabaseDefaults(); _mleader.ContentType = ContentType.MTextContent; _mleader.ArrowSymbolId = arrId; _mleader.MText = mtxt; _mleader.TextAlignmentType = TextAlignmentType.LeftAlignment; _mleader.TextAttachmentType = TextAttachmentType.AttachmentBottomOfTopLine; _mleader.TextAngleType = TextAngleType.HorizontalAngle; _mleader.EnableAnnotationScale = true; _mleader.Annotative = AnnotativeStates.True; _mleader.AddFirstVertex(ldNum, FirstPoint); _mleader.AddLastVertex(ldNum, _secondPoint); _mleader.LeaderLineType = LeaderType.StraightLeader; _mleader.EnableDogleg = false; _mleader.DoglegLength = 0.0; _mleader.LandingGap = 1.0; _mleader.TextHeight = double.Parse(AcApp.GetSystemVariable("TEXTSIZE").ToString()); draw.Geometry.Draw(_mleader); } return(true); }
public void AddCoordMLeader() { Database db = HostApplicationServices.WorkingDatabase; //获取符号为无的箭头块的ObjectId ObjectId arrowId = db.GetArrowObjectId(DimArrowBlock.None); //如果当前图形中还未加入上述箭头块,则加入并获取其ObjectId if (arrowId == ObjectId.Null) { DimTools.ArrowBlock = DimArrowBlock.None; arrowId = db.GetArrowObjectId(DimArrowBlock.None); } using (Transaction trans = db.TransactionManager.StartTransaction()) { Point3d ptCoord = new Point3d(80, 30, 0); //要标注的坐标点 MText mtext = new MText(); //新建多行文本 //设置多行文本的内容为点的坐标值,并且分两行表示 mtext.Contents = "X:" + ptCoord.X.ToString("0.000") + @"\PY:" + ptCoord.Y.ToString("0.000"); mtext.LineSpacingFactor = 0.8; //多行文本的行间距 MLeader leader = new MLeader(); //创建多重引线 //为多重引线添加引线束,引线束由基线和一些单引线构成 int leaderIndex = leader.AddLeader(); //在引线束中添加单引线 int lineIndex = leader.AddLeaderLine(leaderIndex); //在单引线中添加引线头点(引线箭头所指向的点),位置为要进行标注的点 leader.AddFirstVertex(lineIndex, ptCoord); //在单引线中添加引线终点 leader.AddLastVertex(lineIndex, ptCoord.PolarPoint(Math.PI / 4, 10)); //设置单引线的注释类型为多行文本 leader.ContentType = ContentType.MTextContent; leader.MText = mtext;//设置单引线的注释文字 //将多重引线添加到模型空间 db.AddToModelSpace(leader); leader.ArrowSymbolId = arrowId; //设置单引线的箭头块ObjectId leader.DoglegLength = 0; //设置单引线的基线长度为0 //将基线连接到引线文字的下方并且绘制下划线 leader.TextAttachmentType = TextAttachmentType.AttachmentBottomOfTopLine; trans.Commit(); } }
protected override bool WorldDraw(WorldDraw draw) { var wg = draw.Geometry; if (wg != null) { var arrId = AutocadHelpers.GetArrowObjectId(AutocadHelpers.StandardArrowhead._NONE); var mText = new MText { Contents = MlText, Location = _secondPoint, Annotative = AnnotativeStates.True }; mText.SetDatabaseDefaults(); _mLeader = new MLeader(); var ldNum = _mLeader.AddLeader(); _mLeader.AddLeaderLine(ldNum); _mLeader.ContentType = ContentType.MTextContent; _mLeader.ArrowSymbolId = arrId; _mLeader.MText = mText; _mLeader.TextAlignmentType = TextAlignmentType.LeftAlignment; _mLeader.TextAttachmentType = TextAttachmentType.AttachmentBottomOfTopLine; _mLeader.TextAngleType = TextAngleType.HorizontalAngle; _mLeader.EnableAnnotationScale = true; _mLeader.Annotative = AnnotativeStates.True; _mLeader.AddFirstVertex(ldNum, FirstPoint); _mLeader.AddLastVertex(ldNum, _secondPoint); _mLeader.LeaderLineType = LeaderType.StraightLeader; _mLeader.SetDatabaseDefaults(); draw.Geometry.Draw(_mLeader); } return(true); }
public JigMLeader(string contents) : base(new MLeader()) { // Store the string passed in _mContents = contents; // Create a point collection to store our vertices _mPts = new Point3dCollection(); // Create mleader and set defaults MLeader ml = Entity as MLeader; ml.SetDatabaseDefaults(); // Set up the MText contents ml.ContentType = ContentType.MTextContent; MText mt = new MText(); mt.SetDatabaseDefaults(); mt.Contents = _mContents; ml.MText = mt; ml.TextAlignmentType = TextAlignmentType.LeftAlignment; ml.TextAttachmentType = TextAttachmentType.AttachmentMiddle; // Set the frame and landing properties ml.EnableDogleg = true; ml.EnableFrameText = true; ml.EnableLanding = true; // Reduce the standard landing gap ml.LandingGap = 0.05; // Add a leader, but not a leader line (for now) _mLeaderIndex = ml.AddLeader(); _mLeaderLineIndex = -1; }