I am writing an AutoCAD plugin using c# and need to display the property of hatch in the middle of the hatched object (e.g., the center of a circle). I have two problems in code:
How can I access center of circle?
How can I get property of hatch?
I am getting error on this line in autocad.
acText.TextString = hatch.Area.ToString(); // Area of hatch
Below is the code mainly taken from Stackflow.
[CommandMethod("DisplyArea")]
public static void SelectCirclesToHatch()
{
var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var filter = new SelectionFilter(new[] { new TypedValue(0, "CIRCLE") });
var selection = ed.GetSelection(filter);
int vr = 1;
if (selection.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
foreach (var id in selection.Value.GetObjectIds())
{
var ids = new ObjectIdCollection(new[] { id });
using (var hatch = new Hatch())
{
curSpace.AppendEntity(hatch);
tr.AddNewlyCreatedDBObject(hatch, true);
hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
hatch.Associative = true;
hatch.AppendLoop(HatchLoopTypes.Outermost, ids);
hatch.EvaluateHatch(true);
DBText acText = new DBText();
// It needs to be CIRCLE.CENTER, but how can I access that??????
acText.Position = new Point3d(2,2,0);
acText.TextString = hatch.Area.ToString(); // Area of hatch
acText.Height = 0.5;
curSpace.AppendEntity(acText);
tr.AddNewlyCreatedDBObject(acText, true);
}
}
tr.Commit();
}
}
Any solution?