IJCAD の .NET API で図形を1つ選択する際には Editor.GetEntity() を使用していると思います。
この GetEntity() を使用して特定のオブジェクトのみしか選択できなくする方法について紹介します。
サンプルコマンド
//ブロック参照のみ選択する
[CommandMethod("GETOBJ")]
public void GetEntitySample()
{
Editor icEd = Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityOptions icEntOpt = new PromptEntityOptions("\nブロックを選択");
icEntOpt.AllowNone = false;
icEntOpt.SetRejectMessage("\nこのオブジェクトはブロックではありません");
icEntOpt.AddAllowedClass(typeof(BlockReference), false);
PromptEntityResult icEntRes = icEd.GetEntity(icEntOpt);
if (icEntRes.Status != PromptStatus.OK) return;
using (Transaction icTrans =
icEntRes.ObjectId.Database.TransactionManager.StartTransaction())
using (BlockReference icBlockRef =
icTrans.GetObject(icEntRes.ObjectId, OpenMode.ForRead) as BlockReference)
{
icEd.WriteMessage($"\n選択したブロック参照名:{icBlockRef.Name}");
}
}
このサンプルコマンドでは、GetEntity() ではブロック参照のみ選択可能です。
PromptEntityOptions の SetRejectMessage と AddAllowedClass を使用して、
SetRejectMessage には対象でないオブジェクトを選択した際に表示するメッセージを、
AddAllowedClass には GetEntity() でどのオブジェクトを選択させるかを指定できます。