Author Topic: Quick Block Lisp  (Read 2725 times)

0 Members and 1 Guest are viewing this topic.

asami486

  • Guest
Quick Block Lisp
« on: February 03, 2017, 07:00:32 PM »
I got Quick Block Lisp.(always Thank you)
This lisp is very good, but i'd like to change a little.
When I use this lisp, I have to set a Specify insertion point.
It is a little uncomfortable for me to set the point when I don't need a specify insertion point.
Could it set a insertion point automatically at the CENTER of selected objects if I just push the space bar?
(ex) (getpoint "\n Specify insertion point : (Space:Center)"))
Please help me!:D

Code - Auto/Visual Lisp: [Select]
  1.  ;;; Quick Block
  2.   ;;; Tharwat 11. May. 2012 ;;
  3.   ;;; http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/quick-block/td-p/3454228
  4.  
  5. (defun c:B (/ selectionset insertionpoint number Blockname)
  6.   (if (and (setq selectionset (ssget "_:L"))
  7.            (setq insertionpoint (getpoint "\n Specify insertion point :"))
  8.       )
  9.     (progn
  10.       (setq number    1
  11.             Blockname (strcat "MyBlock" (itoa number))
  12.       )
  13.       (while (tblsearch "BLOCK" Blockname)
  14.         (setq Blockname
  15.                (strcat "MyBlock" (itoa (setq number (1+ number))))
  16.         )
  17.       )
  18.       (command "_.-Block" Blockname insertionpoint selectionset "")
  19.       (command "_.-insert" Blockname insertionpoint "" "" "")
  20.     )
  21.     (princ)
  22.   )
  23.   (princ)
  24. )
  25.  

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: Quick Block Lisp
« Reply #1 on: February 04, 2017, 07:10:21 AM »
Code - Auto/Visual Lisp: [Select]
  1.  ;;; Quick Block
  2.   ;;; Tharwat 11. May. 2012 ;;
  3.   ;;; http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/quick-block/td-p/3454228
  4.  
  5. (defun c:B (/ selectionset insertionpoint number Blockname mn mx pnts)
  6.   (defun LM:ssboundingbox ( sel / idx llp ls1 ls2 obj urp ) ; Lee mac
  7.     (repeat (setq idx (sslength sel))
  8.         (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
  9.         (if (and (vlax-method-applicable-p obj 'getboundingbox)
  10.                  (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'llp 'urp)))))
  11.             (setq ls1 (cons (vlax-safearray->list llp) ls1)
  12.                   ls2 (cons (vlax-safearray->list urp) ls2))))
  13.     (if (and ls1 ls2)
  14.         (mapcar '(lambda ( a b ) (apply 'mapcar (cons a b))) '(min max) (list ls1 ls2))))
  15.  
  16.     (if (and (setq selectionset (ssget ))
  17.            ;(setq insertionpoint (getpoint "\n Specify insertion point :"))
  18.       )
  19.     (progn
  20.       (setq number    1
  21.             Blockname (strcat "MyBlock" (itoa number))
  22.       )
  23.       (while (tblsearch "BLOCK" Blockname)
  24.         (setq Blockname
  25.                (strcat "MyBlock" (itoa (setq number (1+ number))))
  26.         )
  27.       )
  28.       (setq pnts (LM:ssboundingbox selectionset))
  29.       (setq mn (nth 0 pnts))
  30.       (setq mx (nth 1 pnts))
  31.       (setq insertionpoint (list (/ (+ (nth 0 mn) (nth 0 mx))2) (/ (+ (nth 1 mn) (nth 1 mx))2)))
  32.       (command "_.-Block" Blockname insertionpoint selectionset "")
  33.       (command "_.-insert" Blockname insertionpoint "" "" "")
  34.     )
  35.     (princ)
  36.   )
  37.   (princ)
  38. )

asami486

  • Guest
Re: Quick Block Lisp
« Reply #2 on: February 04, 2017, 10:42:00 PM »
Thank you So much.
But can I ask one more thing if you don't mind?
It would be good that the original version adds to your version.
In other words, When I command this lisp, I'd like to have 2 options.
First, I'd like to set a specific point by the mouse click like the original version.
Second, if I don't need a specific point and just push the spacebar, It could set a center point automatically like your version.

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: Quick Block Lisp
« Reply #3 on: February 05, 2017, 12:36:59 AM »
Give this a try
Note: Command: CMB or CreateMyBlock
Code - Auto/Visual Lisp: [Select]
  1.  ;;; Quick Block
  2.   ;;; Tharwat 11. May. 2012 ;;
  3.   ;;; http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/quick-block/td-p/3454228
  4. (defun c:CMB () (c:CreateMyBlock))
  5. (defun c:CreateMyBlock (/ selectionset insertionpoint number Blockname mn mx pnts)
  6.   (defun LM:ssboundingbox ( sel / idx llp ls1 ls2 obj urp ) ; Lee mac
  7.     (repeat (setq idx (sslength sel))
  8.         (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
  9.         (if (and (vlax-method-applicable-p obj 'getboundingbox)
  10.                  (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'llp 'urp)))))
  11.             (setq ls1 (cons (vlax-safearray->list llp) ls1)
  12.                   ls2 (cons (vlax-safearray->list urp) ls2))))
  13.    
  14.     (if (and ls1 ls2)
  15.         (mapcar '(lambda ( a b ) (apply 'mapcar (cons a b))) '(min max) (list ls1 ls2))))
  16.  
  17.     (if (setq selectionset (ssget ))
  18.     (progn
  19.       (setq number    1
  20.             Blockname (strcat "MyBlock" (itoa number))
  21.       )
  22.       (while (tblsearch "BLOCK" Blockname)
  23.         (setq Blockname
  24.                (strcat "MyBlock" (itoa (setq number (1+ number))))
  25.         )
  26.       )
  27.       (setq insertionpoint (getpoint "\n Specify insertion point <Press any key for Center>: "))
  28.      
  29.       (cond ( (eq (type P) "LST")
  30.        (setq insertionpoint insertionpoint)
  31.        )
  32.       ( (eq (type P) nil)
  33.        (progn
  34.          (setq pnts (LM:ssboundingbox selectionset))
  35.          (setq mn (nth 0 pnts))
  36.          (setq mx (nth 1 pnts))
  37.          (setq insertionpoint (list (/ (+ (nth 0 mn) (nth 0 mx))2) (/ (+ (nth 1 mn) (nth 1 mx))2)))
  38.          )
  39.        )
  40.       ) ; cond
  41.      
  42.       (command "_.-Block" Blockname insertionpoint selectionset "")
  43.       (command "_.-insert" Blockname insertionpoint "" "" "")
  44.     )
  45.     (princ)
  46.   )
  47.   (princ)
  48. )

asami486

  • Guest
Re: Quick Block Lisp
« Reply #4 on: February 05, 2017, 06:54:44 AM »
Thank you for your help.
But I'm afraid that it has a little problem.
When I set a specific point by the mouse click, the lisp still sets a center point.

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: Quick Block Lisp
« Reply #5 on: February 05, 2017, 07:18:29 AM »
Sorry, There was mistake
Code - Auto/Visual Lisp: [Select]
  1. (defun c:CreateMyBlock (/ selectionset insertionpoint number Blockname mn mx pnts)
  2.   (defun LM:ssboundingbox ( sel / idx llp ls1 ls2 obj urp ) ; Lee mac
  3.     (repeat (setq idx (sslength sel))
  4.         (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
  5.         (if (and (vlax-method-applicable-p obj 'getboundingbox)
  6.                  (not (vl-catch-all-error-p
  7.                         (vl-catch-all-apply 'vla-getboundingbox (list obj 'llp 'urp)))))
  8.             (setq ls1 (cons (vlax-safearray->list llp) ls1)
  9.                   ls2 (cons (vlax-safearray->list urp) ls2))))
  10.  
  11.     (if (and ls1 ls2)
  12.         (mapcar '(lambda ( a b ) (apply 'mapcar (cons a b))) '(min max) (list ls1 ls2))))
  13.  
  14.     (if (setq selectionset (ssget ))
  15.     (progn
  16.       (setq number    1
  17.             Blockname (strcat "MyBlock" (itoa number))
  18.       )
  19.       (while (tblsearch "BLOCK" Blockname)
  20.         (setq Blockname
  21.                (strcat "MyBlock" (itoa (setq number (1+ number))))
  22.         )
  23.       )
  24.       (setq insertionpoint (getpoint "\n Specify insertion point <Press any key for Center>: "))
  25.  
  26.       (cond ( (eq (type insertionpoint) "LST")
  27.        (setq insertionpoint insertionpoint)
  28.        )
  29.       ( (eq (type insertionpoint) nil)
  30.        (progn
  31.          (setq pnts (LM:ssboundingbox selectionset))
  32.          (setq mn (nth 0 pnts))
  33.          (setq mx (nth 1 pnts))
  34.          (setq insertionpoint (list (/ (+ (nth 0 mn) (nth 0 mx))2) (/ (+ (nth 1 mn) (nth 1 mx))2)))
  35.          )
  36.        )
  37.       ) ; cond
  38.  
  39.       (command "_.-Block" Blockname insertionpoint selectionset "")
  40.       (command "_.-insert" Blockname insertionpoint "" "" "")
  41.     )
  42.     (princ)
  43.   )
  44.   (princ)
  45. )

asami486

  • Guest
Re: Quick Block Lisp
« Reply #6 on: February 05, 2017, 08:00:18 AM »
 :-D
That's it!
That is what I wanted!
Really, Really, Really Thanks Mr.Hasan!!

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: Quick Block Lisp
« Reply #7 on: February 05, 2017, 05:22:25 PM »
:-D
That's it!
That is what I wanted!
Really, Really, Really Thanks Mr.Hasan!!
It is my pleasure to help as possible as i can.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Quick Block Lisp
« Reply #8 on: February 05, 2017, 05:54:18 PM »
FWIW, I'd replace this:
Code - Auto/Visual Lisp: [Select]
  1. (setq insertionpoint (getpoint "\n Specify insertion point <Press any key for Center>: "))
  2.  
  3. (cond ( (eq (type insertionpoint) "LST")
  4.   (setq insertionpoint insertionpoint)
  5. )
  6. ( (eq (type insertionpoint) nil)
  7.   (progn
  8.     (setq pnts (LM:ssboundingbox selectionset))
  9.     (setq mn (nth 0 pnts))
  10.     (setq mx (nth 1 pnts))
  11.     (setq insertionpoint (list (/ (+ (nth 0 mn) (nth 0 mx))2) (/ (+ (nth 1 mn) (nth 1 mx))2)))
  12.   )
  13. )
  14. ) ; cond

with:
Code - Auto/Visual Lisp: [Select]
  1. (or ; why? - select XLINE/RAY/POINT entity
  2.   (setq insertionpoint (getpoint "\n Specify insertion point <Press any key for Center>: "))
  3.   (and
  4.     (setq insertionpoint (LM:ssboundingbox selectionset))
  5.     (setq insertionpoint (apply 'mapcar (cons '(lambda (a b) (/ (+ a b) 2.))  insertionpoint))) ; thanks for this, Lee Mac
  6.   )
  7.   (setq insertionpoint (getpoint "\nYou must specify an insertion point <exit>: "))
  8. ); or

Code - Auto/Visual Lisp: [Select]
  1. (setq selectionset (ssget ))

with:
Code - Auto/Visual Lisp: [Select]
  1. (setq selectionset (ssget "_:L-I"))
So either use implied selection either prompt for one (in both cases the locked layers are excluded).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

asami486

  • Guest
Re: Quick Block Lisp
« Reply #9 on: February 06, 2017, 01:44:36 AM »
 :lol:Thank Mr.Grrr always!