Problem with a lisp routine.

Discussion in 'AutoCAD' started by matrixesinc, Jan 28, 2005.

  1. matrixesinc

    matrixesinc Guest

    OK BELOW IS A KEWL LISP WE HAVE SETUP TO ADD A DATE AND THE DRAWING NAME TO THE SIDE OF A DRAWING. IT'S SUPPOSED TO ALSO ERASE A PREVIOUS STAMP THAT EXISTS, AND REPLACE IT. HOWEVER, IT WORKS ON ONE OF OUR NOTEPADS ALL OF THE TIME, BUT ON MINE IS VERY FINICKY, AND WILL SOMETIMES ERASE THE TITLE BLOCK LINE INSTEAD OF JUST INSERTING TEXT OVER ON THE EDGE. I COULD USE SOME REVIEW OF THIS CODE AS I AM NOT A LISP EXPERT.

    (Setq CONAME " DWG#: ")
    (Setq Status " ")

    ;System ID
    ;(SETQ SYS(GETENV "USER"))
    ;(IF(= SYS nil))
    (SETQ SYS "My company")

    ;Stamp Date,Time & Name on Drawing Border
    (Defun MATRIXDWG (/ DWG DNAME DDATE DATE SIZE HORZ HORZ1)


    (Setq DWG (Getvar "DWGNAME"))
    (setq Dname (strcase DWG))


    (Setq DDATE (Getvar "CDATE"))
    (Setq DDATE (rtos DDATE 2 6)) ;Convert date to a string
    (Setq DATE (Strcat (substr DDATE 5 2) "/" ;MM extracted
    (substr DDATE 7 2) "/" ;DD extracted
    (substr DDATE 3 2) " " ;YY extracted
    (substr DDATE 10 2) ":" ;HH extracted
    (substr DDATE 12 2) ":" ;MM extracted
    (substr DDATE 14 2))) ;SS extracted
    (command ".ZOOM" "E") ;Regen drawing

    (setq SIZE (getvar "EXTMAX")) ;get drawing size

    (setvar "TEXTSIZE" 0.15) ;text height
    (setq CT (/ (getvar"TEXTSIZE") 2)) ;text middle
    (setq HT (* (getvar"TEXTSIZE") 1.125)) ;ct option
    (setq P1 (list (car SIZE) 0.0)) ;stamp location
    (setq P2 (list (- (car SIZE) CT) 23.5)) ;stamp location
    (setq SS1 (ssget "C" P1 P2)) ;select objects
    (setq CNT 0)
    (if (/= SS1 nil) (setq CNT (sslength SS1))) ;objects found

    ;delete all objects from selection set SS1
    (if (> CNT 0)
    (repeat CNT
    (cdr(assoc 0(entget(setq EN(ssname SS1(setq CNT(1- CNT)))))))
    (entdel EN)(ssdel EN SS1))
    )


    ;compare limits to extents, set limits to extents if req'd
    (setq limx (round (car (getvar "LIMMAX"))))
    (setq limy (round (cadr (getvar "LIMMAX"))))
    (setq limxy (list limx limy))

    (setq extx (round (car (getvar "EXTMAX"))))
    (setq exty (round (cadr (getvar "EXTMAX"))))
    (setq extxy (list extx exty))

    (if (< limx extx) (setvar "LIMMAX" extxy))
    (Command ".ZOOM" "A") ;zoom to recalculate extmax



    ;*******************************************************************************************
    ;* Date stamp command sequence *************************************************************
    ;*******************************************************************************************
    (Setq SIZE (Getvar "EXTMAX")) ;get drawing xy extents
    (setq TH (*(getvar"TEXTSIZE")(getvar"DIMSCALE"))) ;fix text height
    (setq OS (+ (/ (* TH 2) 3) TH)) ;offset for x SPT

    (setq SPT (list (+ (car SIZE) OS) 0.5)) ;xy start point

    (Setq DATE (Strcat DATE )) ;Date stamp string
    (setq FIXED (/= 0 (cdr(assoc 40 (tblsearch "STYLE" (getvar"TEXTSTYLE"))))))
    (command".TEXT" "S" "Standard" SPT) ;cmd, style & start pt
    (if (not FIXED)(command TH)) ;text height if req'd
    (command "90" DATE) ;rot & text to print

    (setq SPT (list (+ (car SIZE) OS) 13.00)) ;xy start point

    (Setq DATE (Strcat Status)) ;Status stamp string
    (setq FIXED (/= 0 (cdr(assoc 40 (tblsearch "STYLE" (getvar"TEXTSTYLE"))))))
    (command".TEXT" "S" "Standard" SPT) ;cmd, style & start pt
    (if (not FIXED)(command TH)) ;text height if req'd
    (command "90" DATE) ;rot & text to print

    (setq SPT (list (+ (car SIZE) OS) 4.00)) ;xy start point

    (Setq DATE (Strcat SYS CONAME DNAME)) ;Dwgname stamp string
    (setq FIXED (/= 0 (cdr(assoc 40 (tblsearch "STYLE" (getvar"TEXTSTYLE"))))))
    (command".TEXT" "S" "Standard" SPT) ;cmd, style & start pt
    (if (not FIXED)(command TH)) ;text height if req'd
    (command "90" DATE)) ;rot & text to print
     
    matrixesinc, Jan 28, 2005
    #1
  2. matrixesinc

    T.Willey Guest

    (setq SS1 (ssget "C" P1 P2)) ;select objects
    Maybe change this to only select text like
    (setq SS1 (ssget "C" P1 P2 '((0 . "TEXT")))) ;select objects

    Tim
     
    T.Willey, Jan 28, 2005
    #2
  3. matrixesinc

    ECCAD Guest

    You may have local OSNAP settings that are bothering
    the selection set..to accomodate for that, on top of lisp,
    add:
    (setq OSM (getvar "OSMODE")); get current Osnap setting
    (setvar "OSMODE" 0); Set Osnap to NONe
    ......
    your code here......

    And, at the end, before exit.. add:
    (if OSM (setvar "OSMODE" OSM)); reset osnap setting

    Bob
     
    ECCAD, Jan 28, 2005
    #3
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.