Author Topic: Lisp error  (Read 3162 times)

0 Members and 1 Guest are viewing this topic.

One Shot

  • Guest
Lisp error
« on: August 30, 2005, 05:01:50 PM »
I am trying to find the error in this lisp.  It happens at the blockit function.  Can someone please point it out to me and tell me what I need to do to fix it.

Thank you

(defun C:WINTRIM ( / *error* stq wq pick1 pick2 pick3 pick4 tpnt1 tpnt2 bpnt)
  (setvar "cmdecho" 0)
  (setq o_osmode (getvar "osmode")
   o_clayer (getvar "clayer")
   *error*  sillerr
        blss     nil
  )
  (if (not stype) (setq stype "TS"))
  (if (not width) (setq width 3))
  (prompt "\nType: TS-Trim Sill/TSS-Trim Sill Surround/BS-Brick Surround/BR-Brick Rowlock")
  (initget "TS TSS BS BR")
  (if (/= (setq stq (getkword (strcat "\nSpecify type [TS/TSS/BS/BR]<" stype ">: "))) nil)
    (setq stype stq)
  )
  (initget "3 4 6 8")
  (if (/= (setq wq (getkword (strcat "\nSpecify width [3/4/6/8]<" (itoa width) ">: "))) nil)
    (setq width (atoi wq))
  )
  (cond
    ((= stype "TS")
      (initget 1)
      (setq pick1 (getpoint "\nSelect left corner: "))
      (initget 1)
      (setq pick2 (getpoint pick1 "\nSelect right corner: "))
      (setq tpnt1 (polar pick1 (angle pick2 pick1) 0.75)
        tpnt2 (polar pick2 (angle pick1 pick2) 0.75)
       bpnt  (polar pick1 (angle pick1 pick2) (/ (distance pick1 pick2) 2))
      )
      (drawit stype tpnt1 tpnt2 width nil)
      (blockit stype tpnt1 tpnt2 bpnt width nil blss)
    )
    ((= stype "TSS")
      (initget 1)
      (setq pick1 (getpoint "\nSelect top left corner: "))
      (initget 1)
      (setq pick2 (getpoint pick1 "\nSelect bottom left corner: "))
      (initget 1)
      (setq pick3 (getpoint pick2 "\nSelect bottom right corner: "))
      (initget 1)
      (setq pick4 (getpoint pick3 "\nSelect top right corner: "))
      (setq tpnt1 (polar pick2 (angle pick3 pick2) (+ width 0.75))
        tpnt2 (polar pick3 (angle pick2 pick3) (+ width 0.75))
       bpnt  (polar pick1 (angle pick1 pick4) (/ (distance pick1 pick4) 2))
      )
      (drawit stype pick1 pick2 width nil)
      (drawit stype tpnt1 tpnt2 width nil)
      (drawit stype pick3 pick4 width nil)
      (blockit stype tpnt1 tpnt2 bpnt width (+ (distance pick1 pick2) width) blss)
    )
    ((= stype "BR")
      (initget 1)
      (setq pick1 (getpoint "\nSelect left corner: "))
      (initget 1)
      (setq pick2 (getpoint pick1 "\nSelect right corner: "))
      (setq bpnt  (polar pick1 (angle pick1 pick2) (/ (distance pick1 pick2) 2)))
      (drawit stype pick1 pick2 width 2.750)
      (blockit stype pick1 pick2 bpnt width nil blss)
    )
    ((= stype "BS")
      (initget 1)
      (setq pick1 (getpoint "\nSelect top left corner: "))
      (initget 1)
      (setq pick2 (getpoint pick1 "\nSelect bottom left corner: "))
      (initget 1)
      (setq pick3 (getpoint pick2 "\nSelect bottom right corner: "))
      (initget 1)
      (setq pick4 (getpoint pick3 "\nSelect top right corner: "))
      (setq tpnt1 (polar pick2 (angle pick3 pick2) width)
        tpnt2 (polar pick3 (angle pick2 pick3) width)
       bpnt  (polar pick1 (angle pick1 pick4) (/ (distance pick1 pick4) 2))
      )
      (drawit stype pick1 pick2 width 3.0)
      (drawit stype tpnt1 tpnt2 width 2.750)
      (drawit stype pick3 pick4 width 3.0)
      (blockit stype tpnt1 tpnt2 bpnt width (+ (distance pick1 pick2) width) blss)
    )
  )
  (setvar "clayer" o_clayer)
  (setvar "osmode" o_osmode)
  (setvar "cmdecho" 1)
  (princ)
)

;Draw Routine
(defun drawit (typ pt1 pt2 wdth lnspac / reclgth ang pt3 pt4 realnum remain
                                    intnum offset lnpt1 lnpt2
         )
  (setq reclgth (distance pt1 pt2)
   ang     (angle pt1 pt2)
        pt3     (polar pt1 (- ang (/ pi 2)) wdth)
   pt4     (polar pt2 (- ang (/ pi 2)) wdth)
  )
  (setvar "clayer" "0")
  (setvar "plinewid" 0)
  (setvar "osmode" 0)
  (command "-color" 6 "-linetype" "Set" "ByBlock" "")
  (command "_.pline" pt1 pt3 pt4 pt2 "C")
  (if (not blss) (setq blss (ssadd (entlast))) (ssadd (entlast) blss))
  (if (/= lnspac nil)
    (progn
      (setq realnum (rtos (/ reclgth lnspac) 2 8))
      (setq remain (distof (substr realnum (+ (vl-string-search "." realnum) 1)) 2))
      (if (>= remain 0.53125)
        (setq intnum (+ (atoi realnum) 1))
        (setq intnum (atoi realnum))
      )
      (setq offset (/ (- reclgth (* intnum lnspac)) 2))
      (setq offset (+ lnspac offset))
      (command "-color" 1)
      (repeat (- intnum 1)
        (setq lnpt1 (polar pt1 ang offset))
        (setq lnpt2 (polar pt3 ang offset))
        (command "_.line" lnpt1 lnpt2 "")
        (ssadd (entlast) blss)
        (setq offset (+ lnspac offset))
      )      
      (command "-color" "ByLayer" "-linetype" "Set" "ByLayer" "")
    )
  )
)

;Block Routine
(defun blockit (typ pt1 pt2 basept wdth hgt ss / )
  (setvar "filedia" 1)
  (if (/= hgt nil)
    (setq blk_name (strcat (itoa wdth) typ "-" (rtos (distance pt1 pt2) 2 1) " X " (rtos hgt 2 1) ".dwg"))
    (setq blk_name (strcat (itoa wdth) typ "-" (rtos (distance pt1 pt2) 2 1) ".dwg"))
  )  
  C:\Documents and Settings\bcrouse\Desktop\Library R & D Blocks\Window Trim" blk_name))
  (command "_.move" ss "" basept "0,0,0")
  (if (/= (findfile path) nil)
    (command "_.-wblock" path "Y" "" "0,0,0" ss "")
    (command "_.-wblock" path "" "0,0,0" ss "")
  )
  (command "_.-insert" path "S" 1 basept 0)
  (setvar "filedia" 1)
)

;Error Routine
(defun sillerr (msg)
  (prompt (strcat "\nError: " msg))
  (command "-color" "ByLayer" "-linetype" "Set" "ByLayer" "")
  (setvar "clayer" o_clayer)
  (setvar "osmode" o_osmode)
  (setvar "cmdecho" 1)
  (princ)
)[/code]

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Lisp error
« Reply #1 on: August 30, 2005, 05:07:07 PM »
If this line (defun blockit ... ) counts as line number 1, I'd say there's something screwy with line number 7 (starts with C:\Documents ...), for starters.

i.e. not quoted, single backslashes ...
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

One Shot

  • Guest
Lisp error
« Reply #2 on: August 30, 2005, 05:38:02 PM »
Okay I got it to work.  Why would I get this for the name of block (Documents and SettingsbcrouseDesktopLibrary R & D BlocksWindow Trim4BS-41.6 X 80.8.dwg)

I just to want to get the block name:

Example: 4BS-41.6 X 80.8.dwg



Code: [Select]
;Block Routine
(defun blockit (typ pt1 pt2 basept wdth hgt ss / )
  (setvar "filedia" 1)
  (if (/= hgt nil)
    (setq blk_name (strcat (itoa wdth) typ "-" (rtos (distance pt1 pt2) 2 1) " X " (rtos hgt 2 1) ".dwg"))
    (setq blk_name (strcat (itoa wdth) typ "-" (rtos (distance pt1 pt2) 2 1) ".dwg"))
  )  
  (setq path (strcat "C:\Documents and Settings\bcrouse\Desktop\Library R & D Blocks\Window Trim" blk_name))
  (command "_.move" ss "" basept "0,0,0")
  (if (/= (findfile path) nil)
    (command "_.-wblock" path "Y" "" "0,0,0" ss "")
    (command "_.-wblock" path "" "0,0,0" ss "")
  )
  (command "_.-insert" path "S" 1 basept 0)
  (setvar "filedia" 1)
)

;Error Routine
(defun sillerr (msg)
  (prompt (strcat "\nError: " msg))
  (command "-color" "ByLayer" "-linetype" "Set" "ByLayer" "")
  (setvar "clayer" o_clayer)
  (setvar "osmode" o_osmode)
  (setvar "cmdecho" 1)
  (princ)
)


I would like to have it to work like this example of a lisp:

Example:
Code: [Select]

(if (tblsearch "BLOCK" BLOCK-NAME)
    (setq ANSWER (KWORD_PROMPT (list "Yes" "No") "Redefine Block" 1))
  )
  (setvar "osmode" 0)
  (if (or (not (tblsearch "BLOCK" BLOCK-NAME))
 (= "Yes" ANSWER)
      )
    (progn
      (cond
((= ARCH-TYPE "4CK")
(setq COURSE 10.75
      BOTTOM 4.0
      TOP 8.5
      HEIGHT 13.75
      PT-LIST (COURSE-CALC PT-LIST COURSE)
      KEY-LIST (KEY-CALC PT-LIST BOTTOM TOP HEIGHT)
)
)
((= ARCH-TYPE "4C")
(setq COURSE 10.75
      PT-LIST (COURSE-CALC PT-LIST COURSE)
      KEY-LIST NIL
)
)
((= ARCH-TYPE "3CK")
(setq COURSE 8.0
      BOTTOM 4.0
      TOP 8.5
      HEIGHT 10.625
      PT-LIST (COURSE-CALC PT-LIST COURSE)
      KEY-LIST (KEY-CALC PT-LIST BOTTOM TOP HEIGHT)
)
)
((= ARCH-TYPE "3C")
(setq COURSE 8.0
      PT-LIST (COURSE-CALC PT-LIST COURSE)
      KEY-LIST NIL
)
)
      )
      (setq SDLIST (SOLDIER-CALC PT-LIST KEY-LIST BRICK))
      (setq SSLIST (DRAWJACK PT-LIST KEY-LIST ARCH-TYPE))
      (if (= ANSWER "Yes")
(command "-block" BLOCK-NAME ANSWER BLOCK-INS SSLIST SDLIST "")
(command "-block" BLOCK-NAME BLOCK-INS SSLIST SDLIST "")
      )
    )
  )
  (if (tblsearch "BLOCK" BLOCK-NAME)
    (command "-insert" BLOCK-NAME BLOCK-INS 1 1 0)
  )
  (setq SUPPORT-FOLDER (getvar "dwgprefix")
;; currently set to the current drawings folder
BLOCK-FILENAME (strcat SUPPORT-FOLDER BLOCK-NAME ".dwg")
  )
  (if (not (findfile BLOCK-FILENAME))
    (command "-wblock" BLOCK-FILENAME BLOCK-NAME)
    (progn
      (prompt "\nFile already exists.")
      (if
(= (setq
    ANSWER (KWORD_PROMPT (list "Yes" "No") "Redefine file?" 1)
  )
  "Yes"
)
(command "-wblock" BLOCK-FILENAME ANSWER BLOCK-NAME)
      )
    )
  )
  (RETVARS)


How would I do that?

Thank you,

Brad

Jim Yadon

  • Guest
Lisp error
« Reply #3 on: August 30, 2005, 06:59:11 PM »
Quote from: One Shot
Okay I got it to work.  Why would I get this for the name of block (Documents and SettingsbcrouseDesktopLibrary R & D BlocksWindow Trim4BS-41.6 X 80.8.dwg)

I just to want to get the block name:

Example: 4BS-41.6 X 80.8.dwg



Code: [Select]
;Block Routine
(defun blockit (typ pt1 pt2 basept wdth hgt ss / )
  (setvar "filedia" 1)
  (if (/= hgt nil)
    (setq blk_name (strcat (itoa wdth) typ "-" (rtos (distance pt1 pt2) 2 1) " X " (rtos hgt 2 1) ".dwg"))
    (setq blk_name (strcat (itoa wdth) typ "-" (rtos (distance pt1 pt2) 2 1) ".dwg"))
  )  
  (setq path (strcat "C:\Documents and Settings\bcrouse\Desktop\Library R & D Blocks\Window Trim" blk_name))
  (command "_.move" ss "" basept "0,0,0")
  (if (/= (findfile path) nil)
    (command "_.-wblock" path "Y" "" "0,0,0" ss "")
    (command "_.-wblock" path "" "0,0,0" ss "")
  )
  (command "_.-insert" path "S" 1 basept 0)
  (setvar "filedia" 1)
)

;Error Routine
(defun sillerr (msg)
  (prompt (strcat "\nError: " msg))
  (command "-color" "ByLayer" "-linetype" "Set" "ByLayer" "")
  (setvar "clayer" o_clayer)
  (setvar "osmode" o_osmode)
  (setvar "cmdecho" 1)
  (princ)
)





If you cut the strcat function with the file path it'll give you what you're after I believe. I don't have time to test it for you at the moment, my dinner is nearly ready.

Bob Wahr

  • Guest
Lisp error
« Reply #4 on: August 30, 2005, 07:14:13 PM »
shouldn't
Code: [Select]
 (setq   path (strcat "C:\Documents and Settings\bcrouse\Desktop\Library R & D Blocks\Window Trim" blk_name))
be
Code: [Select]
 (setq   path (strcat "C:\\Documents and Settings\\bcrouse\\Desktop\\Library R & D Blocks\\Window Trim\\" blk_name))
or
Code: [Select]
 (setq   path (strcat "C:/Documents and Settings/bcrouse/Desktop/Library R & D Blocks/Window Trim/" blk_name)) Mind you, my lisp is horrible but it seems like I remember something like that.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp error
« Reply #5 on: August 30, 2005, 08:37:57 PM »
Some other items to look at.
Another way to build the block name.
 
Here (if (findfile path) returns a non nil and has the same result as (if (/= (findfile path) nil)

You may want to consider a global variable *rootpath*
(setq *rootpath* "C:/Documents and Settings/bcrouse/Desktop/Library R & D Blocks/")

then
  (setq path (strcat *rootpath* "Window Trim/" blk_name))

Just some things to consider.

Yes Bob is correct.

Code: [Select]
;Block Routine
(defun blockit (typ pt1 pt2 basept wdth hgt ss / )
  (setvar "filedia" 1)
  (setq blk_name
         (strcat (itoa wdth) typ "-" (rtos (distance pt1 pt2) 2 1)
             (if (/= hgt nil)
              (strcat " X " (rtos hgt 2 1) ".dwg")
               ".dwg"
             )
         )
  )
  (setq path (strcat "C:/Documents and Settings/bcrouse/Desktop/Library R & D Blocks/Window Trim/" blk_name))
  (command "_.move" ss "" basept "0,0,0")
  (if (findfile path)
    (command "_.-wblock" path "Y" "" "0,0,0" ss "")
    (command "_.-wblock" path "" "0,0,0" ss "")
  )
  (command "_.-insert" path "S" 1 basept 0)
  (setvar "filedia" 1)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

One Shot

  • Guest
Lisp error
« Reply #6 on: August 31, 2005, 08:32:46 AM »
Quote from: Bob Wahr
shouldn't
Code: [Select]
 (setq   path (strcat "C:\Documents and Settings\bcrouse\Desktop\Library R & D Blocks\Window Trim" blk_name))
be
Code: [Select]
 (setq   path (strcat "C:\\Documents and Settings\\bcrouse\\Desktop\\Library R & D Blocks\\Window Trim\\" blk_name))
or
Code: [Select]
 (setq   path (strcat "C:/Documents and Settings/bcrouse/Desktop/Library R & D Blocks/Window Trim/" blk_name)) Mind you, my lisp is horrible but it seems like I remember something like that.


Thank you for your help!

One Shot

  • Guest
Lisp error
« Reply #7 on: August 31, 2005, 11:55:34 AM »
Thank you CAB.  How have you been?  How has the fishing been going for you?

Brad

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp error
« Reply #8 on: August 31, 2005, 12:01:12 PM »
Been good, was in the Keys for two weeks 4-18 but the legal size lobster were scarce this year.
Saw you e-mail but was too busy getting my feet back on the ground after vacation.
Forgot about it until I saw your post. Hope you got it worked out.

See Ya..
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

One Shot

  • Guest
Lisp error
« Reply #9 on: August 31, 2005, 12:03:31 PM »
Quote from: CAB
Been good, was in the Keys for two weeks 4-18 but the legal size lobster were scarce this year.
Saw you e-mail but was too busy getting my feet back on the ground after vacation.
Forgot about it until I saw your post. Hope you got it worked out.

See Ya..


I have tried it out and it still is not working right.  By the way, I will be down in the Sunshine State for AU this year.  Hope to see you there if you go?

Brad