Hana-m Posted yesterday at 07:45 AM Posted yesterday at 07:45 AM I’m working on part nesting in AutoCAD and I need to save each part as a block named after the part. Is there a way to create a block and automatically use a selected text object as the block name, instead of typing the name manually? Quote
SLW210 Posted 19 hours ago Posted 19 hours ago You would probably need a LISP. Maybe this one... I have moved your thread to the AutoLISP, Visual LISP & DCL Forum. Quote
Emmanuel Delay Posted 1 hour ago Posted 1 hour ago (edited) Based of this code by Lee Mac. I changed it to do what you ask for. - copy-paste this code to a file named select-text-as-block.lsp (or whatever, just make sure it has the .lsp extension), - Drag this file to your drawing - type command otbs, press enter, then follow the instructions. (select the objects; select the text object, select a point on screen) (I hope you don't need attributes; they seem to be somewhat of a problem with this code) ;; Objects to Block - Lee Mac ;; Converts a selection of objects to a block reference. ;; adapted by Emmanuel Delay : obj2blk separated from c:obj2blk (defun add_attdef ( / ip tag prmpt dfault) (entmake (list (cons 0 "ATTDEF") (cons 8 "0") (cons 10 '(0.3 4.3 0.0)) (cons 70 0) (cons 1 "") (cons 2 "NUM") (cons 3 "Number: ") (cons 40 2.0) ) ) ) ;; @params: s: selection, n: name, p: point (defun obj2blk (s n p / e i l s x ) (if (and s (progn (while (not (or (= "" n) (and (snvalid n) (null (tblsearch "BLOCK" n)) ) ) ) (princ "\nBlock name invalid or already exists.") ) (if (= "" n) (setq n "*U") ) p ) ) (progn (entmake (list '(0 . "BLOCK") (cons 10 (trans p 1 0)) (cons 02 n) (cons 70 (if (wcmatch n "`**") 1 0)) ) ) (repeat (setq i (sslength s)) (entmake (entget (setq e (ssname s (setq i (1- i)))))) (if (= 1 (cdr (assoc 66 (entget e)))) (progn (setq x (entnext e) l (entget x) ) (while (/= "SEQEND" (cdr (assoc 0 l))) (entmake l) (setq x (entnext x) l (entget x) ) ) (entmake l) ) ) (entdel e) ) ;;(add_attdef) (if (setq n (entmake '((0 . "ENDBLK")))) (entmake (list '(0 . "INSERT") (cons 02 n) (cons 10 (trans p 1 0)) ) ) ) ) ) (princ "\nBlock made: ") (princ n) ) (defun c:otb ( / s n p) (setq s (ssget "_:L" '((-4 . "<NOT") (0 . "ATTDEF,VIEWPORT") (-4 . "NOT>")))) ;;(setq s (ssget "_:L" '((-4 . "<NOT") (0 . "VIEWPORT") (-4 . "NOT>")))) (setq n (getstring t "\nSpecify Block Name <Anonymous>: ")) (setq p (getpoint "\nSpecify Base Point: ")) (obj2blk s n p) (princ) ) (defun c:otbs ( / s n p) (setq s (ssget "_:L" '((-4 . "<NOT") (0 . "ATTDEF,VIEWPORT") (-4 . "NOT>")))) ;;(setq s (ssget "_:L" '((-4 . "<NOT") (0 . "VIEWPORT") (-4 . "NOT>")))) ;;; (setq n (cdr (assoc 1 (entget (car (entsel "\nSelect a text object that holds the name of the block: ")))))) (setq p (getpoint "\nSpecify Base Point: ")) (obj2blk s n p) (princ) ) Edited 1 hour ago by Emmanuel Delay 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.