Results 1 to 7 of 7

Thread: Need advice on sequencer Lisp

  1. #1
    Active Member
    Join Date
    2009-03
    Posts
    63
    Login to Give a bone
    0

    Question Need advice on sequencer Lisp

    So from time to time I run into situations where I find myself running the same series of commands over and over again. Previously if I felt it would save time I would bang out a quick little temporary sequencer routine so I could just hit enter and run the next command or autolisp function in the sequence, but now I'm trying to put together one I can define on the fly, and be something I can share around to other users in my company but I have hit one snag, I'm hoping someone has some good input. the code is as follows

    Code:
    ;SEQUENCER DEFINITION FUNCTION
    (DEFUN C:SETSEQUENCER ( / TX1 TX2) ;GLOBAL *SEQ-LIST* *SEQ-CNTR*
    (SETQ *SEQ-LIST* (LIST) *SEQ-CNTR* 0)
    (WHILE (NOT (= (SETQ TX1 (GETSTRING (STRCAT "ENTER COMMAND " (ITOA (+ 1 *SEQ-CNTR*)) ":\n "))) ""))
     (IF <EVALUTAE IF TX1 IS AN AUTOCAD COMMAND>;<----------------------------------------------------------------need advice here
      (SETQ TX2 "COM")
      (PROGN (SETQ TX2 "FN" TX1 (STRCAT "C:" TX1))))
     (SETQ *SEQ-LIST* (APPEND *SEQ-LIST* (LIST (LIST TX2 TX1))))
     (SETQ *SEQ-CNTR* (+ 1 *SEQ-CNTR*))
    )
    (SETQ *SEQ-CNTR* 0)
    (PRINC "SEQUENCE SET!\n")
    (PRINC)
    )
    
    ;MAIN SEQUENCER FUNCTION
    (DEFUN C:SEQUENCER ( / TMP)
    (IF (AND *SEQ-CNTR* *SEQ-LIST*) (PROGN
    
    (SETQ TMP (NTH *SEQ-CNTR* *SEQ-LIST*))
    (IF (= TMP NIL)
     (PROGN
      (SETQ *SEQ-CNTR* 0)
      (SETQ TMP (NTH *SEQ-CNTR* *SEQ-LIST*))
     ))
    (COND
     ((= (CAR TMP) "COM")
      (PRINC (STRCAT "EXECUTING COMMAND " (ITOA (+ 1 SEQ-CNTR*))))
      (COMMAND (CADR TMP)))
     ((= (CAR TMP) "FN")
      (PRINC (STRCAT "EXECUTING COMMAND " (ITOA (+ 1 SEQ-CNTR*))))
      (EVAL (LIST (READ (CADR TMP)))))
     (T (PRINC)))
    (SETQ *SEQ-CNTR* (+ 1 *SEQ-CNTR*))
    
    ))
    (PRINC)
    )
    The part I've marked above is where I'm running into the snag. For debugging purposes I just used "OR" with several "=" functions to check if the code as a whole works, and it does. What I want to know is if anyone has an easier way to check if the string in TX1 correlates to an autocad command without using a cumbersome "OR" "=" "=" "=" "=" and manually putting in all the commands I can think of.

    If nothing else I'll have the user input whether the input is an autocad command or a lisp function, but honestly we have some people here who don't know the difference so that route only really make the routine useful for myself. And I'd like to avoid unnecessary steps.

    After I figure this bit I can spit shine this, its still kind of set up from my debugging.

    Thanks all!

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Need advice on sequencer Lisp

    There are a lot of ways to do this.

    AutoCAD has a macro recorder.

    You can find all of the LISP functions in the (atoms-family 1)

    You can capture the command line and record the steps directly.

    Peter
    AutomateCAD

  3. #3
    Active Member
    Join Date
    2009-03
    Posts
    63
    Login to Give a bone
    0

    Default Re: Need advice on sequencer Lisp

    The macro recorder is a useful tool and definitely has it's place, but doesn't play well with dialogue boxes and it's not what I'm after here. Ditto with command line capture.

    I will admit that maybe I don't completely understand the macro recorder, and its possible to do what I'm after with that. For instance, (and this is just an example, not what I want to do specifically) lets say I have a bunch of things I want to identify. First I want to run a lisp I have that grabs the raw description from a COGO point I click and parses out the useful text and copies it to the clipboard. Next I want to insert a block, that block will be different depending on what I'm labeling, sometimes that block will have attributes that I need to enter info for, sometimes it wont. Then I want to rotate the block to align with linework. Then I want to run MLeader, set start and end points to where they make sense, then paste the text from clipboard, make any changes I need to fix spelling etc then confirm the text. Sometimes I'll want to go into the options of MLeader and add extra vertices to the leader, sometimes I wont. Then I want to run those same 4 commands over and over again in that order on anywhere from 30-300 points. I'll say up front this is JUST AN EXAMPLE, I know full well that civil 3d has styles and labels in place to handle most of what I just mentioned and we use them... I'm just trying to give an example. If macro recorder can handle that with all the variable user inputs and dialogue boxes, then I'll bone up on that.

    I'll be adding an (atoms-family) function when I'm spit shinning the lisp and adding the error trapping, but that's only useful for positively identifying lisp functions, which I wasn't having trouble to begin with. For instance (atoms-family 1 (list "MOVE" "LINE")) returns (nil nil). If there was a similar function I could use to identify native autocad commands then that would be exactly what I'm looking for.

    Thanks for your input, and if you can give me any insight on whether the macro recorder can do what I'm after I'll look into it. Thank you

  4. #4
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Need advice on sequencer Lisp

    If you wanted to run AutoCAD commands you can use this syntax.

    P=

    Code:
    (vl-load-com)
    (vl-cmdf "pline")
    (while (= (getvar "cmdactive") 1)
     (vl-cmdf pause)
    )
    AutomateCAD

  5. #5
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    560
    Login to Give a bone
    0

    Default Re: Need advice on sequencer Lisp

    Interesting Karelcad writes a .net code for its macro recorder so you can edit it, v's Autocad Macro recorder which to me has limited editing/customising ability its like its own new language. By the time you have worked it out, probably done it in lisp and its working.

  6. #6
    Active Member
    Join Date
    2009-03
    Posts
    63
    Login to Give a bone
    0

    Default Re: Need advice on sequencer Lisp

    Thanks Peter, that vl-cmdf might actually be what I'm looking for. I just gotta reverse the order I'm checking. Use (atoms-family) to determine if the string provided is a loaded lisp function, else run as a command with (vl-cmdf) and it if turns out the text supplied isn't either of those, nothing will execute. Build in some error trapping and I think this'll work! Thanks!

  7. #7
    Active Member
    Join Date
    2009-03
    Posts
    63
    Login to Give a bone
    0

    Default Re: Need advice on sequencer Lisp

    Actually, it might work reversing the check order even if I used (command)... I do tend to focus on doing something in a certain order and forget to stop and look outside the box...

Similar Threads

  1. Need advice!
    By Sonny Suyitno in forum Inventor - General
    Replies: 5
    Last Post: 2008-03-24, 08:48 PM
  2. PDF Advice
    By Roger Evans in forum Revit Architecture - General
    Replies: 2
    Last Post: 2004-09-09, 12:31 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
  •