Jump to content
Astro

lisp to toggle a specific attribute visible/invisible

Recommended Posts

Astro

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

Share this post


Link to post
Share on other sites
Lee Mac

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

Share this post


Link to post
Share on other sites
Astro
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 :)

Share this post


Link to post
Share on other sites
Lee Mac
Thank you so much!!! you saved my day :)

 

No probs mate :)

Share this post


Link to post
Share on other sites
Astro

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.

Share this post


Link to post
Share on other sites
David Bethel

Remove the "_X" statement from the ssget call and it will ask you for the selections. -David

Share this post


Link to post
Share on other sites
Astro

Thank you so much :D

 

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

Share this post


Link to post
Share on other sites
Astro

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

Share this post


Link to post
Share on other sites
Lee Mac

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

:)

Share this post


Link to post
Share on other sites
Astro

Thanks Man ,

 

It's working :shock:

Share this post


Link to post
Share on other sites
Lee Mac

No probs :)

Share this post


Link to post
Share on other sites
mk4176

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.

Share this post


Link to post
Share on other sites
dlanorh

What are the initial visibility states of the three attributes?

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

Share this post


Link to post
Share on other sites
mk4176

It doesn't matter, I want to run the lisp, depending on the condition, I want the final state.

Share this post


Link to post
Share on other sites
mjab8

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

Share this post


Link to post
Share on other sites
mk4176

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

Share this post


Link to post
Share on other sites
dlanorh

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  

Share this post


Link to post
Share on other sites
mk4176

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.

Share this post


Link to post
Share on other sites
dlanorh
Posted (edited)

Post Removed

Edited by dlanorh

Share this post


Link to post
Share on other sites
dlanorh

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×