Jump to content

How to select an attribute?


pkl

Recommended Posts

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)

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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"]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...