#if BRX_APP
using System.Diagnostics;
using Teigha.Runtime;
using Teigha.DatabaseServices;
using Bricscad.ApplicationServices;
using Teigha.Geometry;
using Bricscad.EditorInput;
using Arx_App = Bricscad.ApplicationServices.Application;
#elif ACAD_APP
using System.Diagnostics;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Bricscad.PlottingServices;
using Arx_App = Autodesk.AutoCAD.ApplicationServices.Application;
#endif
namespace AID
{
public class SwampCode
{
[CommandMethod("TestMleader")]
public void MleaderTest()
{
Document doc = Arx_App.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// set the active style
db.MLeaderstyle = GetMLeaderStyleID("Test");
#if BRX_APP
// points for the leader
Point3d leaderPoint
= new Point3d
(40,
40,
0); // point for leader end point Point3d textPoint
= new Point3d
(50,
20,
0); // point for label text string labelString = "BRX_APP";
#elif ACAD_APP
Point3d leaderPoint
= new Point3d
(0,
40,
0); // point for leader end point Point3d textPoint
= new Point3d
(10,
20,
0); // point for label text string labelString = "ACAD_APP";
#endif
// create the MLeader
MLeader label
= new MLeader
(); label.SetDatabaseDefaults();
label.ContentType = ContentType.MTextContent;
label.Layer = "mleader";
int ldNum = label.AddLeader();
int idx = label.AddLeaderLine(ldNum);
label.AddFirstVertex(idx, leaderPoint);
label.AddLastVertex(idx, textPoint);
// new Mtext for the text
MText mText
= new MText
(); mText.SetDatabaseDefaults();
mText.Contents = labelString;
mText.TextHeight = 2.5;
mText.Attachment=AttachmentPoint.MiddleCenter;
mText.SetAttachmentMovingLocation(AttachmentPoint.MiddleCenter);
label.MText = mText;
// add the mleader to currspace
using (Transaction tr = (doc.TransactionManager).StartTransaction())
{
BlockTableRecord curSpace =
(BlockTableRecord)tr.GetObject(Active.Database.CurrentSpaceId, OpenMode.ForWrite);
curSpace.AppendEntity(label);
tr.AddNewlyCreatedDBObject(label, true);
tr.Commit();
}
}
/// <summary>
/// Checks if the MLeader Style definition is in the active drawing.
/// </summary>
/// <param name="styleName">Name of the MLeader style.</param>
/// <returns>ObjectID of MLeader style, ObjectId.Null on error</returns>
public static ObjectId GetMLeaderStyleID(string styleName)
{
ObjectId styleId = ObjectId.Null; ;
using (Transaction tr = (Arx_App.DocumentManager.MdiActiveDocument.TransactionManager).StartTransaction())
{
DBDictionary mlDictionary = (DBDictionary)tr.GetObject(Active.Database.MLeaderStyleDictionaryId, OpenMode.ForRead);
if (mlDictionary.Contains(styleName))
{
styleId = mlDictionary.GetAt(styleName);
MLeaderStyle style = tr.GetObject(styleId, OpenMode.ForWrite) as MLeaderStyle;
if (style != null)
{
Debug.Print($"style.LandingGap: {style.LandingGap}");
Debug.Print($"style.EnableLanding: {style.EnableLanding}");
}
}
tr.Commit();
return styleId;
}
}
}
}