.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

My Code work on 2014 and doens't Work on 2015

1 REPLY 1
Reply
Message 1 of 2
Amremad
320 Views, 1 Reply

My Code work on 2014 and doens't Work on 2015

hello every one

Why My Code work on 2014 and doens't Work on 2015 ?

 

using System;
using System.Text;
using Microsoft.VisualBasic;
using System.Windows.Forms;
using System.Timers;
using System.Collections;

using System.Collections.Generic;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.PlottingServices;


namespace CADLogs
{
    public class CADLogs : Autodesk.AutoCAD.Runtime.IExtensionApplication
    {
    public struct OpenedDocuments
    {
        public Autodesk.AutoCAD.DatabaseServices.Database cDocument ;
        public int Duration;
        public OpenedDocuments(Database doc,int duration)
        {
            cDocument = doc;
            Duration = duration;
        }
    }

    public List<OpenedDocuments> drawings = new List<OpenedDocuments>();
    public Database curDwg = new Autodesk.AutoCAD.DatabaseServices.Database();
    public DocumentCollection DwgIO = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;


    System.Timers.Timer  wTimer = new System.Timers.Timer();
    System.Timers.Timer  iTimer = new System.Timers.Timer();

    [CommandMethod("CADLogs")]
    public void CheckMyLevel()
    {
        MessageBox.Show("Hello");
    }

    public CADLogs()
    {
        wTimer = new System.Timers.Timer(2000);

        wTimer.Elapsed  += new ElapsedEventHandler(wTimer_Elapsed);
        wTimer.Disposed += new EventHandler( wTimer_Disposed);

        iTimer.Elapsed += iTimer_Elapsed;
        iTimer.Disposed += iTimer_Disposed;

        //wTimer.Enabled = true;

        DwgIO.DocumentBecameCurrent += DocumentBecameCurrent;
        DwgIO.DocumentCreated += DocumentCreated;
        DwgIO.DocumentDestroyed += DocumentDestroyed;
    }



    private void DocumentBecameCurrent(object sender, DocumentCollectionEventArgs e)
    {
        curDwg = e.Document.Database;
    }

    private void curDwg_ObjectModified(object sender, ObjectEventArgs e)
    {
       Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n modified" + curDwg.Filename + ">>" + DateTime.Now.ToString());
    }
    private void DocumentCreated(object sender, DocumentCollectionEventArgs e)
    {
        if (e.Document.Database != null)
        {
            e.Document.Database.ObjectModified += curDwg_ObjectModified;
            curDwg = e.Document.Database;

            drawings.Add(new OpenedDocuments(curDwg, 0));
        }
        else
        {
            MessageBox.Show("Null");
        }
    }
    private void DocumentDestroyed(object sender, DocumentDestroyedEventArgs e)
    {
        foreach(OpenedDocuments doc in drawings)
        {
            MessageBox.Show(e.FileName);
            //if (doc.cDocument.BlockTableId == )
            //MessageBox.Show(doc.cDocument.BlockTableId.ToString());
        }
    }

    private void iTimer_Disposed(object sender, EventArgs e)
    {
       
    }
    private void iTimer_Elapsed(object sender, ElapsedEventArgs e)
    {
        
    }
    private void wTimer_Disposed(object sender, EventArgs e)
    {
        
    }
    private void wTimer_Elapsed(object sender, ElapsedEventArgs e)
    {
       
    }
    public void Initialize()
    {
        curDwg = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
        curDwg.ObjectModified += curDwg_ObjectModified;
        drawings.Add(new OpenedDocuments(curDwg, 0));
    }

    public void Terminate()
    {
        //MessageBox.Show("terminate");
    }


    }
}

 

1 REPLY 1
Message 2 of 2
khoa.ho
in reply to: Amremad

I've just tested your code work on my AutoCAD 2015, with your attached project. I don't know why it did not work at your end.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost