Results 1 to 9 of 9

Thread: Usage of 'Command' and alternatives in LISP routines

  1. #1
    I could stop if I wanted to CEHill's Avatar
    Join Date
    2006-05
    Location
    TN
    Posts
    327
    Login to Give a bone
    0

    Question Usage of 'Command' and alternatives in LISP routines

    Many routines seem to use command from beginner-style tutorials that I have seen.
    As a beginner (for some time), I have heard from other sources that I should not use command and am confused.

    Please clarify the use of command and offer any alternatives?

    Scared to move!
    Yours,

    Clint
    Hill

    ------------------
    CAD Systems Operation and Management
    Chemical Plant Process + Mechanical Design Focus Areas

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Lightbulb Re: Usage of 'Command' and alternatives in LISP routines

    Quote Originally Posted by Clinton.Hill
    Many routines seem to use command from beginner-style tutorials that I have seen.
    As a beginner (for some time), I have heard from other sources that I should not use command and am confused.

    Please clarify the use of command and offer any alternatives?

    Scared to move!
    Nothing wrong with using (command). It's a valid lisp function.

    It's the slowest of the various methods though, so if you are doing a lot of geometry construction, you might want to look at the other alternatives.

    All of the following functions do the same thing, draw 2000 lines.

    "LINE1" uses (command), it takes about 5.8 seconds on my machine
    "LINE2" uses (entmake), it takes about 0.3 seconds on my machine
    "LINE3" uses (vla-addline), it takes about 0.6 seconds on my machine

    If you are drawing 2 or 3 lines, you won't notice the difference, but with a couple of thousand, you can see (entmake) is much quicker.

    Code:
    (defun date2sec ()
      (setq s (getvar "DATE"))
      (setq seconds (* 86400.0 (- s (fix s))))
    )
    
    (defun C:line1 ( / i timer endtimer)
      (setq i 1 timer (date2sec))
      (while (< i 2000)
        (command "._line" (list i i 0.0) (list (+ 2 i)(+ 3 i) 0.0) "")
        (setq i (1+ i))
      )
      (setq endtimer (date2sec))
      (alert (rtos (- endtimer timer) 2 8))
    )
    
    (defun C:line2 ( / i timer endtimer)
      (setq i 1 timer (date2sec))
      (while (< i 2000)
        (entmake (list
    	       (cons 0 "LINE")
    	       (cons 10 (list i i 0.0))
    	       (cons 11 (list (+ 2 i)(+ 3 i) 0.0))
    	     )
        )    
        (setq i (1+ i))
      )
      (setq endtimer (date2sec))
      (alert (rtos (- endtimer timer) 2 8))
    )
    
    
    (defun C:line3 ( / i timer endtimer)
      (vl-load-com)
      (setq i 1 timer (date2sec) ms
    	 (vla-get-modelspace
    	   (vla-get-ActiveDocument
    	     (vlax-get-acad-object))))
      (while (< i 2000)
        (vla-addline ms
          (vlax-3d-point (list i i 0.0))
          (vlax-3d-point (list (+ 2 i)(+ 3 i) 0.0))
        )
        (setq i (1+ i))
      )
      (setq endtimer (date2sec))
      (alert (rtos (- endtimer timer) 2 8))
    )
    R.K. McSwain | CAD Panacea |

  3. #3
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Usage of 'Command' and alternatives in LISP routines

    What can you do without command ?

    I feel that there is a ranking level of making program in lisp by programmers
    Lowest in the ranking level is to use scriptfiles,
    but they are very useful sometimes, and sometimes a must.

    Second last in the ranking level is to use command,
    you can use entmake to make a line, but also command
    and I will tell you that sometimes is simple the best.

    But there is a place in the programmers environment, there they can not use command. . .
    . . . in reactors.

    If you not programming reactors . . . use command as much as you like.

    : ) Happy Computing !

    kennet

  4. #4
    I could stop if I wanted to CEHill's Avatar
    Join Date
    2006-05
    Location
    TN
    Posts
    327
    Login to Give a bone
    0

    Default Re: Usage of 'Command' and alternatives in LISP routines

    Hanging around with the 20,000 ft programming crowd is scary for me at this stage!

    Reactors are not what I am after right now. I do appreciate saving time.
    That's why I am complicating my life with programming in the first place.

    For now, it is just one foot in front of the other.





    Yours,

    Clint
    Hill

    ------------------
    CAD Systems Operation and Management
    Chemical Plant Process + Mechanical Design Focus Areas

  5. #5
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: Usage of 'Command' and alternatives in LISP routines

    Quote Originally Posted by kennet.sjoberg
    If you not programming reactors . . .
    ....and if you want your shortcuts transparently too .

    For example, if you want to set your object snap, either

    Code:
    (defun c:OsEnd ()
    (command "osnap" "end")
    (princ)
    )
    or
    Code:
    (defun c:OsEnd ()
    (setvar "osmode" 1)
    (princ)
    )
    will do. But the first one cannot be called transparently with the help of any function keys or simply 'OsEnd, but the second one will work.

    Regards,
    AH

  6. #6
    I could stop if I wanted to CEHill's Avatar
    Join Date
    2006-05
    Location
    TN
    Posts
    327
    Login to Give a bone
    0

    Default Re: Usage of 'Command' and alternatives in LISP routines

    So not only can command not be used with activex (reactors) but also has some limitations.
    One is that it is not transparent.

    Correct? Are there any others?


    Yours,

    Clint
    Hill

    ------------------
    CAD Systems Operation and Management
    Chemical Plant Process + Mechanical Design Focus Areas

  7. #7
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: Usage of 'Command' and alternatives in LISP routines

    Commands can not be used with ObjectDBX programing.

  8. #8
    AUGI Addict sinc's Avatar
    Join Date
    2004-02
    Location
    Colorado
    Posts
    1,986
    Login to Give a bone
    0

    Default Re: Usage of 'Command' and alternatives in LISP routines

    Quote Originally Posted by Clinton.Hill
    So not only can command not be used with activex (reactors) but also has some limitations.
    One is that it is not transparent.

    Correct? Are there any others?

    Linework drawn with "COMMAND" may yield incorrect results, due to running osnaps. If you want to draw objects on the screen using "COMMAND", you must disable all active OSNAPs while creating the linework, or you will have unpredictable results.

    And of course, if you do something like this, you should make sure your code has the correct error-trapping, so that you can restore the OSNAPs to the original settings, even if the user hits ESC. Otherwise, you end up with "bad" code like some of that in Land Desktop, where the user's OSNAPs get reset if the user hits ESC while running the command.

  9. #9
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: Usage of 'Command' and alternatives in LISP routines

    Good tip sinc.
    I often use the None option within the command, like this:
    Code:
    (command "_.line" "_non" pt1 "_non" pt2 "")

Similar Threads

  1. LISP routines
    By dawn.pedersen309807 in forum AutoLISP
    Replies: 25
    Last Post: 2012-08-28, 07:36 PM
  2. how do you call other lisp routines with lisp?
    By moises.y969653 in forum AutoLISP
    Replies: 1
    Last Post: 2011-02-06, 01:01 PM
  3. Lisp Routines
    By Shadrak in forum AutoCAD Customization
    Replies: 4
    Last Post: 2009-10-08, 01:32 AM
  4. Lisp Routines
    By jsnow in forum AutoCAD General
    Replies: 2
    Last Post: 2009-04-16, 05:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •