Jump to content
jeremyearle5

Need help making a routine to insert a certain set of blocks all at once at 0,0?

Recommended Posts

jeremyearle5

I use autocad 2000 at my job to create drawings for CAM. The machining paths are numbered between 521-850 (this is the block name) each time with numbers being used throughout this range, not nessecarily in order. What I want to do is get only these numbered blocks to insert all at once with one command at 0,0. Question one: Can I get a list of just the block names with autolisp? Question 2: Can I filter the block names with some sort of cond? or will I have to go about that another way?

Share this post


Link to post
Share on other sites
Tharwat

Check this out ... Would insert all your block at the coordinates 0,0,0 and would print the name of your inserted blocks to the command line ..

 

(defun c:TesT (/ Block Blockname lst)
 (while
   (setq Block (tblnext "BLOCK" (null Block)))
    (entmake
      (list '(0 . "INSERT")
            (cons 10 '(0. 0. 0.))
            (cons 2 (setq Blockname (cdr (assoc 2 Block))))
            '(41 . 1.)
            '(42 . 1.)
            '(43 . 1.)
            '(50 . 0.)
      )
    )
    (setq lst (cons Blockname lst))
 )
 (print lst)
 (princ)
)

Share this post


Link to post
Share on other sites
jeremyearle5

Thanks Man! Too bad I have to wait until I get to work tonight to try it out.

Share this post


Link to post
Share on other sites
Tharwat
Thanks Man! Too bad I have to wait until I get to work tonight to try it out.

 

No problem ,

 

And forgot to say , welcome to the forum .:)

 

Tharwat

Share this post


Link to post
Share on other sites
marko_ribar

Maybe this :

 

(defun BlocksFound ( / a b )
   (while (setq a (tblnext "BLOCK" (null a)))
       (if
           (and
               (/= 4 (logand 4 (cdr (assoc 70 a))))
               (if (assoc 1 a) (not (findfile (cdr (assoc 1 a)))) T)
           )
           (setq b (cons (cdr (assoc 2 a)) b))
       )
   )
   b
)

(defun sortblocklist ()
 (vl-sort (blocksfound) '(lambda ( a b ) (< a b)))
)

(defun filterblocklist ( / pref stno enno no blname filtbllst )
 (setq pref (getstring T "\nInput prefix for blocks : "))
 (setq stno (getint "\nInput start number for filtering block list : "))
 (setq enno (getint "\nInput end number for filtering block list : "))
 (setq no (- stno 1))
 (while (<= no enno)
   (setq no (1+ no))
   (setq blname (strcat pref (itoa no)))
   (if (member blname (sortblocklist)) (setq filtbllst (cons blname filtbllst)))
 )
 (setq filtbllst (reverse filtbllst))
)

(defun c:insfilblcks nil
 (foreach bl (filterblocklist)
   (command "_.-insert" bl "0,0,0")
   (while (eq 1 (logand 1 (getvar 'cmdactive))) (command ""))
 )
(princ)
)

 

M.R.

Share this post


Link to post
Share on other sites
jeremyearle5

It worked great Marko! I just switched out the user input with the starting and ending numbers I needed. I appreciate it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×