acObjId = acLyrTbl["MyLayer"];
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
[CommandMethod("IterateLayers")]
public static void IterateLayers()
{
// Get the current document and database, and start a transaction
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// This example returns the layer table for the current database
//현재 데이터베이스 레이어 테이블을 반환
LayerTable acLyrTbl;
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
OpenMode.ForRead) as LayerTable;
// Step through the Layer table and print each layer name
//레이어 테이블을 통해 단계와 각 레이어의 이름을 인쇄
foreach (ObjectId acObjId in acLyrTbl)
{
LayerTableRecord acLyrTblRec;
acLyrTblRec = acTrans.GetObject(acObjId,
OpenMode.ForRead) as LayerTableRecord;
acDoc.Editor.WriteMessage("\n" + acLyrTblRec.Name);
}
// Dispose of the transaction
}
}
LayerTable 개체에 MyLayer라는 레이어 테이블 레코드 찾기
다음 예제는 MyLayer라는 레이어가 존재하거나하지 않을 경우 결정 LayerTable 개체를확인하고, 적절한 메시지를 표시합니다
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
[CommandMethod("FindMyLayer")]
public static void FindMyLayer()
{
// Get the current document and database, and start a transaction
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Returns the layer table for the current database
LayerTable acLyrTbl;
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
OpenMode.ForRead) as LayerTable;
// Check to see if MyLayer exists in the Layer table
//MyLayer는 레이어 테이블에 존재하는지 확인
if (acLyrTbl.Has("MyLayer") != true)
{
acDoc.Editor.WriteMessage("\n'MyLayer' does not exist");
}
else
{
acDoc.Editor.WriteMessage("\n'MyLayer' exists");
}
// Dispose of the transaction
}
}
출처
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html
댓글 없음 :
댓글 쓰기