Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Quick block

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Anonymous
2194 Views, 9 Replies

Quick block

I have migrated o a new office and I am looking for a Lisp routine that used to make Blocks in-place instantly.  he name of the block doesn't matter, but it can't be an anonymous block (I already have that routine!)

 

Does anyone have this lisp routine they could share?  Basically, you run the Lisp command, select whatever you want and it instantly transforms your selection into a randomly named block.  I think I got this routine off of a Hot Tip Harry website a LONG time ago.

 

HELP!

Tags (2)
9 REPLIES 9
Message 2 of 10
_Tharwat
in reply to: Anonymous

Things like this .... ?

 

(defun c:Test (/ selectionset insertionpoint number Blockname)
  ;;; Tharwat 11. May. 2012 ;;
  (if (and (setq selectionset (ssget "_:L"))
           (setq insertionpoint (getpoint "\n Specify insertion point :"))
      )
    (progn
      (setq number    1
            Blockname (strcat "MyBlock" (itoa number))
      )
      (while (tblsearch "BLOCK" Blockname)
        (setq Blockname
               (strcat "MyBlock" (itoa (setq number (1+ number))))
        )
      )
      (command "_.-Block" Blockname insertionpoint selectionset ""
              )
    )
    (princ)
  )
  (princ)
)

 

Message 3 of 10
Anonymous
in reply to: _Tharwat

Almost!  I ran this lisp and it deletes the original content, but I just want to convert a selection to a named block, in place, without having to reinsert it.

 

THANK YOU FOR YOUR HELP!

Message 4 of 10
_Tharwat
in reply to: Anonymous

With the adds of command call insert , we will re-insert the same block name in its chosen insertion point . Smiley Very Happy

 

Try and tell me back ..

 

(defun c:Test (/ selectionset insertionpoint number Blockname)
  ;;; Tharwat 11. May. 2012 ;;
  (if (and (setq selectionset (ssget "_:L"))
           (setq insertionpoint (getpoint "\n Specify insertion point :"))
      )
    (progn
      (setq number    1
            Blockname (strcat "MyBlock" (itoa number))
      )
      (while (tblsearch "BLOCK" Blockname)
        (setq Blockname
               (strcat "MyBlock" (itoa (setq number (1+ number))))
        )
      )
      (command "_.-Block" Blockname insertionpoint selectionset "")
      (command "_.-insert" Blockname insertionpoint "" "" "")
    )
    (princ)
  )
  (princ)
)

 

Message 5 of 10
Anonymous
in reply to: _Tharwat

Perfect!!!  Way to go!

Message 6 of 10
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

.... Basically, you run the Lisp command, select whatever you want and it instantly transforms your selection into a randomly named block.  I think I got this routine off of a Hot Tip Harry website a LONG time ago.

....


This is from Hot Tip Harry's website [Cadalyst] -- might it be the one?  It doesn't name it randomly, though.  And I didn't download it and try it.  But it came up when I searched for "quick block":

 

http://cadtips.cadalyst.com/standard-blocks/quick-blocks

Kent Cooper, AIA
Message 7 of 10
_Tharwat
in reply to: Anonymous


@Anonymous wrote:

Perfect!!!  Way to go!


Enjoy it . Smiley Wink

 

Tharwat

Message 8 of 10
Anonymous
in reply to: Kent1Cooper

Thanks, this really helps!

Message 9 of 10
desmund08
in reply to: _Tharwat

 


@_Tharwat wrote:

With the adds of command call insert , we will re-insert the same block name in its chosen insertion point . Smiley Very Happy

 

Try and tell me back ..

 

(defun c:Test (/ selectionset insertionpoint number Blockname)
  ;;; Tharwat 11. May. 2012 ;;
  (if (and (setq selectionset (ssget "_:L"))
           (setq insertionpoint (getpoint "\n Specify insertion point :"))
      )
    (progn
      (setq number    1
            Blockname (strcat "MyBlock" (itoa number))
      )
      (while (tblsearch "BLOCK" Blockname)
        (setq Blockname
               (strcat "MyBlock" (itoa (setq number (1+ number))))
        )
      )
      (command "_.-Block" Blockname insertionpoint selectionset "")
      (command "_.-insert" Blockname insertionpoint "" "" "")
    )
    (princ)
  )
  (princ)
)

 


 

Hi @_Tharwat ,

 

Thanks for this lisp. It's very useful for me.

 

What if I want to specify the block name instead of automatic, what should I add on your code?

 

Thank you.

Message 10 of 10
_Tharwat
in reply to: desmund08

Hi,

Just this a shot.

(defun c:Test (/ selectionset insertionpoint Blockname)
  ;;; Tharwat 13. Jul. 2020 ;;
  (if (and (setq selectionset (ssget "_:L"))
           (setq insertionpoint (getpoint "\nSpecify insertion point :"))
           (setq Blockname (getstring t "\nSpecify Block name :"))
           (setq Blockname (vl-string-left-trim " " Blockname))
           (if (or (= Blockname "")
                   (not (snvalid Blockname))
                   (tblsearch "BLOCK" Blockname)
                   )
               (alert "Invalid block name, or its already existed!")
             Blockname)
           )
    (progn
      (command "_.-Block"  Blockname "_none" insertionpoint selectionset "")
      (command "_.-insert" Blockname "_none" insertionpoint "" "" "")
    )
    (princ)
  )
  (princ)
) (vl-load-com)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost