pkl Posted November 16, 2015 Share Posted November 16, 2015 Hello everybody, I have a lisproutine wich will modify the value (add a string before the existing value) of an attibute in an block. This works fine but it changes all the attributes. Does anybody know how i can change the scrip so i can select the attribute by mouseclick? Peter Here is the lisp i use: (defun c:Test (/ s) (setq tekst (getstring "\nVoer in te voegen tekst in: ")) (princ "\nSelect Attributed Blocks") (if (setq s (ssget "_:L" '((0 . "INSERT")(66 . 1)))) ((lambda (i / sn) (while (setq sn (ssname s (setq i (1+ i)))) (mapcar '(lambda (u) (vla-put-textstring u (strcat tekst (vla-get-textstring u)))) (vlax-invoke (vlax-ename->vla-object sn) 'getattributes) ) )) -1) ) (princ) ) (vl-load-com) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 16, 2015 Share Posted November 16, 2015 ssget doesn't allow selection of subentities - you will need to use nentsel or nentselp. Given the operation your program is performing, you might find this program useful. PS: Please edit your post and enclose your code with code tags: [highlight][noparse] [/noparse][/highlight] Your code here [highlight][noparse] [/noparse][/highlight] Quote Link to comment Share on other sites More sharing options...
pkl Posted November 18, 2015 Author Share Posted November 18, 2015 Thanx for helping. I tried to make it suitable for user input. There is somthing goiing wrong. Will you please look at it? [/font] [font="Calibri"];; (pstext "Prefix Text" "Suffix Text" <mode>) ;; ;; <mode> = 0 - single selection ;; = 1 - window selection ;; ;; Author: Lee Mac 2011 - [url="http://www.lee-mac.com"]www.lee-mac.com[/url][/font] [font="Calibri"](defun pstext ( preftext sufftext mode / a e i s ) (cond ( (= 0 mode) (while (progn (setvar 'ERRNO 0) (setq e (car (nentsel))) (cond ( (= 7 (getvar 'ERRNO)) (princ "\nMissed, try again.") ) ( (eq 'ENAME (type e)) (if (wcmatch (cdr (assoc 0 (entget e))) "TEXT,MTEXT,ATTRIB") (entmod (setq e (entget e) a (assoc 1 e) e (subst (cons 1 (strcat preftext (cdr a) sufftext)) a e) ) ) (princ "\nInvalid Object.") ) ) ) ) ) ) ( (setq s (ssget "_:L" (list '(0 . "TEXT,MTEXT")))) (repeat (setq i (sslength s)) (entmod (setq e (entget (ssname s (setq i (1- i)))) a (assoc 1 e) e (subst (cons 1 (strcat preftext (cdr a) sufftext)) a e) ) ) ) ) ) (princ) )[/font] [font="Calibri"](defun c:tekst_voor_achter_single ( ) (setq tekstvs (getstring "\nTekst voor: ")) (setq tekstas (getstring "\nTekst achter: ")) (pstext "tekstvs" "tekstas" 0) )[/font] [font="Calibri"](defun c:tekst_voor_achter_window ( ) (setq tekstvw (getstring "\nTekst voor: ")) (setq tekstaw (getstring "\nTekst achter: ")) (pstext "tekstvw" "tekstaw" 1) )[/font] [font="Calibri"](princ "\nType \"tekst_voor_achter_single\" of \"tekst_voor_achter_window\".")[/font] [font="Calibri"] Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 19, 2015 Share Posted November 19, 2015 (edited) You may be better using a pick a block but do it on attribute that you pick when selecting a block and it returns the attribute tag name. Use the pick pt to get block name using entsel as 2nd go. Lee on the mark as usual. ; example code to get block name and attribute to change (setq ent (nentsel "pick block attribute to change")) (setq tagname (cdr (assoc 2 (entget (car ent))))) ; tagname picked (setq ptxyz (nth 0 (cdr ent))) (setq ent2 (ssget ptxyz)) (setq bname (cdr (assoc 2 (entget (ssname ent2 0))))) ; block name What you want (setq ent (entget (car (nentsel "pick block attribute to change")))) (setq att (cdr (assoc 1 ent))) ; attribute picked (setq b (strcat "xxx " att)) (entmod (subst (cons 1 b) (assoc 1 ent) ent)) Edited November 19, 2015 by BIGAL Did home work on lee's suggetsion Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 22, 2015 Share Posted November 22, 2015 Thanx for helping.I tried to make it suitable for user input. There is somthing goiing wrong. Will you please look at it? A good effort - simply remove the double-quotes around your variables when passing the values to the pstext function, i.e.: (pstext tekstvs tekstas 0) 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.