Jump to content

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


Recommended Posts

Posted

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?

Posted

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

Posted

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

Posted
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

Posted

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.

Posted

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

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