TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: nivuahc on September 12, 2006, 11:09:59 AM

Title: How would you handle this: Timer function?
Post by: nivuahc on September 12, 2006, 11:09:59 AM
A friend asked me to throw something together for him as an art project and this is, essentially, what he wants to do;

Open a drawing
Wait a specified amount of time (5 minutes or so)
Close the drawing
Open the next
Wait a specified amount of time (5 minutes or so)
Close the drawing
Open the next
Wait a specified amount of time (5 minutes or so)
Close the drawing
Open the next
etc...

But here's the catch: He wants the user (gallery patron) to be able to use the 3DOrbit command via touchscreen for those 5 minutes or so...

Now I haven't put a tremendous amount of thought into the process but the half a dozen things I considered didn't seem to work.

While he is a very talented 3D artist and quite proficient with AutoCAD, he wouldn't know a Lisp routine from a script so I'm trying to make this as simple as possible for him.

I've got it setup now to write a script based on the drawings contained in a selected folder, then run the script. No problems there. It's the "start a timer, begin the 3dOrbit command, cancel the command at the specified time" part that's giving me trouble.

Any suggestions or advice?
Title: Re: How would you handle this: Timer function?
Post by: uncoolperson on September 12, 2006, 11:43:01 AM
.net should be able to handle this pretty easily, i don't think lisp would like it much though.
Title: Re: How would you handle this: Timer function?
Post by: T.Willey on September 12, 2006, 11:57:06 AM
.net should be able to handle this pretty easily, i don't think lisp would like it much though.
I second that.  I have written a basic countdown program in C# if you want to see it.  It has been posted in the .Net forum, here. (http://www.theswamp.org/index.php?topic=12328.0)
Title: Re: How would you handle this: Timer function?
Post by: nivuahc on September 12, 2006, 12:05:49 PM
Well, to think I was trying to make this as simple as possible for my friend... honestly, that code was all Greek to me. :)

Okay, it wasn't that bad, but I have no idea how to use code written in C# in AutoCAD. And I have no idea how to hack your routine to make it do only what I want. And I have no idea how to explain it to anyone else.

Basically, I'm (as usual) quite lost and confused.
Title: Re: How would you handle this: Timer function?
Post by: ElpanovEvgeniy on September 12, 2006, 12:12:27 PM
Use View object...
Title: Re: How would you handle this: Timer function?
Post by: TimSpangler on September 12, 2006, 12:19:32 PM
I would think that you would need a reator of some sort so that the user couldn't cancel the ORBIT command and if they do reinvoke it til the time runs out.  I wouldn't se why it couldnt be done with lisp, but it would be hard to control.
Title: Re: How would you handle this: Timer function?
Post by: T.Willey on September 12, 2006, 12:21:51 PM
Okay.  :-)

If I understand you correctly, you want to select a certain amout of drawings, have one open for 5 minutes, and then close it (without saving), and open the next one?  I think this shouldn't be too hard.  Let me see what I can come up with.
Title: Re: How would you handle this: Timer function?
Post by: ElpanovEvgeniy on September 12, 2006, 12:25:09 PM
It is possible to write orbit program...
From a script we open the drawing and we start for my_orbit program which watches an operating time and itself it is completed, further the script opens the following drawing.
Title: Re: How would you handle this: Timer function?
Post by: T.Willey on September 12, 2006, 12:35:18 PM
How do you get it to watch the time?  I have never seen a way to do that, and I have seen a couple of people asking for this.  Very interesting.
Title: Re: How would you handle this: Timer function?
Post by: nivuahc on September 12, 2006, 12:50:09 PM
How do you get it to watch the time?  I have never seen a way to do that, and I have seen a couple of people asking for this.  Very interesting.

x2

Which is why I posted in the first place. I've already got a very simple "select a drawing from your folder, write the script, run it" routine setup I'm just stuck on the whole "after this period of time (during which the 3DOrbit command is being used) go to the next drawing" bit.

Title: Re: How would you handle this: Timer function?
Post by: JohnK on September 12, 2006, 08:29:46 PM
> How would i handle this?
With a program.

> How do you get it to watch the time?  I have never seen a way to do
> that, and I have seen a couple of people asking for this.

Then you havnet paid attention.

EDIT: Fat fingers!!!

Try this on for size. Its real sloppy, but it was a once thru quickie.

Code: [Select]
(defun tryme ( / sec flag)
  (alert "I will give you a few seconds to draw as many lines as you can GO!")
  (command "_.line")
  (setq sec (atoi (substr (rtos (getvar "cdate")2 8) 12 2)))
  (if (= 1 (logand (getvar"cmdactive") 1))
    (setq flag T))
  (while flag
         (command pause)
         (if (> (atoi (substr (rtos (getvar "cdate")2 8) 12 2)) sec)
           (setq flag nil)))
  (command) (command)
  (alert "Alright, that's enough!")
  (princ)
 )
Title: Re: How would you handle this: Timer function?
Post by: T.Willey on September 13, 2006, 11:14:54 AM
Works.
Title: Re: How would you handle this: Timer function?
Post by: nivuahc on September 13, 2006, 11:16:15 AM
Not with 3DOrbit. :)
Title: Re: How would you handle this: Timer function?
Post by: JohnK on September 13, 2006, 05:49:38 PM
> Works.

Yep, sorta.  It's bloated, crapy, and redundant, but when it comes time we can put a dress on the theory and send it off to the prom.

> Not with 3DOrbit.

Not with the native one. But i was under the impression that we were going to roll our own.  (hence the ``simple'' code. ...I was using something like ``working pseudo code'' to drive a point home.)

Title: Re: How would you handle this: Timer function?
Post by: Kerry on September 13, 2006, 05:56:31 PM
Hi John, long time ...

Title: Re: How would you handle this: Timer function?
Post by: JohnK 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.)
Title: Re: How would you handle this: Timer function?
Post by: CAB 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.
Title: Re: How would you handle this: Timer function?
Post by: T.Willey 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.
Title: Re: How would you handle this: Timer function?
Post by: CAB 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?
Title: Re: How would you handle this: Timer function?
Post by: T.Willey 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.
Title: Re: How would you handle this: Timer function?
Post by: nivuahc on September 14, 2006, 12:09:18 PM
I was trying it with MILLISECS but couldn't manage to make it work.
Title: Re: How would you handle this: Timer function?
Post by: Greg B 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?
Title: Re: How would you handle this: Timer function?
Post by: nivuahc on September 14, 2006, 12:11:53 PM
yup
Title: Re: How would you handle this: Timer function?
Post by: nivuahc 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.
Title: Re: How would you handle this: Timer function?
Post by: Greg B on September 14, 2006, 12:14:29 PM
external application?
Title: Re: How would you handle this: Timer function?
Post by: nivuahc 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 (http://www.autoitscript.com/autoit3/). They even have a version of SciTE (http://www.scintilla.org/SciTE.html) with AutoIt syntax highlighting and help built-in. It's been a very helpful little tool to have in my toolbox over the years.
Title: Re: How would you handle this: Timer function?
Post by: T.Willey 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.
Title: Re: How would you handle this: Timer function?
Post by: LE 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.
Title: Re: How would you handle this: Timer function?
Post by: nivuahc 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
Title: Re: How would you handle this: Timer function?
Post by: nivuahc on September 14, 2006, 02:01:13 PM
I have no idea what the above means (okay, I have an idea...)
Title: Re: How would you handle this: Timer function?
Post by: nivuahc on September 14, 2006, 02:02:58 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.

The presentation is going to be AutoCAD running on a touch-screen monitor.
Title: Re: How would you handle this: Timer function?
Post by: T.Willey on September 14, 2006, 02:06:39 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
The only thing I can think of, is that you are not referenceing a windows dll file.  I'm using Windos2000, and Acad06.  You might have to ask one of the .Net gurus for help there.

Edit:  I can supply a dll file if you want, but I know most people don't want to trust a dll file, so I posted the code.  Let me know.
Title: Re: How would you handle this: Timer function?
Post by: nivuahc on September 14, 2006, 02:14:38 PM
missing resource, got it, found it, compiled it, now have a dll file.

So how do I load a DLL into AutoCAD?  :ugly:
Title: Re: How would you handle this: Timer function?
Post by: T.Willey on September 14, 2006, 02:16:43 PM
missing resource, got it, found it, compiled it, now have a dll file.

So how do I load a DLL into AutoCAD?  :ugly:
'netload' command.
Title: Re: How would you handle this: Timer function?
Post by: JohnK on September 14, 2006, 08:39:09 PM
A Script? Why do you want to use a script? AutoLisp is a procedural language, isn't that enough? (Its smarter then just a plain old script.)

CAB and T.Willey, the real problem would be with the scoping aspect. The procedure that does the counting would also have to control the other aspects as well -i.e. I don't really see a way to have a separate proced for handling one thing like timing and one for command handling.

Now, CAB you did hit on a interesting topic (well sorta.) We could build a master procedure for doing all that we need and allow the programmer to ``plug'' process' into that procedure. However that could prove to be difficult, so i think just a ``custom roll'' would have to be the way to go in this case.

In my opinion, all we really need as far as tools is a way for the user to `view the part' , a `way to control end user commands' and `a way to time the whole process'. Everything else like automatic loading and lists of drawings is almost trivial.

*** Sizzle, POP!  HOLD ON ONE SEC! (IDEA) ***
T.Willey, Your SeeSharp proced got me thinking a bit...theoretically speaking, We could:
o  Have lisp set up
o  Pass controll to a separate .DLL / app
o  Which would just start a countdown proced and pass back a var to AutoLisp.
    ( Potential problem! )
o  Have lisp watch environment for command and extra stuff.
o  Once timer is done the timer proced could send a cancel command to Acad and that would trigger the lisp to move on.

hummm...What do you think? Now obviously there are tons more we would have to do/account for, but my thought is that by moving the timer process outside of the acad session, we would not cause Acad to draw more system resources.
Title: Re: How would you handle this: Timer function?
Post by: JohnK on September 14, 2006, 08:42:51 PM
BTW, we would prolly have to use a plain old See+Plus or VBee .DLL so that would be no problems with dot-Butterfly-Net.
Title: Re: How would you handle this: Timer function?
Post by: ElpanovEvgeniy on September 15, 2006, 06:14:39 AM

Code: [Select]
(defun test-3dorbit (/ DOC PT1 PT2 R S V V1 VD VP W)
  ;;  ElpanovEvgeniy, Russia, Moscow, 2006
  ;;  Example of creation function "3dorbit"
  ;;  This variant spins only around of an origin coordinates
  ;;  and does not handle PAN...
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))
        v1  (vla-add (vla-get-Views doc) "tmp1")
        pt2 (trans (cadr (grread nil 5)) 1 2)
  ) ;_  setq
  (while (= (car (setq pt1 (grread nil 5))) 5)
    (setq r   (/ (getvar "VIEWSIZE") 4.)
          pt1 (trans (cadr pt1) 1 2)
          v   (trans
                ((lambda (x1 y1 x2 y2)
                   (list
                     (- x1 x2)
                     (- y1 y2)
                     (- (sqrt (abs (- (* R R) (* x1 x1) (* y1 y1))))
                        (sqrt (abs (- (* R R) (* x2 x2) (* y2 y2))))
                     ) ;_  -
                   ) ;_  list
                 ) ;_  lambda
                  (car pt2)
                  (cadr pt2)
                  (car pt1)
                  (cadr pt1)
                )
                2
                1
              ) ;_  trans
          pt2 pt1
          s   (/ r (distance '(0 0 0) (getvar "VIEWDIR")))
          vd  (mapcar (function (lambda (x) (* x s))) (getvar "VIEWDIR"))
          v   (mapcar (function +) vd v)
          s   (/ r (distance '(0 0 0) v))
          v   ((lambda (s) (list (* (car v) s) (* (cadr v) s) (* (caddr v) s)))
                (/ r (distance '(0 0 0) v))
              )
          w   (* (/ r (vla-get-Height (setq vp (vla-get-ActiveViewport doc)))) (vla-get-Width vp) 4.)
    ) ;_  setq
    (vla-put-Direction
      v1
      (vlax-3d-point v)
    ) ;_  vla-put-Direction
    (vla-SetView vp v1)
    (vla-put-Height vp (* r 4.))
    (vla-put-Width vp w)
    (vla-put-ActiveViewport doc vp)
  ) ;_  while
) ;_  defun
Title: Re: How would you handle this: Timer function?
Post by: nivuahc on September 15, 2006, 09:25:28 AM
ElpanovEvgeniy, that's very cool. Gorgeous, even. :)

I think his intent was to leave the view shaded, though, while it was being rotated. But that is definately one to stick into the bag of tricks.
Title: Re: How would you handle this: Timer function?
Post by: ElpanovEvgeniy on September 15, 2006, 11:17:10 AM
ElpanovEvgeniy, that's very cool. Gorgeous, even. :)

I think his intent was to leave the view shaded, though, while it was being rotated. But that is definately one to stick into the bag of tricks.


Code: [Select]
(defun test-3dorbit (/ PT1 PT2 R S V V1 VD W)
  ;;  ElpanovEvgeniy, Russia, Moscow, 2006
  ;;  Example of creation function "3dorbit"
  ;;  This variant spins only around of an origin coordinates
  ;;  and does not handle PAN...

  ;;  Add SadeMode
  ;;  (test-3dorbit)
  (setq
    v1  (entmakex
          (list
            '(0 . "VIEW")
            '(100 . "AcDbSymbolTableRecord")
            '(100 . "AcDbViewTableRecord")
            '(2 . "tmp1")
            '(70 . 0)
            (cons 40 (getvar "VIEWSIZE"))
            (cons 10 (getvar "VIEWCTR"))
            (cons
              41
              (* (getvar "VIEWSIZE")
                 (apply
                   (function /)
                   (getvar "SCREENSIZE")
                 ) ;_  apply
              ) ;_  *
            ) ;_  cons
            (cons 11 (getvar "VIEWDIR"))
            (cons 12 (getvar "TARGET"))
            (cons 42 (getvar "LENSLENGTH"))
            (cons 43 (getvar "FRONTZ"))
            (cons 44 (getvar "BACKZ"))
            (cons 50 (getvar "VIEWTWIST"))
            (cons 71 (getvar "VIEWMODE"))
            '(281 . 6)
            '(72 . 0)
          ) ;_  list
        ) ;_  entmakex
    pt2 (trans (cadr (grread nil 5)) 1 2)
  ) ;_  setq
  (while (= (car (setq pt1 (grread nil 5))) 5)
    (setq r   (/ (getvar "VIEWSIZE") 4.)
          r   (if (> r 1e10)
                1e10
                r
              ) ;_  if
          pt1 (trans (cadr pt1) 1 2)
          v   (trans
                ((lambda (x1 y1 x2 y2)
                   (list
                     (- x1 x2)
                     (- y1 y2)
                     (- (sqrt (abs (- (* R R) (* x1 x1) (* y1 y1))))
                        (sqrt (abs (- (* R R) (* x2 x2) (* y2 y2))))
                     ) ;_  -
                   ) ;_  list
                 ) ;_  lambda
                  (car pt2)
                  (cadr pt2)
                  (car pt1)
                  (cadr pt1)
                )
                2
                1
              ) ;_  trans
          pt2 pt1
          s   (/ r (distance '(0 0 0) (getvar "VIEWDIR")))
          vd  (mapcar (function (lambda (x) (* x s))) (getvar "VIEWDIR"))
          v   (mapcar (function +) vd v)
          s   (/ r (distance '(0 0 0) v))
          v   ((lambda (s) (list (* (car v) s) (* (cadr v) s) (* (caddr v) s)))
                (/ r (distance '(0 0 0) v))
              )
          w   (* (/ r (getvar "VIEWSIZE"))
                 (* (getvar "VIEWSIZE")
                    (apply
                      (function /)
                      (getvar "SCREENSIZE")
                    ) ;_  apply
                 ) ;_  *
                 4.
              ) ;_  *
    ) ;_  setq
    (entmod
      (subst (cons 41
                   (* (getvar "VIEWSIZE")
                      (apply
                        (function /)
                        (getvar "SCREENSIZE")
                      ) ;_  apply
                   ) ;_  *
             ) ;_  cons
             (assoc 41 (entget v1))
             (subst (cons 40 (getvar "VIEWSIZE"))
                    (assoc 40 (entget v1))
                    (subst (cons 11 v) (assoc 11 (entget v1)) (entget v1))
             ) ;_  subst
      ) ;_  subst
    ) ;_  entmod
    (entupd v1)
    (setview (tblsearch "VIEW" "tmp1"))
  ) ;_  while
  (entdel v1)
) ;_  defun
Title: Re: How would you handle this: Timer function?
Post by: nivuahc on September 15, 2006, 11:19:50 AM
Dude!

That rocks completely!  :kewl:
Title: Re: How would you handle this: Timer function?
Post by: ElpanovEvgeniy on September 15, 2006, 11:41:10 AM
Fix bag (entdel v1)

Code: [Select]
(defun test-3dorbit (/ PT1 PT2 R S V V1 VD W)
  ;;  ElpanovEvgeniy, Russia, Moscow, 2006
  ;;  Example of creation function "3dorbit"
  ;;  This variant spins only around of an origin coordinates
  ;;  and does not handle PAN...

  ;;  Add SadeMode
  ;;  (test-3dorbit)
  (if (tblsearch "VIEW" "tmp1")
    (setq
      v1  (tblobjname "VIEW" "tmp1")
      pt2 (trans (cadr (grread nil 5)) 1 2)
    ) ;_  setq
    (setq
      v1  (entmakex
            (list
              '(0 . "VIEW")
              '(100 . "AcDbSymbolTableRecord")
              '(100 . "AcDbViewTableRecord")
              '(2 . "tmp1")
              '(70 . 0)
              (cons 40 (getvar "VIEWSIZE"))
              (cons 10 (getvar "VIEWCTR"))
              (cons
                41
                (* (getvar "VIEWSIZE")
                   (apply
                     (function /)
                     (getvar "SCREENSIZE")
                   ) ;_  apply
                ) ;_  *
              ) ;_  cons
              (cons 11 (getvar "VIEWDIR"))
              (cons 12 (getvar "TARGET"))
              (cons 42 (getvar "LENSLENGTH"))
              (cons 43 (getvar "FRONTZ"))
              (cons 44 (getvar "BACKZ"))
              (cons 50 (getvar "VIEWTWIST"))
              (cons 71 (getvar "VIEWMODE"))
              '(281 . 6)
              '(72 . 0)
            ) ;_  list
          ) ;_  entmakex
      pt2 (trans (cadr (grread nil 5)) 1 2)
    ) ;_  setq
  ) ;_  if
  (while (= (car (setq pt1 (grread nil 5))) 5)
    (setq r   (/ (getvar "VIEWSIZE") 4.)
          r   (if (> r 1e10)
                1e10
                r
              ) ;_  if
          pt1 (trans (cadr pt1) 1 2)
          v   (trans
                ((lambda (x1 y1 x2 y2)
                   (list
                     (- x1 x2)
                     (- y1 y2)
                     (- (sqrt (abs (- (* R R) (* x1 x1) (* y1 y1))))
                        (sqrt (abs (- (* R R) (* x2 x2) (* y2 y2))))
                     ) ;_  -
                   ) ;_  list
                 ) ;_  lambda
                  (car pt2)
                  (cadr pt2)
                  (car pt1)
                  (cadr pt1)
                )
                2
                1
              ) ;_  trans
          pt2 pt1
          s   (/ r (distance '(0 0 0) (getvar "VIEWDIR")))
          vd  (mapcar (function (lambda (x) (* x s))) (getvar "VIEWDIR"))
          v   (mapcar (function +) vd v)
          s   (/ r (distance '(0 0 0) v))
          v   ((lambda (s) (list (* (car v) s) (* (cadr v) s) (* (caddr v) s)))
                (/ r (distance '(0 0 0) v))
              )
          w   (* (/ r (getvar "VIEWSIZE"))
                 (* (getvar "VIEWSIZE")
                    (apply
                      (function /)
                      (getvar "SCREENSIZE")
                    ) ;_  apply
                 ) ;_  *
                 4.
              ) ;_  *
    ) ;_  setq
    (entmod
      (subst (cons 41
                   (* (getvar "VIEWSIZE")
                      (apply
                        (function /)
                        (getvar "SCREENSIZE")
                      ) ;_  apply
                   ) ;_  *
             ) ;_  cons
             (assoc 41 (entget v1))
             (subst (cons 40 (getvar "VIEWSIZE"))
                    (assoc 40 (entget v1))
                    (subst (cons 11 v) (assoc 11 (entget v1)) (entget v1))
             ) ;_  subst
      ) ;_  subst
    ) ;_  entmod
    (entupd v1)
    (setview (tblsearch "VIEW" "tmp1"))
  ) ;_  while
) ;_  defun
Title: Re: How would you handle this: Timer function?
Post by: T.Willey on September 15, 2006, 11:58:52 AM
Nicely done Evgeniy!  I don't know/use views enough to have EVER come up with this bit of code.  I will study it and learn some new tricks.  Thanks for sharing.

Edit:  One thing you might want to add, is turning off (or making as small as possible) the cross hairs.
Title: Re: How would you handle this: Timer function?
Post by: ElpanovEvgeniy on September 15, 2006, 12:01:50 PM
Code: [Select]
(defun time-3dorbit (/ s)
  ;;  ElpanovEvgeniy, Russia, Moscow, 2006
  ;;  Timer for test-3dorbit
  ;; (time-3dorbit)
  (princ "\n tiner set 60 sec ")
  (princ)
  (setq s ((lambda (sec) (+ (* 86400 (- sec (fix sec))) 60)) (getvar "DATE")))
  (while (> s ((lambda (sec) (* 86400 (- sec (fix sec)))) (getvar "DATE")))
    (VL-CATCH-ALL-APPLY (function test-3dorbit) (list s))
  ) ;_  while
) ;_  defun
(defun test-3dorbit (sec / PT1 PT2 R S V V1 VD W)
  ;;  ElpanovEvgeniy, Russia, Moscow, 2006
  ;;  Example of creation function "3dorbit"
  ;;  This variant spins only around of an origin coordinates
  ;;  and does not handle PAN...

  ;;  Add SadeMode
  ;;  (test-3dorbit)
  (if (tblsearch "VIEW" "tmp1")
    (setq
      v1  (tblobjname "VIEW" "tmp1")
      pt2 (trans (cadr (grread nil 5)) 1 2)
    ) ;_  setq
    (setq
      v1  (entmakex
            (list
              '(0 . "VIEW")
              '(100 . "AcDbSymbolTableRecord")
              '(100 . "AcDbViewTableRecord")
              '(2 . "tmp1")
              '(70 . 0)
              (cons 40 (getvar "VIEWSIZE"))
              (cons 10 (getvar "VIEWCTR"))
              (cons
                41
                (* (getvar "VIEWSIZE")
                   (apply
                     (function /)
                     (getvar "SCREENSIZE")
                   ) ;_  apply
                ) ;_  *
              ) ;_  cons
              (cons 11 (getvar "VIEWDIR"))
              (cons 12 (getvar "TARGET"))
              (cons 42 (getvar "LENSLENGTH"))
              (cons 43 (getvar "FRONTZ"))
              (cons 44 (getvar "BACKZ"))
              (cons 50 (getvar "VIEWTWIST"))
              (cons 71 (getvar "VIEWMODE"))
              '(281 . 6)
              '(72 . 0)
            ) ;_  list
          ) ;_  entmakex
      pt2 (trans (cadr (grread nil 5)) 1 2)
    ) ;_  setq
  ) ;_  if
  (while (and (= (car (setq pt1 (grread nil 5))) 5)
              (> sec ((lambda (sec) (* 86400 (- sec (fix sec)))) (getvar "DATE")))
         ) ;_  and
    (setq r   (/ (getvar "VIEWSIZE") 4.)
          r   (if (> r 1e10)
                1e10
                r
              ) ;_  if
          pt1 (trans (cadr pt1) 1 2)
          v   (trans
                ((lambda (x1 y1 x2 y2)
                   (list
                     (- x1 x2)
                     (- y1 y2)
                     (- (sqrt (abs (- (* R R) (* x1 x1) (* y1 y1))))
                        (sqrt (abs (- (* R R) (* x2 x2) (* y2 y2))))
                     ) ;_  -
                   ) ;_  list
                 ) ;_  lambda
                  (car pt2)
                  (cadr pt2)
                  (car pt1)
                  (cadr pt1)
                )
                2
                1
              ) ;_  trans
          pt2 pt1
          s   (/ r (distance '(0 0 0) (getvar "VIEWDIR")))
          vd  (mapcar (function (lambda (x) (* x s))) (getvar "VIEWDIR"))
          v   (mapcar (function +) vd v)
          s   (/ r (distance '(0 0 0) v))
          v   ((lambda (s) (list (* (car v) s) (* (cadr v) s) (* (caddr v) s)))
                (/ r (distance '(0 0 0) v))
              )
          w   (* (/ r (getvar "VIEWSIZE"))
                 (* (getvar "VIEWSIZE")
                    (apply
                      (function /)
                      (getvar "SCREENSIZE")
                    ) ;_  apply
                 ) ;_  *
                 4.
              ) ;_  *
    ) ;_  setq
    (entmod
      (subst (cons 41
                   (* (getvar "VIEWSIZE")
                      (apply
                        (function /)
                        (getvar "SCREENSIZE")
                      ) ;_  apply
                   ) ;_  *
             ) ;_  cons
             (assoc 41 (entget v1))
             (subst (cons 40 (getvar "VIEWSIZE"))
                    (assoc 40 (entget v1))
                    (subst (cons 11 v) (assoc 11 (entget v1)) (entget v1))
             ) ;_  subst
      ) ;_  subst
    ) ;_  entmod
    (entupd v1)
    (setview (tblsearch "VIEW" "tmp1"))
  ) ;_  while
) ;_  defun
Title: Re: How would you handle this: Timer function?
Post by: ElpanovEvgeniy on September 15, 2006, 02:11:16 PM
I was interested with this problem, and I often recollected it!
To release a ideas for work, today I have allocated time, for its decision... :-)

Last variant, shows as it to start for a time, that it would be impossible to stop.
Title: Re: How would you handle this: Timer function?
Post by: Greg B on September 15, 2006, 02:18:48 PM
that it would be impossible to stop.

Nothing is impossible to stop!
Title: Re: How would you handle this: Timer function?
Post by: ElpanovEvgeniy on September 15, 2006, 02:25:51 PM
The program is indifferent to buttons of the mouse and the keyboard...
Certainly, all can be stopped.
I with you agree! (For example a hammer...)
Title: Re: How would you handle this: Timer function?
Post by: Greg B on September 15, 2006, 02:27:31 PM
The program is indifferent to buttons of the mouse and the keyboard...
Certainly, all can be stopped.
I with you agree! (For example a hammer...)

Kinda extreme, but yeah that would work.  I was thinking the power button.
Title: Re: How would you handle this: Timer function?
Post by: ElpanovEvgeniy on September 15, 2006, 02:32:06 PM
If I have correctly understood, the program is necessary for presentation and should not stop...
I badly understand English and could understand explanations incorrectly.  :-(
Title: Re: How would you handle this: Timer function?
Post by: Greg B on September 15, 2006, 02:36:28 PM
No....you did just fine!
Title: Re: How would you handle this: Timer function?
Post by: ElpanovEvgeniy on September 15, 2006, 02:46:02 PM
I do not have time to complete this program (command PAN) is not processed, if who that will make, it will be interesting to look!
Title: Re: How would you handle this: Timer function?
Post by: T.Willey on September 15, 2006, 02:47:40 PM
If I have correctly understood, the program is necessary for presentation and should not stop...
I badly understand English and could understand explanations incorrectly.  :-(
No....you did just fine!
Second!
Title: Re: How would you handle this: Timer function?
Post by: nivuahc on September 15, 2006, 02:52:24 PM
I do not have time to complete this program (command PAN) is not processed, if who that will make, it will be interesting to look!

Evgeniy!

The way the routine works right now is more than anyone could ask for. I'm completely blown away by how awesome that is!

Title: Re: How would you handle this: Timer function?
Post by: JohnK on September 17, 2006, 10:55:38 PM
Yes, That  is very nice Elpanov!

How's the main program going now nivuahc?
Title: Re: How would you handle this: Timer function?
Post by: ElpanovEvgeniy on September 18, 2006, 07:57:17 AM
During work it is possible to use PAN and ZOOM in a transparent mode.
 :-)

Code: [Select]
(defun time-3dorbit (/ s)
  ;;  ElpanovEvgeniy, Russia, Moscow, 2006
  ;;  Timer for test-3dorbit
  ;; (time-3dorbit)
  (princ "\n tiner set 60 sec ")
  (setq s ((lambda (sec) (+ (* 86400 (- sec (fix sec))) 60)) (getvar "DATE")))
  (while (> s ((lambda (sec) (* 86400 (- sec (fix sec)))) (getvar "DATE")))
    (VL-CATCH-ALL-APPLY (function test-3dorbit) (list s))
  ) ;_  while
  (princ)
) ;_  defun
(defun my-3dorbit (sec / PT1 PT2 R S V V1 VD W)
  ;;  ElpanovEvgeniy, Russia, Moscow, 2006
  ;;  Function "3dorbit"
  ;;  During work it is possible to use PAN and ZOOM
  ;;  in a transparent mode.
  ;;  (my-3dorbit)
  (if (tblsearch "VIEW" "tmp1")
    (setq
      v1  (tblobjname "VIEW" "tmp1")
      pt2 (trans (cadr (grread nil 5)) 1 2)
    ) ;_  setq
    (setq
      v1  (entmakex
            (list
              '(0 . "VIEW")
              '(100 . "AcDbSymbolTableRecord")
              '(100 . "AcDbViewTableRecord")
              '(2 . "tmp1")
              '(70 . 0)
              (cons 40 (getvar "VIEWSIZE"))
              (cons 10 (getvar "VIEWCTR"))
              (cons
                41
                (* (getvar "VIEWSIZE")
                   (apply
                     (function /)
                     (getvar "SCREENSIZE")
                   ) ;_  apply
                ) ;_  *
              ) ;_  cons
              (cons 11 (getvar "VIEWDIR"))
              '(12 0. 0. 0.)
              (cons 42 (getvar "LENSLENGTH"))
              (cons 43 (getvar "FRONTZ"))
              (cons 44 (getvar "BACKZ"))
              (cons 50 (getvar "VIEWTWIST"))
              (cons 71 (getvar "VIEWMODE"))
              '(281 . 6)
              '(72 . 0)
            ) ;_  list
          ) ;_  entmakex
      pt2 (trans (cadr (grread nil 5)) 1 2)
    ) ;_  setq
  ) ;_  if
  (while (and (= (car (setq pt1 (grread nil 5))) 5)
              (> sec ((lambda (sec) (* 86400 (- sec (fix sec)))) (getvar "DATE")))
         ) ;_  and
    (setq r   (/ (getvar "VIEWSIZE") 4.)
          w   (trans (getvar "VIEWCTR") 1 2)
          pt1 (trans (cadr pt1) 1 2)
          v   (trans
                ((lambda (x1 y1 x2 y2)
                   (list
                     (- x1 x2)
                     (- y1 y2)
                     (- (sqrt (abs (- (* R R) (* x1 x1) (* y1 y1))))
                        (sqrt (abs (- (* R R) (* x2 x2) (* y2 y2))))
                     ) ;_  -
                   ) ;_  list
                 ) ;_  lambda
                  (- (car pt2) (car w))
                  (- (cadr pt2) (cadr w))
                  (- (car pt1) (car w))
                  (- (cadr pt1) (cadr w))
                )
                2
                1
              ) ;_  trans
          pt2 pt1
          s   (/ r (distance '(0. 0. 0.) (getvar "VIEWDIR")))
          vd  (mapcar (function (lambda (x) (* x s))) (getvar "VIEWDIR"))
          v   (mapcar (function +) vd v)
          s   (/ r (distance '(0. 0. 0.) v))
          v   ((lambda (s) (list (* (car v) s) (* (cadr v) s) (* (caddr v) s)))
                (/ r (distance '(0. 0. 0.) v))
              )
          w   (* (/ r (getvar "VIEWSIZE"))
                 (* (getvar "VIEWSIZE")
                    (apply
                      (function /)
                      (getvar "SCREENSIZE")
                    ) ;_  apply
                 ) ;_  *
                 4.
              ) ;_  *
    ) ;_  setq
    (entmod
      (list
        (cons -1 v1)
        '(0 . "VIEW")
        '(100 . "AcDbSymbolTableRecord")
        '(100 . "AcDbViewTableRecord")
        '(2 . "tmp1")
        '(70 . 0)
        (cons 40 (getvar "VIEWSIZE"))
        (cons 10 (trans (getvar "VIEWCTR") 1 2))
        (cons
          41
          (* (getvar "VIEWSIZE")
             (apply
               (function /)
               (getvar "SCREENSIZE")
             ) ;_  apply
          ) ;_  *
        ) ;_  cons
        (cons 11 v)
        '(12 0. 0. 0.)
        (cons 42 (getvar "LENSLENGTH"))
        (cons 43 (getvar "FRONTZ"))
        (cons 44 (getvar "BACKZ"))
        (cons 50 (getvar "VIEWTWIST"))
        (cons 71 (getvar "VIEWMODE"))
        '(281 . 6)
        '(72 . 0)
      ) ;_  list
    ) ;_  entmod
    (entupd v1)
    (setview (tblsearch "VIEW" "tmp1"))
  ) ;_  while
) ;_  defun
Title: Re: How would you handle this: Timer function?
Post by: jxphklibin on August 19, 2009, 02:21:32 AM
 Waiting!!!!
Title: Re: How would you handle this: Timer function?
Post by: ElpanovEvgeniy on August 19, 2009, 05:20:33 AM
Waiting!!!!


You wish to lift this theme?
Title: Re: How would you handle this: Timer function?
Post by: CAB on August 19, 2009, 08:30:35 AM
LeeBen what are you waiting for exactly?
Title: Re: How would you handle this: Timer function?
Post by: Shinyhead on August 19, 2009, 09:26:45 AM
Not to derail things to much, but wouldn't having an application open and close a series of 3D dwfs be easier and look better? 
Title: Re: How would you handle this: Timer function?
Post by: jxphklibin on August 19, 2009, 09:39:17 PM
LeeBen what are you waiting for exactly?


Posts made the wrong place, sorry!