jeremyearle5 Posted December 12, 2011 Posted December 12, 2011 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? Quote
Tharwat Posted December 12, 2011 Posted December 12, 2011 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) ) Quote
jeremyearle5 Posted December 12, 2011 Author Posted December 12, 2011 Thanks Man! Too bad I have to wait until I get to work tonight to try it out. Quote
Tharwat Posted December 12, 2011 Posted December 12, 2011 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 Quote
marko_ribar Posted December 12, 2011 Posted December 12, 2011 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. Quote
jeremyearle5 Posted December 13, 2011 Author Posted December 13, 2011 It worked great Marko! I just switched out the user input with the starting and ending numbers I needed. I appreciate it. 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.