hgcwh Posted June 8, 2012 Posted June 8, 2012 Hello, I insert a text block and then explode it ,and then I want to replace some texts Here is my lsp: (command ".-Insert" pause pause "1" "1" "0") (setq BA_O (entlast)) (command "explode" BA_O) (setq BA (entlast)) (setq BA_data (entget (car BA))) ……. It seems that I cannot use “ (setq BA (entlast))” to get exploded text object. It gives me “error: bad argument type: consp ” Please advise how I can assign exploded text object to variable BA. Many thanks Jay Quote
BlackBox Posted June 8, 2012 Posted June 8, 2012 What you should do is store the (entlast) prior to insertion/exploding of your block. Then use (entnext) to grab the proceeding entities (those after the (entlast) that you stored previously), until you reach the Text/Mtext entities you're after. Quote
hgcwh Posted June 8, 2012 Author Posted June 8, 2012 Hi, RenderMan Thank you for help. I modified code as you suggested (see below), BA_O is used to save last object. (entnext BA_O) is to get what is exploded. But I still get warning error: bad function: . Please advise. Thanks. Jay [/code] (command ".-Insert" pause pause "1" "1" "0") (setq BA_O (entlast)) (command "explode" BA_O) (setq BA (entnext BA_O)) (setq BA_data (entget (car BA))) What you should do is store the (entlast) prior to insertion/exploding of your block. Then use (entnext) to grab the proceeding entities (those after the (entlast) that you stored previously), until you reach the Text/Mtext entities you're after. Quote
Lee Mac Posted June 8, 2012 Posted June 8, 2012 Variable 'BA' is not a list, but an entity name - you are attempting to use the car function on this variable, causing an error. Perhaps use the asterisk (*) to insert the block already exploded: (setq e (entlast)) (command "_.-insert" (strcat "*" (getstring t "\nSpecify Block Name: ")) pause 1.0 0.0) (while (setq en (entnext en)) (setq lst (cons en lst)) ) 'lst' is then a list of entity names of the entities composing the block - remember to localise this variable in your program, otherwise it will be duplicated in each run. Or, with more error trapping: (defun c:test ( / *error* b c e l ) (defun *error* ( msg ) (if c (setvar 'cmdecho c)) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (princ) ) (while (not (or (eq "" (setq b (getstring t "\nSpecify Block Name: "))) (tblsearch "BLOCK" b) (setq b (findfile (strcat b ".dwg"))) ) ) ) (if b (progn (setq c (getvar 'cmdecho) e (entlast) ) (setvar 'cmdecho 0) (princ "\nSpecify Point for Block: ") (command "_.-insert" (strcat "*" b) pause 1.0 0.0) (while (setq e (entnext e)) (setq l (cons e l)) ) (print l) (setvar 'cmdecho c) ) ) (princ) ) 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.