Jump to content

lisp to toggle a specific attribute visible/invisible


Astro

Recommended Posts

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

AM2.LSP

Link to comment
Share on other sites

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • Astro

    6

  • dlanorh

    6

  • mk4176

    6

  • Lee Mac

    4

Top Posters In This Topic

Posted Images

Easier way:

 

(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))

Link to comment
Share on other sites

Easier way:

 

(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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 month later...

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?

 

 

 
(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))

Link to comment
Share on other sites

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

 


(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))

:)

Link to comment
Share on other sites

  • 8 years later...

Hello,

Any help is appreciated.

I need to add to this code few conditions.

 

I have a block (C1609) with the following Tags:

 

LEGAL_LENGTH

CALC_LENGTH

CROSS

 

1. I need to make LEGAL_LENGTH and CALC_LENGTH Visible if there is a "/" in CROSS.

 

2. I need to make CALC_LENGTH visible if there is no value in LEGAL_LENGTH

 

3. I need to make LEGAL_LENGTH visible and CALC_LENGTH invisible if there is no "/" in CROSS

 

thanks in advance

 

M.K.

Link to comment
Share on other sites

What are the initial visibility states of the three attributes?

If there is no value in LEGAL_LENGTH is it still visible?

Link to comment
Share on other sites

Instead of toggle On/Off, is it possible to have a few preset options to choose Tags combination (using getkword) visibility ON, eg. TAG1&TAG2, TAG2&TAG3, TAG1 only, TAG2 only and All ON?

Thanks

Link to comment
Share on other sites

Maybe I should explain in another words.

The drawing has a lot of block instances of block C1609 (Attached:C1609.dwg)

If TAG "CROSS" has "/" in it, the other TAGS should be visible.

If TAG "LEGAL_LENGTH" has any value, and no "/" in TAG "CROSS", TAG "CALCULATE_LENGTH" should be invisible.

IF TAG "LEGAL_LENGTH" is empty, TAG "CALCULATED_LENGTH" should be visible, or the visibility state of TAG LEGAL_LENGTH doesn't matter because it's empty.

It should be stated that not always there is a LEGAL_LENGTH value, but always there is CALCULATED_LENGTH value.

The lisp should scan the drawing of any instances of block C1609 and modify the visibility state depending on the conditions in each instance.

Thank you

Link to comment
Share on other sites

OK, Try this. It has only been briefly tested on a block I constructed.

(vl-load-com)
(defun C:test ( / *error* c_doc ss atts a_lst t_str)

 (defun *error* ( msg )
       (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
       (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
       (princ)
   );end_defun
   
   (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
         ss (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "C1609")))
   );end_setq

   (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
   (vla-startundomark c_doc)
   
   (vlax-for blk (vla-get-activeselectionset c_doc)
   (setq a_lst nil
         atts (append (vlax-invoke blk 'GetAttributes) (vlax-invoke blk 'GetConstantAttributes))
   );end_setq
   (foreach att atts
     (setq a_lst (cons (cons (vlax-get-property att 'tagstring) (list att (vlax-get-property att 'textstring))) a_lst))
     (vlax-put-property att 'invisible :vlax-false)
   );end_foreach
   (setq t_str (cadr (cdr (assoc "CROSS" a_lst))))      
   (if (not (wcmatch t_str "*/*"))
     (vlax-put-property (car (cdr (assoc "CALC_LENGTH" a_lst))) 'invisible :vlax-true)
   );end_if         
 );_end vlax-for t_blk
   (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
);end_defun  

Link to comment
Share on other sites

Thank you very much.

First Case worked perfectly when there is a "/" in CROSS, both CLACULATED_LENGTH and LEGAL_LENGTH are on.

Second Case did not work.

It turned all CALCULATED_LENGTH off even if there is no "/" in CROSS or LEGAL_LENGTH is empty.

Can you, please, fix that.

Link to comment
Share on other sites

OK I think this no works as you want it.

 

 

(vl-load-com)
(defun C:test ( / *error* c_doc ss atts a_lst t_str l_val)

 (defun *error* ( msg )
   (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
   (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
   (princ)
 );end_defun
           
 (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
       ss (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "C1609")))
 );end_setq

 (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
 (vla-startundomark c_doc)
           
 (vlax-for blk (vla-get-activeselectionset c_doc)
   (setq a_lst nil
         atts (append (vlax-invoke blk 'GetAttributes) (vlax-invoke blk 'GetConstantAttributes))
   );end_setq
   (foreach att atts
     (setq a_lst (cons (cons (vlax-get-property att 'tagstring) (list att (vlax-get-property att 'textstring))) a_lst))
     (vlax-put-property att 'invisible :vlax-false)
   );end_foreach
   (setq t_str (cadr (cdr (assoc "CROSS" a_lst)))
         l_val (strlen (cadr (cdr (assoc "LEGAL_LENGTH" a_lst))))
   );end_setq                    
   (if (and (not (vl-string-search "/" t_str)) (> l_val 0))
     (vlax-put-property (car (cdr (assoc "CALC_LENGTH" a_lst))) 'invisible :vlax-true)
   );end_if         
 );_end vlax-for t_blk
 (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
);end_defun

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...