2012년 11월 26일 월요일

[코드]Field를 포함하는 문자개체의 위치를 출력 (postID = "7094591052476811047")


using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using WinApp = System.Windows.Forms.Application;

public class Script
{
    private ObjectId _idField;
    private ObjectId _idFrom;
    private ObjectId _idTo;

    public string Open(string hField, string hFrom, string hTo)
    {
        return Regen(hField, hFrom, hTo);
    }

    public string Regen(string hField, string hFrom, string hTo)
    {
        string evalStr ="123";
        Point3d position = new Point3d();
        Document doc = AcadApp.DocumentManager.MdiActiveDocument;
        Editor ed = doc.Editor;
        try
        {
            Database db = doc.Database;

            long ln1 = Convert.ToInt64(hFrom, 16);
            Handle hn1 = new Handle(ln1);
            _idFrom= db.GetObjectId(false, hn1, 0);

            using(Transaction tr = db.TransactionManager.StartTransaction())
            {
                DBObject txtObj = tr.GetObject(_idFrom, OpenMode.ForRead, false);
                if(txtObj !=null)
                {
                    if (txtObj.GetType() == typeof(MText))
                    {
                        position  = ((MText)txtObj ).Location;
                    }
                    else
                    {
                        position = ((DBText)txtObj ).Position;
                    }
                }
            }
        }
        catch(Autodesk.AutoCAD.Runtime.Exception e)
        {
            return e.Message;
        }
        return "(" + position.X + "," + position.Y + "," + position.Z + ")";
    }
}

댓글 없음:

댓글 쓰기