Blocks to multiple point LISP

Blocks to multiple point LISP

mathew.grainger
Observer Observer
2,494 Views
6 Replies
Message 1 of 7

Blocks to multiple point LISP

mathew.grainger
Observer
Observer

Would somebody be kind enough to help me, i'm having trouble with a LISP file. 

 

I am trying to insert the same block to multiple points, all at once. 

 

i have got my hands on the following;

 

(defun C:PT2BLK ( / ss blk n) (setq ss (ssget "x" '((0 . "POINT"))) blk (getstring "\nName of Block: ") )::setq (if (and ss (tblsearch "block" blk)) (progn (setq n (1- (sslength ss))) (while (>= n 0) (setq pt (cdr (assoc 10 (entget (ssname ss n)))) n (1- n) );; setq (command "_.-insert" blk pt "" "" "") );;while );;progn );; if (princ) )

 

However, when i load this file into CAD it flags up an error message. 

 

; error: malformed list on input

 

Thanks you. 

0 Likes
Accepted solutions (1)
2,495 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Don't do this line structure... its really hard to read and control. 

 

If so, remove all the commentary.

In one case you have :: instead of ;; 

 

 

That's all, otherwise the code works. You should turn the OSNAPs off as well. Also you can add T for getstring that allows you to type a block name with spaces.

 

 

(defun C:PT2BLK ( / ss blk n)
  (setq ss (ssget "x" '((0 . "POINT")))
        blk (getstring "\nName of Block: ")
        );;setq
  (if (and ss
           (tblsearch "block" blk))
    (progn
      (setq n (1- (sslength ss)))
      (while (>= n 0)
        (setq pt (cdr (assoc 10 (entget (ssname ss n))))
              n (1- n) );; setq
        (command "_.-insert" blk "_none" pt "" "" "")
        );;while
      );;progn
    );; if
  (princ) )

 

I usually would do something like this:

 

(defun C:PT2BLK ( / ss blk n)

  (if (and (setq ss (ssget "x" '((0 . "POINT"))))
           (setq blk (getstring T "\nName of Block: "))
           (or (tblsearch "block" blk)
               (prompt (strcat "\nBlock '" blk "' is not defined in the drawing!"))
               ))
    (repeat (setq n (sslength ss))
      (command "_.-insert" blk
               "_s" 1
               "_r" 0
               "_none" (cdr (assoc 10 (entget (ssname ss (setq n (1- n)))))))))
  (princ)
)

 

 

0 Likes
Message 3 of 7

mathew.grainger
Observer
Observer

Wow, thank you for your help and quick response. You have saved me alot of time.

0 Likes
Message 4 of 7

sthompson1021
Advisor
Advisor

Would it be possible to use this lisp and insert a block to points that are on one layer and a different block to points on a different layer?

 

0 Likes
Message 5 of 7

cadffm
Consultant
Consultant

Hi,

 

remove the three chars "x" in ssget row,

Now, you can select the points you want.

 

 

Sebastian

Message 6 of 7

sthompson1021
Advisor
Advisor

OK, I have to plead my ignorance. What are you referring to when you say "three chars"

0 Likes
Message 7 of 7

sthompson1021
Advisor
Advisor

Never mind, I figured it out.  Thanks for the help. It worked perfect.

0 Likes