Author Topic: Help: Modify Lisp Scale block only  (Read 1830 times)

0 Members and 1 Guest are viewing this topic.

miquan

  • Guest
Help: Modify Lisp Scale block only
« on: December 18, 2013, 06:12:38 PM »
Dear all,

I tried to modified this lisp.
This is used to sclae block only with a scale factor.
I tried to store scale factor (by STR value in my lisp) from last command, and use it in the next one. But I failed.
Could you possibly help me?

Thanks,
Miquan

Code - Auto/Visual Lisp: [Select]
  1. (defun c:sb (/        tapblock sodt     index    soblocksua
  2.              entdt    tt       diemchen tyle     DAIHT    DAIMOI
  3.              TEMP str
  4.             )
  5.   (init)
  6.   (princ "\nScale Block Only!")
  7.   (setq tapblock   (ssget '((0 . "INSERT")))
  8.         temp       (initget "R C")
  9.        
  10.         (SETQ temp (GETVAR "USERR3"))
  11. (IF (= temp 0)
  12.     (PROGN
  13.      (SETQ STR "1")
  14.      (SETVAR "USERR3" 1)
  15.     )  
  16.     (SETQ STR (RTOS temp))
  17. )
  18.        
  19.        
  20.         temp       (getreal "\nScale Factor <" STR ">:")
  21.        
  22.         (IF (= temp NIL)
  23.     (SETQ temp (GETVAR "USERR3"))
  24.     (SETVAR "USERR3" temp)
  25. )
  26.        
  27.        
  28.         tyle       (cond
  29.                      ((= temp "R")
  30.                       (setq
  31.                         daiht  (getdist "\nCurrent Length: ")
  32.                         daimoi (getdist "\nNew Length: ")
  33.                         tyle   (/ daimoi daiht)
  34.                       )
  35.                      )
  36.                      ((= temp "C")
  37.                       (setq tyle (getreal "\nNew Scale Factor: "))
  38.                      )
  39.                      (t temp)
  40.                    )
  41.         sodt       (sslength tapblock)
  42.         index      0
  43.         soblocksua 0
  44.   )
  45.   (repeat sodt
  46.     (setq entdt      (ssname tapblock index)
  47.           index      (1+ index)
  48.           tt         (entget entdt)
  49.           diemchen   (trans (cdr (assoc '10 tt)) 0 1)
  50.           soblocksua (1+ soblocksua)
  51.     )
  52.     (luuos)
  53.     (setvar "OSMODE" 0)
  54.     (command ".scale" entdt "" diemchen tyle)
  55.     (traos)
  56.   )
  57.   (princ (strcat "\nNumber of Modified Blocks: " (itoa soblocksua)))
  58.   (sssetfirst nil tapblock)
  59.   (done)
  60. )
  61.  

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help: Modify Lisp Scale block only
« Reply #1 on: December 18, 2013, 08:58:27 PM »
Untested but may get you closer to your goal.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:sb (/ tapblock sodt i ename tt diemchen daiht daimoi sb_scale)
  2.   ;(init)
  3.   (princ "\nScale Block Only!")
  4.   (setq tapblock (ssget '((0 . "INSERT"))))
  5.  
  6.   (if (zerop (setq sb_scale (getvar "USERR3")))
  7.     (progn
  8.       (setq sb_scale 1.)
  9.       (setvar "USERR3" 1.)
  10.     )
  11.   )
  12.  
  13.   (initget "R C")
  14.   (setq ans (getreal (strcat "\nScale Factor <" (rtos sb_scale 2 2) ">:")))
  15.   (cond
  16.     ((= ans "R")
  17.      (setq daiht    (getdist "\nCurrent Length: ")
  18.            daimoi   (getdist "\nNew Length: ")
  19.            sb_scale (/ daimoi daiht)
  20.      )
  21.     )
  22.     ((= ans "C")
  23.      (setq sb_scale (getreal "\nNew Scale Factor: "))
  24.  
  25.     )
  26.     ((= (type ans) 'real) (setq sb_scale ans))
  27.   )
  28.   (setvar "USERR3" sb_scale)
  29.   (setq i -1)
  30.   (while (setq ename (ssname tapblock (setq i (1+ i))))
  31.     (setq tt       (entget ename)
  32.           diemchen (trans (cdr (assoc '10 tt)) 0 1)
  33.     )
  34.     ;(luuos)
  35.     (setvar "OSMODE" 0)
  36.     (command ".scale" ename "" diemchen sb_scale)
  37.     ;(traos)
  38.   )
  39.   (princ (strcat "\nNumber of Modified Blocks: " (itoa (sslength tapblock))))
  40.   (sssetfirst nil tapblock)
  41.   ;(done)
  42. )
« Last Edit: December 19, 2013, 09:00:58 AM by CAB »
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.

miquan

  • Guest
Re: Help: Modify Lisp Scale block only
« Reply #2 on: December 19, 2013, 12:51:24 AM »
Dear CAB,

Thanks for your reply, I tried but it's failed.
The error is "too many arguments"

I re-post here with my lisp and some sub function.
Please look at and give me some advices.

Thanks,
Miquan

Code - Auto/Visual Lisp: [Select]
  1. (defun c:sb (/ tapblock tt diemchen daiht daimoi ans sb_scale i)
  2.   (init)
  3.  (princ "\nScale Block Only!")
  4.  (setq tapblock (ssget '((0 . "INSERT"))))
  5.  
  6.  (if (zerop (setq sb_scale (getvar "USERR3")))
  7.    (progn
  8.      (setq sb_scale 1)
  9.      (setvar "USERR3" 1)
  10.    )
  11.  )
  12.  
  13.  (initget "R C")
  14.  (setq ans (getreal "\nScale Factor <" (rtos sb_scale 2) ">:"))
  15.  (cond
  16.    ((null ans) (setq ans sb_scale))
  17.    ((= ans "R")
  18.     (setq daiht    (getdist "\nCurrent Length: ")
  19.           daimoi   (getdist "\nNew Length: ")
  20.           sb_scale (/ daimoi daiht)
  21.     )
  22.    )
  23.    ((= ans "C")
  24.     (setq sb_scale (getreal "\nNew Scale Factor: "))
  25.  
  26.    )
  27.  )
  28.  (setvar "USERR3" sb_scale)
  29.  (setq i -1)
  30.  (while (setq ename (ssname ss (setq i (1+ i))))
  31.    (setq tt       (entget ename)
  32.          diemchen (trans (cdr (assoc '10 tt)) 0 1)
  33.    )
  34.    (luuos)
  35.    (setvar "OSMODE" 0)
  36.    (command ".scale" ename "" diemchen sb_scale)
  37.    (traos)
  38.  )
  39.  (princ (strcat "\nNumber of Modified Blocks: " (itoa (sslength tapblock))))
  40.  (sssetfirst nil tapblock)
  41.  (done)
  42. )
  43.  
  44. (defun miquan_newerror (msg)
  45.   (if (and (/= msg "Function cancelled")
  46.            (/= msg "quit / exit abort")
  47.       )
  48.     (princ (strcat "\n" msg))
  49.   )
  50.   (done)
  51. )
  52. ;;----------
  53. (defun init ()
  54.   (setq
  55.     miquan_CMD     (getvar "CMDECHO")
  56.     miquan_OLDERROR *error*
  57.     *error*        miquan_newerror
  58.  
  59.   )
  60.   (setvar "CMDECHO" 0)
  61.   (command ".undo" "BE")
  62. )
  63. ;;----------
  64. (defun done ()
  65.   (command ".redraw")
  66.   (command ".undo" "E")
  67.   (if miquan_CMD
  68.     (setvar "CMDECHO" miquan_CMD)
  69.   )
  70.   (if miquan_OLDERROR
  71.     (setq *error* miquan_OLDERROR)
  72.   )
  73.   (princ)
  74. )
  75.  
  76. (defun luuos ()
  77.   (setq
  78.     miquan_OSMODE   (getvar "OSMODE")
  79.     miquan_AUTOSNAP (getvar "AUTOSNAP")
  80.   )
  81. )
  82. (defun traos ()
  83.   (if miquan_OSMODE
  84.     (setvar "OSMODE" miquan_OSMODE)
  85.   )
  86.   (if miquan_AUTOSNAP
  87.     (setvar "AUTOSNAP" miquan_AUTOSNAP)
  88.   )
  89. )
  90.  
  91.  

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help: Modify Lisp Scale block only
« Reply #3 on: December 19, 2013, 09:01:28 AM »
I updated the code in my post, try again.  8)
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.

miquan

  • Guest
Re: Help: Modify Lisp Scale block only
« Reply #4 on: December 20, 2013, 10:41:31 AM »
Dear CAB,

It works perfectly, Thanks so much.

Miquan

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help: Modify Lisp Scale block only
« Reply #5 on: December 20, 2013, 11:56:03 AM »
Glad to help.
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.