simple Save Date LISP routine (troubles)

Discussion in 'AutoCAD' started by Matt, Feb 3, 2004.

  1. Matt

    Matt Guest

    This works perfect on my machine, but it won't work the first time on my
    other machines. When you key up "SD" and the block doesn't exist it
    should ask where to insert, pull the Dimscale and everything should be
    fine. But on anyone's machine except mine, it isn't pulling the
    time/date or anything. It tries to enter the string on the next command
    line - so the output is "Jan 01,1980 - 12:00". But I am shooting for
    "Drawing1.dwg - 02/03/04 - 10:29 - JMG", and if I run the lisp again it
    is corrected. Again, it works fine on my machine, but when I move it to
    another computer it doesn't work.

    (as a side note, I would also like to know how to get a default input
    when prompted for the Insert question)

    Thanks for any help, I am confused.

    Here's the code...
    ================================================

    ; SAVEDATE.LSP

    (defun C:SD (/ cdate ss edata ename)
    (setq cdate (rtos (getvar "cdate") 2 6)
    cdate
    (strcat
    (getvar "dwgname")
    " - "
    (substr cdate 5 2)
    "/"
    (substr cdate 7 2)
    "/"
    (substr cdate 3 2)
    " - "
    (substr cdate 10 2)
    ":"
    (substr cdate 12 2)
    ;
    ; HEY YOU!!!!!!!! - CHANGE INITIALS BELOW!!!!!!!!!!!!!!
    ;
    " - JMG"
    ;
    ; (getvar "loginname")
    ; the above line can be used to pull the Windows Login Name
    )
    )
    (if
    (setq ss (ssget "X" '((0 . "INSERT") (2 . "SAVEDATE"))))
    (progn
    (setq ename (entnext (ssname ss 0))
    edata (entget ename)
    edata (subst (cons 1 cdate) (assoc 1 edata) edata)
    )
    (entmod edata)
    (entupd ename)
    )
    (progn
    (princ "\nSAVEDATE block not found.\n")
    (initget "Y N")
    (setq ans (getkword "Insert <Y/N>:"))
    (if (= ans "Y")
    (progn
    (setq ins (getpoint "Enter Insertion point: "))
    (command "INSERT" "SAVEDATE" ins (*(getvar "dimscale")) (*(getvar
    "dimscale")) "0" cdate))
    )
    )
    )
    (princ)
    )

    ; End Of File
     
    Matt, Feb 3, 2004
    #1
  2. Matt

    ECCAD Guest

    Matt,
    The program (as written) works the 1st time on my machine.
    I'm using Win98, R2002 standard, no frills.

    I notice that IF I type cdate at the Command: prompt, it returns
    a value. I think you should change the
    (setq cdate (rtos (getvar "cdate") 2 6)
    cdate
    (strcat
    (getvar "dwgname")
    " - "
    (substr cdate 5 2)
    "/"
    (substr cdate 7 2)
    "/"
    (substr cdate 3 2)
    " - "
    (substr cdate 10 2)
    ":"
    (substr cdate 12 2)
     
    ECCAD, Feb 3, 2004
    #2
  3. Matt

    Jeff Mishler Guest

    Matt,
    As Bob said, it works fine on mine also. But, I had to create the "savedate"
    block w/attribute. When I made a different one that had the attribute set as
    "preset", it errored as you describe. So, check your block and make sure the
    att. isn't preset.

    Jeff
     
    Jeff Mishler, Feb 3, 2004
    #3
  4. Matt

    Matt Guest

    I just determined what it was, I have several machines that when you
    instert a block the attributes remain blank. I found a fresh install on
    an unused machine and it worked, so I knew something was up.

    How do I get it to prompt for attributes again??
     
    Matt, Feb 3, 2004
    #4
  5. Matt

    Jeff Mishler Guest

    attreq
    0 = defaults
    1 = prompts

     
    Jeff Mishler, Feb 3, 2004
    #5
  6. Matt

    Matt Guest

    Thanks... you the man...

     
    Matt, Feb 3, 2004
    #6
  7. Matt (and to all),

    I see many people using a function with (getvar "cdate") and breaking it up
    with a function. There IS an easier way: (Watch out for word wrap)

    (setq mydate (menucmd "M=$(edtime,$(getvar,date),DD\"/\"MO\"/\"YY\" -
    \"H:MMam/pm)")
    username "JMG"
    mydate (strcat (getvar "dwgname") " - " mydate " - " username)
    )

    There - 3 lines to do the same as the first 12 lines of your code :) Look up
    (menucmd) in the AutoLISP reference, and the EDTIME function in the DIESEL
    catalog of the customization reference to learn how to format this.

    I agree with Jeff about why your function may not be working. However, I
    will investigate further...
     
    Phil Kenewell, Feb 3, 2004
    #7
  8. Have you thought about using the express tools Rtext object to incorporate
    all that stuff automatically?
    In R14 and earlier, I had a datestamp similar to what you are attempting,
    but replaced with Rtext and it's all automatically updated now.

    The string I use for Rtext is:

    $(if,$(eq,$(getvar, "ctab"),"Model"),"",$(getvar, "ctab")
    in )$(upper,$(getvar, "dwgprefix")$(substr,$(getvar,
    "dwgname"),1,$(-,$(strlen,$(getvar, "dwgname")),4)))
    $(if,$(eq,$(getvar,"userr3"),0),"",[1:$(getvar,"userr3")])

    and
     
    Allen Johnson, Feb 3, 2004
    #8
  9. $(edtime, 0,M/D/YYYY)
    [$(if,$(eq,$(getvar,"users1"),""),$(getvar,"loginname"),$(getvar,"users1"))]

    In my mnl file I use the code below to generate initials from the network
    loginname:

    (defun name ( / namlist)
    (setq namlist '(("ALLEN" "ASJ")
    ("ANJIE" "AJB")
    ("AUDRA" "AMD")
    ("BRENT" "BAP")
    ("BRUCE" "CBN")
    ("CELESTE" "CKS")
    ("DESIREE" "DEM")
    ("ERIC" "ECW")
    ("JON" "JDL")
    ("KEN" "KRV")
    ("LUC" "JDL")
    ("MARKH" "MJH")
    ("MARKM" "MAM")
    ("RON" "RLB")
    )
    nam (strcase (getvar "loginname"))
    )

    (if (assoc nam namlist)
    (cadr (assoc nam namlist))
    (substr nam 1 3)
    )

    )

    (setvar "USERS1" (name))
     
    Allen Johnson, Feb 3, 2004
    #9
  10. Oh, and USERR3 is set to the dwg scale, i.e. 96 for 1/8", 24 for 1/2", etc.
     
    Allen Johnson, Feb 3, 2004
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.