选择集woe
我使用以下函数为我提供特定层上的块引用选择集。 AutoCADDrawingObjectName.BlockReference 返回文本“INSERT”。但是,当我知道我要求的层有块引用时,它返回了selectSetResult.Status值的错误警告(我无法拾取任何代码),并为该值返回Null。
public static SelectionSet GetBlockRefOnLayerSelectionSet(string LayerName)
{
Document thisDrawing;
SelectionSet selectionSet = null;
PromptSelectionResult selectionSetResult;
TypedValue[] typedArray = new TypedValue;
SelectionFilter selectionFilter;
try
{
thisDrawing = GetDocument();
Editor editor = thisDrawing.Editor;
typedArray.SetValue(new TypedValue((int)DxfCode.Start, AutoCADDrawingObjectName.BlockReference), 0);
typedArray.SetValue(new TypedValue((int)DxfCode.LayerName, LayerName), 1);
selectionFilter = new SelectionFilter(typedArray);
selectionSetResult = editor.SelectAll(selectionFilter);
if (selectionSetResult.Value != null)
{
selectionSet = selectionSetResult.Value;
}
}
catch (Exception ex)
{
MessageBox.Show("AutoCADUtility.GetBlockRefOnLayerSelectionSet : " + ex.Message, MessageHeadings.ExceptionError);
}
return selectionSet;
}
我不禁觉得编辑器.SelectAll指令是错误的。 COM AcadSelectionSet 类允许我们使用 .选择方法,但我找不到等效方法。
有人能看到我在这里做错了什么吗?
问候, 保罗
**** Hidden Message ***** 嗨,请不要让C#像VB(A)一样冗长/嘈杂,您可以在单个表达式中声明和初始化您的变量。你说“我知道我要求的层有Block refs,”,但代码没有...使用. NET,我们检查PromptResult.Satus.PromptStatus.OK表示对象已被选中PromptStatus.Error表示选择为空。忘记COM做什么,这里是. NET。尝试这样做:公共静态SelectionSet GetBlockRefOnLayerSelectionSet(string layerName)。
{。
编辑Application.DocumentManager.MdiActiveDocument.Editor。
TypeValue[]typeValue={new TypeValue(0,"INSERT"), new TypeValue(8, layerName)};。
提示选择结果选择结果=ed.GetSelection(新的选择过滤器(类型值));。
如果(selectionResult.Status==PromptStatus.OK)。
返回selectionResult.Value;。
其他。
返回null;。
}。
正如我所希望的那样,这是我在其他地方的编程。我没有设置块引用的层。 感谢您确认代码正常工作
页:
[1]