Author Topic: How would you handle this: Timer function?  (Read 22262 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: How would you handle this: Timer function?
« Reply #15 on: September 13, 2006, 06:01:09 PM »
Hey-ya Kerry, Yes it has been. You still on tomorrow's time? (Quick give me the winning lottery numbers. *grin* ...No, seriously give 'em to me.)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How would you handle this: Timer function?
« Reply #16 on: September 14, 2006, 09:28:21 AM »
Hey john,

I was pondering the timer thing for the last day or so. Not within the lisp but an external timer.
Having little or no knowledge or reactors It may not be possible.
Here are my drug (doctor prescribed) induced thoughts. :)

Interrupt Timer based on a system variable.
I would use the "date" sys var, but it is write only & may not fire the reactor.
But if it did every time it was updated it would run the call back function which would depend on
a global variable for guidance.

So set the reactor on
Save / update the global variable
..  Global Var
...  '( (time_index Time_interval repeate_idx ( lisp_name . (list og arguments optional)))
...     (Another lisp, etc)....
...   )


Call Back
Get system date & loop through the Global_Var
If (>= (- sys_data time_index) time_interval) ; ok to run
..  call lisp routine with argument(s)
..  if (< repeate_idx 0) ; infant times
...    reset time_index
..  else
...    deinc repeate_idx
...    if (= repeate_idx 0) ; last time here
....     remove lisp from Global Var
...    else
....    reset time_index


Well that's it. Depends on how the SysVar Reactor behaves.

What got m thinking about the interrupt was a way to solve this problem:
http://www.theswamp.org/index.php?topic=8969.msg152157#msg152157

The lisp stops waiting on some input from the mouse. With the interrupt the draw portion of
the lisp could be run outside the main lisp while waiting for the mouse to move.
Well I thought it may be possible if the reactor could be made to work.

I'm through rambling now, back to the couch.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How would you handle this: Timer function?
« Reply #17 on: September 14, 2006, 11:16:46 AM »
'Date' and 'CDate' don't fire system variable reactors.  I tried that first.  Unless I messed up.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How would you handle this: Timer function?
« Reply #18 on: September 14, 2006, 11:42:15 AM »
Thanks Tim,
I was afraid of that.
Any var's you can think of that would change on a regular basis?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How would you handle this: Timer function?
« Reply #19 on: September 14, 2006, 11:44:29 AM »
Thanks Tim,
I was afraid of that.
Any var's you can think of that would change on a regular basis?
You're welcome.  Not that I can think of off the top of my head.  I was looking at this, and hoping that some time keeping variable would be able to be look at, but haven't found one yet.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

nivuahc

  • Guest
Re: How would you handle this: Timer function?
« Reply #20 on: September 14, 2006, 12:09:18 PM »
I was trying it with MILLISECS but couldn't manage to make it work.

Greg B

  • Seagull
  • Posts: 12417
  • Tell me a Joke!
Re: How would you handle this: Timer function?
« Reply #21 on: September 14, 2006, 12:11:09 PM »
Question...

You have it set up now to go through the drawings right?  Without being able to orbit around them?

nivuahc

  • Guest
Re: How would you handle this: Timer function?
« Reply #22 on: September 14, 2006, 12:11:53 PM »
yup

nivuahc

  • Guest
Re: How would you handle this: Timer function?
« Reply #23 on: September 14, 2006, 12:12:51 PM »
And, for a reason I have yet to quite figure out, the launching of an exernal application (all it does is pause for a bit then send an ESC to AutoCAD) seems to throw the script into a tizzy.

Greg B

  • Seagull
  • Posts: 12417
  • Tell me a Joke!
Re: How would you handle this: Timer function?
« Reply #24 on: September 14, 2006, 12:14:29 PM »
external application?

nivuahc

  • Guest
Re: How would you handle this: Timer function?
« Reply #25 on: September 14, 2006, 12:49:06 PM »
I wrote a script with AutoIt and compiled it into an .exe file

The script pauses (right now for 20 seconds) then sends the ESC key (cancel) to AutoCAD.

The problem is stopping the 3DOrbit command while it's in progress and I decided to try that tact, as nothing else seemed to work.

Here's the thing (and it's likely something I'm overlooking), after it sends the ESC to AutoCAD, the AutoCAD script (the one opening the drawings and launching the 3DOrbit command) stops too. This normally wouldn't be a problem because I can also send RESUME to AutoCAD with my external trickery. But, for some reason, it causes AutoCAD to not be able to recognise the path of the next drawing.


Completely Off Topic:
Greg (or anyone else), if you've ever wanted to try some scripting (either very simple or quite complex) but didn't want to have to learn an entire programming language, and you wanted to do it without dropping a big chunk of money down on software, I highly recommend taking a look at AutoIt. They even have a version of SciTE with AutoIt syntax highlighting and help built-in. It's been a very helpful little tool to have in my toolbox over the years.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How would you handle this: Timer function?
« Reply #26 on: September 14, 2006, 01:38:01 PM »
Okay, so it's a combo for a little lisp, and a little C#.

Set Acad to single document mode (sdi = 1)
Load the dll file (once compiled)
Load the Lisp file
Issue 'TestTimer3' (dll command)
Issue 'Test' the lisp command.

And away you go.  Right now it is set to be only 10 seconds.  You will have to quit Acad to release the timer object, but I don't think that is a problem for what you want.

Lisp code: (change the variable 'DirPath' to your directory to run)
Code: [Select]
(defun c:Test (/ MyOpen DirPath)

(setq DirPath "c:\\willey-temp\\test\\xref_test\\")
(foreach Dwg (vl-directory-files Dirpath "*.dwg" 1)
 (command "_.open" "_y" (strcat DirPath Dwg))
 (setvar "tilemode" 1)
 (command "_.3dorbit")
)
)

C# code: (Change this line CountDownTimer.Interval = 10000; to be the time you desire, value is in milliseconds)
Code: [Select]
using System;
using System.Diagnostics;
using System.Timers;
using System.Windows.Forms;
using System.Runtime.InteropServices;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(Test.TimeLimitOpenv03))]

namespace Test
{
    /// <summary>
    /// Description of TimeLimitOpen.
    /// </summary>
    public class TimeLimitOpenv03
    {
   
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedPostCommand@@YAHPBD@Z")]
extern static public int acedPostCommand(string cmd);
        System.Timers.Timer CountDownTimer;
        //- Constructor: sets up var's etc for this class before use.
        public TimeLimitOpenv03()
        {
            CountDownTimer = new System.Timers.Timer();
            CountDownTimer.Elapsed += new ElapsedEventHandler(CancelCommand);
            CountDownTimer.Interval = 10000;
        }
 
        ~TimeLimitOpenv03() // <-- Destructor, do clean up here.
        {
            CountDownTimer.Elapsed -= new ElapsedEventHandler(CancelCommand);
        }
        public void CancelCommand(object sender, ElapsedEventArgs e)
        {
        acedPostCommand ("CancelCmd");
        }

        [CommandMethod("TestTimer3", CommandFlags.Session)]
        public void Main()
        {
            CountDownTimer.Enabled = true;
            //AcadApp.DocumentManager.MdiActiveDocument.SendStringToExecute ("_.3dorbit\n", false, false, true);
        }
    }
}

Edit: Files are not set to read only, if they are, the program (lisp) will choke.
« Last Edit: September 14, 2006, 01:39:03 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: How would you handle this: Timer function?
« Reply #27 on: September 14, 2006, 01:59:36 PM »
have been out of this thread, and no idea the status....

have anyone had think to provide a function, with the same ability as the command 3dOrbit?

How are the presentations are going to be?.... using AutoCAD?..... sorry no comprende bien (understand well).


Cheers.

nivuahc

  • Guest
Re: How would you handle this: Timer function?
« Reply #28 on: September 14, 2006, 02:00:47 PM »
Quote
Error   1   The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)   C:\Documents and Settings\cchauvin\Local Settings\Application Data\Temporary Projects\Test\Class1.cs   4   14   Test

nivuahc

  • Guest
Re: How would you handle this: Timer function?
« Reply #29 on: September 14, 2006, 02:01:13 PM »
I have no idea what the above means (okay, I have an idea...)