Cách gọi hàm Select tiện dụng
1 Thêm class SelectExts.cs
Lưu mã sau dưới dạng tệp tin SelectExts_by_AJS.cs
Code:
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using System.Collections.Generic;
using System.Linq;
namespace LMAN.By.AJS
{
internal static class SelectExts
{
public static List<ObjectId> Select(this Editor ed, params object[] pairs)
{
PromptSelectionResult promptSelectionResult = ((pairs == null || pairs.Length < 2) ? ed.GetSelection() : ed.GetSelection(pairs.ToSelectionFilter()));
List<ObjectId> result = new List<ObjectId>();
if (promptSelectionResult.Status == PromptStatus.OK)
{
result = promptSelectionResult.Value.GetObjectIds().ToList();
}
return result;
}
private static SelectionFilter ToSelectionFilter(this object[] pairs)
{
List<TypedValue> list = new List<TypedValue>();
for (int i = 0; i < pairs.Length - 1; i += 2)
{
if ((int)pairs[i] == -3)
{
list.Add(new TypedValue((int)pairs[i]));
i--;
}
else
{
list.Add(new TypedValue((int)pairs[i], pairs[i + 1]));
}
}
return new SelectionFilter(list.ToArray());
}
}
}2 Cách dùng
Code:
public static List<ObjectId> HowToUse()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
var ids = ed.Select(0, "*LINE,INSERT", 8, "AJS.Layer", -3, 1001, "AJS.XData.App.Name");
return ids;
}Link tải (MediaFire)
📥 https://www.mediafire.com/
---------------------------------------------------------------------------------------------
Mọi thông tin xin liên hệ Fanpage AutoLISP Thật là đơn giản!
Cảm ơn bạn đã theo dõi!

Không có nhận xét nào:
Đăng nhận xét