+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Forum Newbie
    Using
    AutoCAD 2016
    Join Date
    Oct 2015
    Posts
    2

    Default How to select an attribute?

    Registered forum members do not see this ad.

    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)

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,531

    Default

    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:

    [code] Your code here [/code]
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Forum Newbie
    Using
    AutoCAD 2016
    Join Date
    Oct 2015
    Posts
    2

    Default

    Thanx for helping.
    I tried to make it suitable for user input. There is somthing goiing wrong. Will you please look at it?


    Code:
    ;; (pstext "Prefix Text" "Suffix Text" <mode>)
    ;;
    ;; <mode> = 0  -  single selection
    ;;        = 1  -  window selection
    ;;
    ;; Author: Lee Mac 2011  -  www.lee-mac.com
    (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)
    )
    (defun c:tekst_voor_achter_single ( )
      (setq tekstvs (getstring "\nTekst voor: "))
      (setq tekstas (getstring "\nTekst achter: "))
        (pstext "tekstvs" "tekstas" 0)
    )
    (defun c:tekst_voor_achter_window ( )
      (setq tekstvw (getstring "\nTekst voor: "))
      (setq tekstaw (getstring "\nTekst achter: "))
        (pstext "tekstvw" "tekstaw" 1)
    )
    (princ "\nType \"tekst_voor_achter_single\" of \"tekst_voor_achter_window\".")

  4. #4
    Quantum Mechanic
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,499

    Default

    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.

    Code:
    ; 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
    Code:
    (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))
    Last edited by BIGAL; 19th Nov 2015 at 09:34 am. Reason: Did home work on lee's suggetsion
    A man who never made mistakes never made anything

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,531

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by pkl View Post
    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.:
    Code:
    (pstext tekstvs tekstas 0)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Select a block by attribute?
    By titoprax in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 18th May 2016, 08:39 pm
  2. Cant select attribute
    By Ski_Me in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 1
    Last Post: 2nd Jul 2015, 07:22 pm
  3. Select Blocks by Name & Attribute Property
    By churchill in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 1
    Last Post: 22nd Nov 2013, 01:34 am
  4. Select Attribute and Insert Current Date
    By nod684 in forum AutoLISP, Visual LISP & DCL
    Replies: 16
    Last Post: 1st Oct 2013, 04:07 pm
  5. Select block in Autocad and read attribute(VBA)
    By ZORANCRO in forum .NET, ObjectARX & VBA
    Replies: 7
    Last Post: 19th Sep 2012, 04:11 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts