Jump to content
pkl

How to select an attribute?

Recommended Posts

pkl

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)

Share this post


Link to post
Share on other sites
Lee Mac

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]

Share this post


Link to post
Share on other sites
pkl

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"]

Share this post


Link to post
Share on other sites
BIGAL

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 by BIGAL
Did home work on lee's suggetsion

Share this post


Link to post
Share on other sites
Lee Mac
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)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×