tnvsb Posted September 29, 2018 Posted September 29, 2018 Dear All, a small modification to be done in followig code. The below code can match the sorce text value to destination text value. The modifcation I need is to match block name value to selected text value. Lisp Code 1 for reference: (defun c:MT() (setq entt (car (entsel "Select source text:"))) (setq enttx (entget entt)) (setq txt (assoc 1 enttx)) (setq entd (entget (car (entsel "Select destination DIMENSION:")))) (setq dtx (assoc 1 entd)) (setq vij (subst txt dtx entd)) (entmod vij)) Or other code I have, that can match text value to block name value. (defun c:RNB (/ *error* _strip ssText ssBlock newBlockName blockName acDoc) (defun *error* (msg) (if acDoc (vla-endundomark acDoc) ) (cond ((not msg)) ; Normal exit ((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit) ((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it ) (princ) ) (defun _strip (string) (foreach char '("<" ">" ":" "\"" "/" "\\" "|" "?" "*") (while (vl-string-search char string) (setq string (vl-string-subst "" char string)) ) ) string ) (while (and (princ "\nSelect text: ") (setq ssText (ssget ":S:E" '((0 . "MTEXT,TEXT")))) (princ "\nSelect block to rename: ") (setq ssBlock (ssget ":S:E" '((0 . "INSERT")))) (/= (setq newBlockName (strcat "" (_strip (vla-get-textstring (vlax-ename->vla-object (ssname ssText 0)) ) ) ) ) (setq blockName (vla-get-effectivename (vlax-ename->vla-object (ssname ssBlock 0)) ) ) ) (not (tblsearch "block" newBlockName)) ) (progn (vla-startundomark (setq acDoc (vla-get-activedocument (vlax-get-acad-object))) ) (vla-put-name (vla-item (vla-get-blocks acDoc) blockName) newBlockName ) (prompt (strcat "\nBlock \"" blockName "\" renamed to \"" newBlockName "\" " ) ) ) ) ) Regards, T.Brahmanandam Quote
marko_ribar Posted September 29, 2018 Posted September 29, 2018 (edited) Simply... (defun c:BN2TXT ( / bl txt bln ) (vl-load-com) (while (or (not (setq bl (car (entsel "\nPick block to implement its name to text entity...")))) (if bl (or (/= (cdr (assoc 0 (entget bl))) "INSERT") (= (vla-get-isxref (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (vla-get-name (vlax-ename->vla-object bl)))) :vlax-true) ) ) ) (prompt "\nMissed or picked wrong entity type...") ) (while (or (not (setq txt (car (entsel "\nPick destination text entity...")))) (if txt (not (wcmatch (cdr (assoc 0 (entget txt))) "*TEXT")) ) ) (prompt "\nMissed or picked wrong entity type...") ) (setq bln (vla-get-effectivename (vlax-ename->vla-object bl))) (vla-put-textstring (vlax-ename->vla-object txt) bln) (princ) ) Edited September 29, 2018 by marko_ribar Quote
tnvsb Posted September 29, 2018 Author Posted September 29, 2018 Dear Sir, I am getting error as below. Please help me. ; error: bad argument type: numberp: nil Command: Bn2txt Unknown command "BN2TXT". Press F1 for help Quote
marko_ribar Posted September 29, 2018 Posted September 29, 2018 1 hour ago, tnvsb said: Dear Sir, I am getting error as below. Please help me. ; error: bad argument type: numberp: nil Command: Bn2txt Unknown command "BN2TXT". Press F1 for help I don't receive such an error... Please retest it again... If someone else has an issue with error, then something's wrong, but on my PC it works just fine... M.R. Quote
tnvsb Posted September 29, 2018 Author Posted September 29, 2018 Thank you sir, Now it's working fine, I don't know what happened earlier. Regards, T.Brahmanandam 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.