Click here to Skip to main content
15,914,452 members
Home / Discussions / C#
   

C#

 
QuestionDatagrid to arraylist Pin
jeweladdict14-Sep-06 6:14
jeweladdict14-Sep-06 6:14 
AnswerRe: Datagrid to arraylist Pin
Jay Riggs14-Sep-06 7:15
Jay Riggs14-Sep-06 7:15 
QuestionWindows Timer event, with other program Pin
T.Willey14-Sep-06 5:59
T.Willey14-Sep-06 5:59 
AnswerRe: Windows Timer event, with other program Pin
Nader Elshehabi14-Sep-06 9:52
Nader Elshehabi14-Sep-06 9:52 
GeneralRe: Windows Timer event, with other program Pin
T.Willey14-Sep-06 11:19
T.Willey14-Sep-06 11:19 
GeneralRe: Windows Timer event, with other program Pin
Nader Elshehabi14-Sep-06 11:37
Nader Elshehabi14-Sep-06 11:37 
GeneralRe: Windows Timer event, with other program Pin
T.Willey14-Sep-06 12:06
T.Willey14-Sep-06 12:06 
GeneralRe: Windows Timer event, with other program Pin
Nader Elshehabi14-Sep-06 12:26
Nader Elshehabi14-Sep-06 12:26 
Hello

Well, forgive me if I say that your code sin't Object oriented. It looks like you have good experience in languages before C++. Your style is very procedural and it sin't that bad. It's just that your applications doesn't even have an interface?!! All you do is that you show a dialog, ake an input then do some interop. Well, either you make a full functional windows application or wrap your code in a dll or something. I didn't mean to ofend you - sincerely-, I just wanted to be as honest as I can with you.

Anyway, I wouldn't like to disrupt your code structure, so, the closest solution to get your code to work -though it would be better to remodel your code later to be more OO-, is simply to declare your variables as static thus you'd be able to call them by the class.
Here is your code, modified:

namespace Test
{
    /// <summary>
    /// Description of TimeLimitOpen.
    /// </summary>
    public class TimeLimitOpenv02
    {
        
        [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
            EntryPoint = "?acedPostCommand@@YAHPBD@Z")]
        extern static public int acedPostCommand(string cmd);
        private static string[] DwgList;//<---Modification
        public Document NewDoc;
        DocumentCollection DocMan = AcadApp.DocumentManager;
        System.Timers.Timer CountDownTimer;
        private static int cnt = 1; //<---Modification
        //- Constructor: sets up var's etc for this class before use.
        public TimeLimitOpenv02()
        {
            CountDownTimer = new System.Timers.Timer();
            CountDownTimer.Elapsed += new ElapsedEventHandler(CancelCommand);
            CountDownTimer.Interval = 10000;
        }

        ~TimeLimitOpenv02() // <-- Destructor, do clean up here.
        {
            CountDownTimer.Elapsed -= new ElapsedEventHandler(CancelCommand);
        }
        public void CancelCommand(object sender, ElapsedEventArgs e)
        {
            acedPostCommand ("CancelCmd");
            //MessageBox.Show (DocMan.ToString());
            NewDoc = DocMan.MdiActiveDocument;
            //MessageBox.Show ("Testing");
            //MessageBox.Show (cnt.ToString());
            NewDoc.CloseAndDiscard();
            NewDoc = DocMan.Open (DwgList[cnt], true);
            if (NewDoc != DocMan.MdiActiveDocument) {
                DocMan.MdiActiveDocument = NewDoc;
            }
            ++TimeLimitOpenv02.cnt;//You access it by the class name
            if (TimeLimitOpenv02.cnt > TimeLimitOpenv02.DwgList.Length) {
                CountDownTimer.Enabled = false;
                CountDownTimer.Dispose();
            }
            NewDoc.SendStringToExecute ("_.3dorbit", false, false, true);
        }

        [CommandMethod("TestTimer", CommandFlags.Session)]
        public void Main()
        {
            Autodesk.AutoCAD.Windows.OpenFileDialog Dia =
                new Autodesk.AutoCAD.Windows.OpenFileDialog(
                "Select drawings to update Cloud layer", "", "dwg", "",
                Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
            Dia.ShowDialog();
            TimeLimitOpenv02.DwgList = Dia.GetFilenames();
            if (DwgList.Length > 1)
            {
                CountDownTimer.Enabled = true;
                Document NewDoc = DocMan.Open (DwgList[0], true);
                if (NewDoc != DocMan.MdiActiveDocument) {
                    DocMan.MdiActiveDocument = NewDoc;
                }
                NewDoc.SendStringToExecute ("_.3dorbit\n", false, false, true);
            }
        }
    }
}


BTW:
You still can access DwgList from your main, and your CancelCommand if you didn't redeclare it. Your redeclaration made a second local variable with the same name that masked the original one -I hope I'm making sense!;P-. Anyway, even though I totally don't like this static workaround, but it would relieve the ambiguity, and get your code to work. But if you want to make a windows application, at least it should have a form, shouldn't it? Well, Maybe you are making a command line tool -never liked them though-. Good luck! I hope it works this time.

RegardsRose | [Rose]

GeneralRe: Windows Timer event, with other program Pin
T.Willey14-Sep-06 12:55
T.Willey14-Sep-06 12:55 
GeneralRe: Windows Timer event, with other program Pin
T.Willey14-Sep-06 13:10
T.Willey14-Sep-06 13:10 
GeneralRe: Windows Timer event, with other program Pin
Nader Elshehabi14-Sep-06 13:41
Nader Elshehabi14-Sep-06 13:41 
GeneralRe: Windows Timer event, with other program Pin
T.Willey14-Sep-06 14:02
T.Willey14-Sep-06 14:02 
GeneralRe: Windows Timer event, with other program Pin
Nader Elshehabi14-Sep-06 14:28
Nader Elshehabi14-Sep-06 14:28 
GeneralRe: Windows Timer event, with other program [modified] Pin
T.Willey15-Sep-06 7:29
T.Willey15-Sep-06 7:29 
AnswerRe: Windows Timer event, with other program Pin
Nader Elshehabi15-Sep-06 9:21
Nader Elshehabi15-Sep-06 9:21 
GeneralRe: Windows Timer event, with other program Pin
T.Willey15-Sep-06 10:03
T.Willey15-Sep-06 10:03 
GeneralRe: Windows Timer event, with other program Pin
Nader Elshehabi15-Sep-06 12:52
Nader Elshehabi15-Sep-06 12:52 
QuestionHotKey Indicator Pin
mtone14-Sep-06 5:18
mtone14-Sep-06 5:18 
AnswerRe: HotKey Indicator Pin
Not Active14-Sep-06 5:28
mentorNot Active14-Sep-06 5:28 
AnswerRe: HotKey Indicator Pin
John Baird14-Sep-06 5:55
John Baird14-Sep-06 5:55 
AnswerRe: HotKey Indicator Pin
Nader Elshehabi14-Sep-06 9:43
Nader Elshehabi14-Sep-06 9:43 
Questionchange form background image Pin
Muller214-Sep-06 4:53
Muller214-Sep-06 4:53 
AnswerRe: change form background image Pin
Judah Gabriel Himango14-Sep-06 5:13
sponsorJudah Gabriel Himango14-Sep-06 5:13 
GeneralRe: change form background image Pin
Muller214-Sep-06 5:49
Muller214-Sep-06 5:49 
GeneralRe: change form background image Pin
User 665814-Sep-06 6:16
User 665814-Sep-06 6:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.