TheSwamp

Code Red => .NET => Topic started by: Bobby C. Jones on December 28, 2005, 02:35:38 PM

Title: AU 2005 code - Part 4 "Single entity selection"
Post by: Bobby C. Jones 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());
}
}
}
}