Jump to content

Recommended Posts

Posted

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  

Posted

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)))))))

Posted

Thanx man the WHILE statement is more efficient indeed.

But I wondered if WHILE can be incorporated with the IF statement?

Posted
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 ;)

Posted

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...