AutoCAD C#

[AutoCAD C#]원 그리기 (Layer, Color) 예제

데브프로그라 2024. 4. 26. 16:54
반응형

AutoCAD에서 원을 그리는 함수를 먼저 정의한다.
필요에 따라 사용할 수 있는 함수로, 아래와 같이 정의하여 사용한다.

static public Circle CreateCircle(Point3d CenterPt, double dRadius)
        {
            Circle oCir = null;  
            Database db = HostApplicationServices.WorkingDatabase;
            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            using (Transaction ts = tm.StartTransaction())
            {
                try
                {
                    BlockTable blockTable = (BlockTable)ts.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead, false);
                    BlockTableRecord modelSpace = (BlockTableRecord)ts.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                    oCir  = new Circle(CenterPt, Vector3d.ZAxis, dRadius);
                    oCir.Layer = "0";
                    oCir.ColorIndex=2;
                    modelSpace.AppendEntity( oCir );
                    ts.AddNewlyCreatedDBObject(oCir, true);
                    ts.Commit();
                }
                catch (System.Exception exception)
                {
                    ed.WriteMessage(exception.ToString());
                    ts.Abort();
                }
                finally
                {
                    ts.Dispose();
                }
            }
            return oCir  ;
        }

반응형