Steven P Posted July 9, 2019 Share Posted July 9, 2019 Good afternoon, I have been trying to use entmake to create a block which works sort of using this as an example: (entmake '((0 . "BLOCK") (2 . "MyNewBlock") (70 . 64) (10 4.0 5.0 0.0))) (entmake '((0 . "LINE") (10 0 0) (11 2 2))) (entmake '((0 . "ENDBLK"))) (entmake '((0 . "INSERT") (2 . "MyNewBlock") (10 6.0 6.0 0.0))) (this creates a block with a single line, simple for my question). First question, I would like to use variables as the line points, but I don't know how to do that, google hasn't helped much and I can't think of anything else to try, so (entmake '((0 . "LINE")(10 0 0)(... might become (entmake '(0 . "LINE") (10 pt1 pt2)(.... Second question might be the same answer. I can rename the block after it is created (I think) - but it would be nicer to create it with the correct name to start with - what I am doing will create different blocks based on user input. Thanks for any help or pointers, hope I have explained this clear enough Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 9, 2019 Share Posted July 9, 2019 Hi, An example: (setq p1 '(0. 0. 0.)) (setq p2 '(2.0 2.0 0.0)) (entmake (list '(0 . "LINE") (cons 10 p1) (cons 11 p2))) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 9, 2019 Share Posted July 9, 2019 Here's an existing example for non-attributed blocks: ;; Objects to Block - Lee Mac ;; Converts a selection of objects to a block reference. (defun c:obj2blk ( / e i l n p s x ) (if (and (setq s (ssget "_:L" '((-4 . "<NOT") (0 . "ATTDEF,VIEWPORT") (-4 . "NOT>")))) (progn (while (not (or (= "" (setq n (getstring t "\nSpecify Block Name <Anonymous>: "))) (and (snvalid n) (null (tblsearch "BLOCK" n)) ) ) ) (princ "\nBlock name invalid or already exists.") ) (if (= "" n) (setq n "*U") ) (setq p (getpoint "\nSpecify Base Point: ")) ) ) (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) ) (if (setq n (entmake '((0 . "ENDBLK")))) (entmake (list '(0 . "INSERT") (cons 02 n) (cons 10 (trans p 1 0)) ) ) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Steven P Posted July 10, 2019 Author Share Posted July 10, 2019 Thanks, Tharwat, that's about the only thing I didn't try yesterday! Lee, once again, that looks like the work of a genius, I'll try it out today. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 10, 2019 Share Posted July 10, 2019 (edited) You're welcome @Steven P, I hope it helps - if necessary, the program could be stripped back to a function which simply accepts a selection set of objects, a basepoint, and a block name, and then generates the corresponding block definition (and block reference) using entmake. Hopefully the posted code demonstrates the techniques for accomplishing this, though of course, feel free to ask if you are unsure about anything. Edited July 10, 2019 by Lee Mac Quote Link to comment Share on other sites More sharing options...
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.