2012년 12월 4일 화요일

[코드]XAML실행테스트

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 Autodesk.Windows;

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Markup;
using System.Xml;
using System.IO;

using iDwgFieldMgd;

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

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

    public string Regen(string hField, string hFrom, string hTo)
    {
        Document doc = AcadApp.DocumentManager.MdiActiveDocument;
        Editor ed = doc.Editor;
        try
        {
            Database db = doc.Database;

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

            long ln2 = Convert.ToInt64(hFrom, 16);
            if (ln2 > 0)
            {
                Handle hn2 = new Handle(ln2);
                _idFrom = db.GetObjectId(false, hn2, 0);
            }

            long ln3 = Convert.ToInt64(hTo, 16);
            if (ln3 > 0)
            {
                Handle hn3 = new Handle(ln3);
                _idTo = db.GetObjectId(false, hn3, 0);
            }
        }
        catch (Autodesk.AutoCAD.Runtime.Exception e)
        {
            return e.Message;
        }

        return "로딩됨";
    }

    public string Open(string hField, string hFrom, string hTo)
    {
        try {
            //[XAML코드]기본윈도우의 포스트 아이디
            String codes = iDwgUtils.GetXamlCode("7332555001323949436");

            StringReader sr = new StringReader(codes);

            XmlReader reader = XmlReader.Create(sr);

            Window wintest = (Window)XamlReader.Load(reader);

            wintest.Show();

            wintest.SizeChanged += wintest_Changed;
        }
        catch(System.Exception ex)
        {
             MessageBox.Show(ex.Message);
        }
        return Regen(hField, hFrom, hTo);
    }

    private void wintest_Changed(object sender, RoutedEventArgs e)
    {
    //    MessageBox.Show("Dynamic windows loaded from XAML string");
    }

    public void Exit(string str)
    {
           wintest.Close();
    }
}

댓글 없음:

댓글 쓰기