C#調(diào)用ListEmployee命令
C#語言有很多值得學(xué)習(xí)的地方,這里我們主要介紹C#調(diào)用ListEmployee命令,包括介紹調(diào)用Editor的GetSelection()函數(shù)來選擇實(shí)體等方面。
C#調(diào)用ListEmployee命令
現(xiàn)在讓我們來創(chuàng)建一個命令,當(dāng)用戶在圖形中選擇一個雇員對象時,它會顯示雇員的詳細(xì)資料。 我們會使用上一章中創(chuàng)建的ListEmployee()函數(shù)在命令行中輸出雇員的詳細(xì)資料。下面是你必須遵循的步驟:
◆C#調(diào)用ListEmployee命令
◆調(diào)用Editor的GetSelection()函數(shù)來選擇實(shí)體
- PromptSelectionResult res = ed.GetSelection(Opts, filter);
上面的filter用來過濾選擇集中的塊索引。你可以創(chuàng)建如下的過濾列表:
- TypedValue[] filList = new TypedValue[1];
- filList[0] = new TypedValue((int)DxfCode.Start, "INSERT");
- SelectionFilter filter = new SelectionFilter(filList);
從選擇集中獲取ObjectId數(shù)組:
- //如果選擇失敗則什么也不做
- if (res.Status != PromptStatus.OK)
- return;
- Autodesk.AutoCAD.EditorInput.SelectionSet SS = res.Value;
- ObjectId[] idArray;
- idArray = SS.GetObjectIds();
***,把選擇集中的每個ObjectId輸入到ListEmployee()函數(shù)來獲取一個雇員詳細(xì)資料的字符串?dāng)?shù)組。把雇員的詳細(xì)資料輸出到命令行。例如:
- //獲取saEmployeeList 數(shù)組中的所有雇員
- foreach (ObjectId employeeId in idArray)
- {
- ListEmployee(employeeId, ref saEmployeeList);
- //把雇員的詳細(xì)資料輸出到命令行
- foreach (string employeeDetail in saEmployeeList)
- {
- ed.WriteMessage(employeeDetail);
- }
【編輯推薦】