+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 11 to 18 of 18
  1. #11
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,456

    Default

    Registered forum members do not see this ad.

    itacad,
    I still don't understand what you mean by "without evaluating the content".
    However this should work out your problem:

    Code:
    (defun C:SelBlksByAttTag ( / msg dcl des dch dcf r )
      
      (vl-some (function (lambda (x / msg) (and (vl-catch-all-error-p (setq msg (vl-catch-all-apply (eval x)))) (prompt (strcat "\nError: " (vl-catch-all-error-message msg))))))
        '(
          (function 
            (lambda nil 
              (and (setq dcl (vl-filename-mktemp nil nil ".dcl")) (setq des (open dcl "w"))
                (mapcar (function (lambda (x) (princ (strcat "\n" x) des))) 
                  '("SelBlksByAttTag : dialog"
                    "{ label = \"Select by Attribute\"; spacer_1;"
                    "  : boxed_column"
                    "  { label = \"Attribute options\";"
                    "    : toggle { label = \"Tag\"; key = \"at\"; value = 1; }"
                    "    : toggle { label = \"Value\"; key = \"av\"; value = 1; }"
                    "  }"
                    "  spacer;"
                    "  : boxed_radio_column"
                    "  { label = \"Block Selection\";"
                    "    : radio_button { label = \"All\"; key = \"sx\"; value = 1; }"
                    "    : radio_button { label = \"Manual\"; key = \"ss\"; }"
                    "  }"
                    "  spacer;"
                    "  : column"
                    "  {"
                    "    : toggle { label = \"Same Name Blocks\"; key = \"b\"; alignment = centered; }"
                    "  }"
                    "  spacer_1; ok_cancel; : text { key = \"error\"; }"
                    "}"
                  ); list
                ); mapcar
                (not (setq des (close des))) (< 0 (setq dch (load_dialog dcl))) (new_dialog "SelBlksByAttTag" dch)
                (progn 
                  (action_tile "accept"
                    (vl-prin1-to-string
                      (quote
                        (
                          (lambda ( / tmp )
                            (cond 
                              ( (not (setq tmp (apply 'append (mapcar '(lambda (x) (if (= "1" (get_tile x)) (list x))) '("at" "av")))))
                                (set_tile "error" "Specify Attribute Option!")
                              )
                              ( (setq r (append (list (= "1" (get_tile "b"))) (vl-some '(lambda (x) (if (= "1" (get_tile x)) (list x))) '("sx" "ss")) tmp))
                                (done_dialog 1) 
                              )
                            ); cond
                          ); lambda
                        )
                      ); quote
                    ); vl-prin1-to-string
                  ); action_tile
                  (/= 1 (setq dcf (start_dialog)))
                ); progn
                (setq r nil)
              ); and
            ); lambda
          ); function 
          (function 
            (lambda ( / nfo SS L )
              (cond
                ( (not r) )
                ( 
                  (not
                    (setq nfo
                      ('((f)(setvar 'errno 0) (f))
                        '(( / e enx o )
                          (cond
                            ( (= 52 (getvar 'errno)) nil)
                            (
                              (or
                                (not (setq e (car (nentsel "\nPick Attribute <exit>: ")))) 
                                (not (member '(0 . "ATTRIB") (setq enx (entget e)))) 
                                (and (= 7 (getvar 'errno)) (princ "\nMissed, try again.") (setvar 'errno 0))
                              )
                              (f)
                            )
                            ( (setvar 'errno 52) (setq o (vlax-ename->vla-object e))
                              (cons (vla-get-EffectiveName (vlax-ename->vla-object (cdr (assoc 330 enx)))) (mapcar '(lambda (x) (vlax-get o x)) '(TagString TextString)))
                            )
                          )
                        )
                      )
                    ); setq nfo
                  ); not
                )
                (
                  (not
                    (setq SS 
                      (ssget (cdr (assoc (cadr r) '(("ss" . "_:L-I")("sx" . "_X")))) 
                        (append 
                          '((0 . "INSERT") (66 . 1))
                          (if (car r) (list (cons 2 (strcat "`**," (car nfo)))))
                          (list (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model")))
                        ); append
                      ); ssget
                    ); setq SS
                  ); not
                )
                (
                  (
                    '(( b / bnm i o ) 
                      (setq i (sslength SS))
                      (cond 
                        (b
                          (setq bnm (car nfo))
                          (repeat i (and (eq bnm (vla-get-EffectiveName (setq o (vlax-ename->vla-object (ssname SS (setq i (1- i))))))) (setq L (cons o L))))
                        ); b
                        ( (repeat i (setq L (cons (vlax-ename->vla-object (ssname SS (setq i (1- i)))) L))) )
                      ); cond
                      (not L)
                    ); list
                    (car r)
                  )
                )
                (
                  (
                    '(( m v / nSS ) 
                      (setq nSS (ssadd))
                      (vl-some (function (lambda (a b) (if (equal a m) (eval b))))
                        '(("at" "av")("at")("av"))
                        '(
                          (foreach x L (and (vl-some '(lambda (att) (equal v (mapcar '(lambda (xx) (vlax-get att xx)) '(TagString TextString)))) (vlax-invoke x 'GetAttributes)) (ssadd (vlax-vla-object->ename x) nSS)))
                          (progn (setq v (car v)) (foreach x L (and (vl-some '(lambda (att) (eq (vlax-get att 'TagString) v)) (vlax-invoke x 'GetAttributes)) (ssadd (vlax-vla-object->ename x) nSS))))
                          (progn (setq v (cadr v)) (foreach x L (and (vl-some '(lambda (att) (eq (vlax-get att 'TextString) v)) (vlax-invoke x 'GetAttributes)) (ssadd (vlax-vla-object->ename x) nSS))))
                        ); list
                      ); vl-some
                      (sssetfirst nil nSS)
                    ); list
                    (cddr r)
                    (cdr nfo)
                  )
                )
              ); cond
            ); lambda
          ); function
        ); list
      ); vl-some
      
      '(((87 114 105 116 116 101 110 32 98 121) (71 114 114 114) (67 114 101 100 105 116 115 32 116 111) (76 101 101 32 77 97 99))
        (104 116  116  112 58 47 47 119	119 119 46 99 97 100 116  117 116  111 114 46 110	101  116  47 102 111 114 117 109 47 115 104 111  119	116 104 114 101 97 100 
          46 112 104 112 63 49 48	50 55 56 54 45 83 101 108 101 99 116  45 98	108  111 99 107 115 45 98 121 45 97 116 116 114 105 98 117 116 101 45 84 65 71
        )
      )
      
      (vl-catch-all-apply 'eval
        '(
          (progn
            (and (< 0 dch) (unload_dialog dch))
            (and (eq 'FILE (type des)) (close des))
            (and (eq 'STR (type dcl)) (findfile dcl) (vl-file-delete dcl))
          ); progn
        ); list
      ); vl-catch-all-apply
      (princ)
    ); defun
    (vl-load-com) (princ)
    SelBlksByAttTag.jpg

  2. #12
    Full Member
    Discipline
    Electrical
    Using
    AutoCAD 2018
    Join Date
    Jan 2018
    Posts
    34

    Default


    Incredible! it'is perfect!
    I am a bit ashamed because I have not contributed at all...
    With the hope that it will also be useful to others, I sincerely thank you!

  3. #13
    Quantum Mechanic BIGAL's Avatar
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,595

    Default

    Grrr like the.

    Code:
    (setq dcl (vl-filename-mktemp nil nil ".dcl")) (setq des (open dcl "w"))
    (princ (strcat "\n" x) des)))
    Much easier than write-line fo, learn something new everyday. Maybe a foreach method.
    A man who never made mistakes never made anything

  4. #14
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,456

    Default

    Quote Originally Posted by itacad View Post

    Incredible! it'is perfect!
    I am a bit ashamed because I have not contributed at all...
    With the hope that it will also be useful to others, I sincerely thank you!
    Glad it worked out and you are wellcome.
    Just be careful when explaining your request, I understood this part and I think its enough:
    Quote Originally Posted by itacad View Post
    It would be nice to have all these combinations in one lisp, and decide what to select:
    - attribute tag or attribute value
    - all blocks in the drawing or blocks in a selected area


    Quote Originally Posted by BIGAL View Post
    Grrr like the.

    Code:
    (setq dcl (vl-filename-mktemp nil nil ".dcl")) (setq des (open dcl "w"))
    (princ (strcat "\n" x) des)))
    Much easier than write-line fo, learn something new everyday. Maybe a foreach method.
    The overall dcl-on-the-fly technique (more precisely: the good DCL wrapping) was demonstrated by Lee Mac, so these stuff kinda originated from him (atleast I was introduced about this from him).
    Although to avoid again using 80% of his style in this code, I've decided to experiment would it work by using the error-trapping techniques only. (seems to work: erases the temporarily created .dcl file)
    So that explains the bit frustrating code (Lee's style was to wrap everything within a single cond function and exit with (*error* nil) in the end).

    In the end I did a conclusion that for these type of dialogs (that contain toggles and radio_buttons) is enough to define action_tile just for the 'accept' key and manipulate/check input there.

  5. #15
    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,572

    Default

    Thank you for your acknowledgement Grrr, happy to have inspired.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  6. #16
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,456

    Default

    Quote Originally Posted by Lee Mac View Post
    Thank you for your acknowledgement Grrr, happy to have inspired.
    Pleased to hear that Lee,
    Just making sure your hard effort and help won't remain unmentioned.

  7. #17
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    1,012

    Default

    yeah thankx a lot Grrr , had just one brain cell left and it exploded just by looking at your code

    so if you don't hear from me again , then I am probably still out there ... somewhere ... looking for a replacement...

    oh and thank you too Lee

  8. #18
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,456

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by rlx View Post
    yeah thankx a lot Grrr , had just one brain cell left and it exploded just by looking at your code

    so if you don't hear from me again , then I am probably still out there ... somewhere ... looking for a replacement...

    oh and thank you too Lee
    Just hit a few beers to wake-up the philosopher inside of you, and you'll be fine.

Similar Threads

  1. Replies: 8
    Last Post: 2nd Apr 2017, 08:05 pm
  2. [NEVERMIND] Select blocks by specific attribute value
    By Gotrekk in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 28th Apr 2016, 05:03 pm
  3. How to select an attribute?
    By pkl in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 22nd Nov 2015, 06:52 pm
  4. Cant select attribute
    By Ski_Me in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 1
    Last Post: 2nd Jul 2015, 07:22 pm
  5. 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

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