gschmidt Posted March 16, 2015 Posted March 16, 2015 Hi, I am creating a LISP code which creates BLOCKS with ENTMAKE, but i'm stuck. How do I get this code efficient?: If the Block not exists: Create it with Name X-1 And If the the Block exist (X-1): Create it with Name X-2, X-3, etc. I have a code which works, but I seems to me it can be more efficient ; Set Block Name (setq blk "Anchor-Wires-1") (setq count 1) (while (tblsearch "BLOCK" (strcat "Anchor-Wires-" (rtos count 2 0))) (setq blk (strcat "Anchor-Wires-" (rtos (1+ count) 2 0))) (setq count (1+ count)) ) (if (not (tblsearch "BLOCK" blk)) (progn ; Make block of Anchor Wires - Header (entmake (list '(0 . "BLOCK") (cons 10 (trans ins_pt 1 0)) (cons 2 blk) (cons 70 2) ) ) Rest of the Code Quote
Tharwat Posted March 16, 2015 Posted March 16, 2015 This should give you a unique name assigned to variable 'blk' . (setq nm "Anchor-Wires-" i 0) (while (tblsearch "BLOCK" (setq blk (strcat nm (itoa (setq i (1+ i))))))) Quote
gschmidt Posted March 16, 2015 Author Posted March 16, 2015 Thanx man the WHILE statement is more efficient indeed. But I wondered if WHILE can be incorporated with the IF statement? Quote
Tharwat Posted March 16, 2015 Posted March 16, 2015 Thanx man ... You are welcome . But I wondered if WHILE can be incorporated with the IF statement? It is not required to use if function in your case unless you have another goal than the one you brought earlier Quote
David Bethel Posted March 16, 2015 Posted March 16, 2015 I use some thing similar : (defun nw_block (fe / nw_set) (setq bc 1 bn "TEMP1") (while (tblsearch "BLOCK" bn) (setq bc (1+ bc) bn (strcat "TEMP" (itoa bc)))) (setq nw_set (ssadd)) (while fe (ssadd fe nw_set) (setq fe (entnext fe))) (command "_.UCS" "_World") (setvar "CECOLOR" "BYLAYER") (setvar "CELTYPE" "BYLAYER") (setvar "THICKNESS" 0) (command "_.BLOCK" bn '(0 0 0) nw_set "") (redraw)) Record the first entity ename created. This adds all entities created since then to create a block. HH -David Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.