Astro Posted August 6, 2009 Posted August 6, 2009 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 Quote
Lee Mac Posted August 6, 2009 Posted August 6, 2009 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)) Quote
Astro Posted August 6, 2009 Author Posted August 6, 2009 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 Quote
Lee Mac Posted August 6, 2009 Posted August 6, 2009 Thank you so much!!! you saved my day No probs mate Quote
Astro Posted August 6, 2009 Author Posted August 6, 2009 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. Quote
David Bethel Posted August 6, 2009 Posted August 6, 2009 Remove the "_X" statement from the ssget call and it will ask you for the selections. -David Quote
Astro Posted August 6, 2009 Author Posted August 6, 2009 Thank you so much I have realy to learn lisp language. You can do so great things with. Quote
Astro Posted September 24, 2009 Author Posted September 24, 2009 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)) Quote
Lee Mac Posted September 24, 2009 Posted September 24, 2009 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)) Quote
mk4176 Posted June 13, 2018 Posted June 13, 2018 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. Quote
dlanorh Posted June 13, 2018 Posted June 13, 2018 What are the initial visibility states of the three attributes? If there is no value in LEGAL_LENGTH is it still visible? Quote
mk4176 Posted June 14, 2018 Posted June 14, 2018 It doesn't matter, I want to run the lisp, depending on the condition, I want the final state. Quote
mjab8 Posted June 14, 2018 Posted June 14, 2018 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 Quote
mk4176 Posted June 14, 2018 Posted June 14, 2018 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 Quote
dlanorh Posted June 14, 2018 Posted June 14, 2018 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 Quote
mk4176 Posted June 14, 2018 Posted June 14, 2018 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. Quote
dlanorh Posted June 14, 2018 Posted June 14, 2018 (edited) Post Removed Edited June 14, 2018 by dlanorh Quote
dlanorh Posted June 15, 2018 Posted June 15, 2018 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 Quote
Recommended Posts
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.