컬렉션에 새 구성원을 추가하려면 Add 메서드를 사용합니다. 예를 들어, 다음 코드는 새 레이어를 만들고 레이어 테이블에 추가합니다 :
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
[CommandMethod("AddMyLayer")]
public static void AddMyLayer()
{
// 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)
{
// Open the Layer Table for write
//쓰기위한 레이어 테이블을 엽니다
acLyrTbl.UpgradeOpen();
// Create a new layer table record and name the layer "MyLayer"
//새 레이어 테이블 레코드를 만들고 레이어 "MyLayer"을 지정
LayerTableRecord acLyrTblRec = new LayerTableRecord();
acLyrTblRec.Name = "MyLayer";
// Add the new layer table record to the layer table and the transaction
//레이어 테이블과 트랜잭션에 새 레이어 테이블 레코드 추가
acLyrTbl.Add(acLyrTblRec);
acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);
// Commit the changes
//변경 내용을 적용
acTrans.Commit();
}
// Dispose of the transaction
}
}
출처
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html
댓글 없음 :
댓글 쓰기