Author Topic: AU 2005 code - Part 4 "Single entity selection"  (Read 5102 times)

0 Members and 1 Guest are viewing this topic.

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
AU 2005 code - Part 4 "Single entity selection"
« on: December 28, 2005, 02:35:38 PM »
Code: [Select]
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;

namespace AU2005.AcadApi
{
//Page 10
public class GetEntityExample
{
[CommandMethod("GetCircle")]
public void GetEntity ()
{
Editor currentEditor = Application.DocumentManager.MdiActiveDocument.Editor;

//Create a new entity selection options object and
//restrict it to selecting circles only
PromptEntityOptions entitySelectionOpts = new PromptEntityOptions("\nSelect Circle: ");
entitySelectionOpts.SetRejectMessage("\nOnly Circles may be selected.");
entitySelectionOpts.AddAllowedClass (typeof (Circle), true);

//Start the selection process
PromptEntityResult entitySelectionResult = currentEditor.GetEntity(entitySelectionOpts);

//If a circle was successfully selected, diplay its radius
if (entitySelectionResult.Status == PromptStatus.OK)
{
DisplayCircleRadius(entitySelectionResult.ObjectId);
}
}


private void DisplayCircleRadius(ObjectId circleId)
{
Editor currentEditor = Application.DocumentManager.MdiActiveDocument.Editor;

using (Transaction trans = currentEditor.Document.TransactionManager.StartTransaction())
{
Circle selectedCircle = (Circle) trans.GetObject(circleId, OpenMode.ForRead);

Application.ShowAlertDialog ("Radius: " + selectedCircle.Radius.ToString());
}
}
}
}

Bobby C. Jones