+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Mar 2009
    Posts
    31

    Default lisp to toggle a specific attribute visible/invisible

    Registered forum members do not see this ad.

    Hi all,

    I have a lisp to switch the visibility off all the attributes off my drawing with a specific TAG (e.g. TAG1) . The lisp scan all the blocks containing this TAG.
    But i have to type on the command line "on" or "off" to swicht the visibility off the attribute.

    What can i do to switch the mode directly without typing on the command line "on or "off".
    Let's say, if TAG1 is visible then it switch to invisible.
    If TAG1 is invisible it switch to visible.

    Maybee somebody can help me with this lisp. Thank you
    Attached Files

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,882

    Default

    Easier way:

    Code:
    (defun c:am2 (/ tag ss sel)
      (vl-load-com)
    
      (setq tag "TAG1") ;; <<-- Tag to be Searched
    
      (and (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))
           (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet
                                     (vla-get-ActiveDocument (vlax-get-acad-object))))
              (foreach att (append (vlax-invoke Obj 'GetAttributes)
                                   (vlax-invoke Obj 'GetConstantAttributes))
                (if (eq tag (strcase (vla-get-TagString att)))
                  (vla-put-invisible att
                    (cond ((eq :vlax-true (vla-get-invisible att)) :vlax-false)
                          (:vlax-true))))))
           (vla-delete sel))
    
      (princ))
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  3. #3
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Mar 2009
    Posts
    31

    Default Thank you

    Quote Originally Posted by Lee Mac View Post
    Easier way:

    Code:
    (defun c:am2 (/ tag ss sel)
      (vl-load-com)
     
      (setq tag "TAG1") ;; <<-- Tag to be Searched
     
      (and (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))
           (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet
                                     (vla-get-ActiveDocument (vlax-get-acad-object))))
              (foreach att (append (vlax-invoke Obj 'GetAttributes)
                                   (vlax-invoke Obj 'GetConstantAttributes))
                (if (eq tag (strcase (vla-get-TagString att)))
                  (vla-put-invisible att
                    (cond ((eq :vlax-true (vla-get-invisible att)) :vlax-false)
                          (:vlax-true))))))
           (vla-delete sel))
     
      (princ))
    Thank you so much!!! you saved my day

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,882

    Default

    Quote Originally Posted by Astro View Post
    Thank you so much!!! you saved my day
    No probs mate
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  5. #5
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Mar 2009
    Posts
    31

    Default

    Hi, It's me again.

    Your lisp works perfectly. Thank you.

    One last question. Is there a way to do exactly the same but by selection? So i can select the blocks i want to switch the visibility off the attribute.

  6. #6
    Forum Deity David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    2,075

    Default

    Remove the "_X" statement from the ssget call and it will ask you for the selections. -David
    R12 (Dos) - A2K

  7. #7
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Mar 2009
    Posts
    31

    Default

    Thank you so much

    I have realy to learn lisp language. You can do so great things with.

  8. #8
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Mar 2009
    Posts
    31

    Default

    Hi Guys,

    I have a simple question for you.

    I have this code to change the visibility of an attribute.
    What do i have to change in my code if i want to change the visiblity off "TAG1" and "TAG2" and maybe also "TAG3" if i want to add it later by my own in the code?


    Code:
     
    (defun c:am2 (/ tag ss sel)
      (vl-load-com)
    
      (setq tag "TAG1") ;; <<-- Tag to be Searched
    
      (and (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))
           (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet
                                     (vla-get-ActiveDocument (vlax-get-acad-object))))
              (foreach att (append (vlax-invoke Obj 'GetAttributes)
                                   (vlax-invoke Obj 'GetConstantAttributes))
                (if (eq tag (strcase (vla-get-TagString att)))
                  (vla-put-invisible att
                    (cond ((eq :vlax-true (vla-get-invisible att)) :vlax-false)
                          (:vlax-true))))))
           (vla-delete sel))
    
      (princ))

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,882

    Default

    Use a list instead, and check for that member in the list:

    Code:
     
    (defun c:am2 (/ tag ss sel)
      (vl-load-com)
    
      (setq tag '("TAG1" "TAG2" "TAG3"))  ;; <<-- Tag(s) to be Searched
    
      (and (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))
           (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet
                                     (vla-get-ActiveDocument (vlax-get-acad-object))))
              (foreach att (append (vlax-invoke Obj 'GetAttributes)
                                   (vlax-invoke Obj 'GetConstantAttributes))
                (if (vl-position (strcase (vla-get-TagString att)) tag)
                  (vla-put-invisible att
                    (cond ((eq :vlax-true (vla-get-invisible att)) :vlax-false)
                          (:vlax-true))))))
           (vla-delete sel))
    
      (princ))
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  10. #10
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Mar 2009
    Posts
    31

    Default

    Registered forum members do not see this ad.

    Thanks Man ,

    It's working

Similar Threads

  1. Replies: 0
    Last Post: 2nd Apr 2009, 01:05 pm
  2. Toggle display color with LISP
    By Flores in forum AutoLISP, Visual LISP & DCL
    Replies: 21
    Last Post: 11th Nov 2008, 03:43 pm
  3. Is there a LISP to toggle layers?
    By Ste1978 in forum AutoLISP, Visual LISP & DCL
    Replies: 15
    Last Post: 18th Jul 2008, 01:54 pm
  4. Little help needed with visible/invisible lines
    By jay in forum AutoCAD Beginners' Area
    Replies: 4
    Last Post: 19th Dec 2005, 10:42 pm
  5. ... Insert attribute information into specific Xcell Cells?
    By Pablo Ferral in forum AutoCAD General
    Replies: 3
    Last Post: 13th Apr 2005, 07:32 pm

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