问题描述
我在选择目标 acadObject
时遇到了一些麻烦.我通过 selectionset.SelectonScreen
方法获得输入.
I have some trouble to select the targeted acadObject
. I get the input via selectionset.SelectonScreen
method.
在这里,我可以根据我的过滤条件从模型空间中获取更多数量的对象.但我只需要用户提供一个对象.
Here i can get more number of object from modelspace based on my filter condition.But i need only one object from the user.
这里我在下面提到了我的代码:
Here i mentioned my code below:
AcadSelectionSet selset= null;
selset=currDoc.selectionset.add("Selset");
short[] ftype=new short[1];
object[] fdata=new object[1];
ftype[0]=2;//for select the blockreference
fdata[0]=blkname;
selset.selectOnScreen ftype,fdata; // Here i can select any no. of blocks according to filter value but i need only one block reference.
请帮我解决这个问题.
推荐答案
这是来自 autocad 开发人员帮助的直接引用
this is a direct quote from autocad developer help
AutoCAD .NET API 有大量文档.
There is tons of documentation the AutoCAD .NET API.
你需要有
[程序集:CommandClass(typeof(namespace.class))]
如果您希望能够在NetLoad
.dll(如果它是一个类库)之后从命令行调用此命令,请在您的命名空间之上.
above your namespace if you want to be able to invoke this command from the command line after you NetLoad
the .dll, if it is a classLibrary.
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
[CommandMethod("SelectObjectsOnscreen")]
public static void SelectObjectsOnscreen()
{
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Request for objects to be selected in the drawing area
PromptSelectionResult acSSPrompt = acDoc.Editor.GetSelection();
// If the prompt status is OK, objects were selected
if (acSSPrompt.Status == PromptStatus.OK)
{
SelectionSet acSSet = acSSPrompt.Value;
// Step through the objects in the selection set
foreach (SelectedObject acSSObj in acSSet)
{
// Check to make sure a valid SelectedObject object was returned
if (acSSObj != null)
{
// Open the selected object for write
Entity acEnt = acTrans.GetObject(acSSObj.ObjectId,
OpenMode.ForWrite) as Entity;
if (acEnt != null)
{
// Change the object's color to Green
acEnt.ColorIndex = 3;
}
}
}
// Save the new object to the database
acTrans.Commit();
}
// Dispose of the transaction
}
}
这篇关于如何通过选择集只获取一个acadobject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!