Modify Visibility state change program for selected blocks

Modify Visibility state change program for selected blocks

murmanator
Advocate Advocate
723 Views
4 Replies
Message 1 of 5

Modify Visibility state change program for selected blocks

murmanator
Advocate
Advocate

The program below works great to modify ALL blocks in model space to the defined visibility state. I would like to modify it to change only selected blocks.

 

(defun c:changevis ( / blk idx obj sel vis ) ;;;<<< CHANGES VISIBILITY STATE OF ALL BLOCKS IN MODEL SPACE
(setq blk "SCHEM-SPA-RTN" ;; Block Name
vis "90" ;; New Visibility State
)
(if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)))))
(repeat (setq idx (sslength sel))
(if (= (strcase blk) (strcase (LM:blockname (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))))))
(LM:SetVisibilityState obj vis)
)
)
)
(princ)
)

 

I tried a few ways of using this but nothing worked out (this is a program I use to change the Block Table selection, I thought it would work for Visibility state also but no):

 

(defun C:TEST ( / ss )
(if (setq ss (ssget '((0 . "INSERT"))))
(while (setq e (ssname ss 0))
(setpropertyvalue e
"AcDbDynBlockPropertyVisibility 1" 90)
(ssdel e ss)
)
)(princ)
)

0 Likes
Accepted solutions (1)
724 Views
4 Replies
Replies (4)
Message 2 of 5

CodeDing
Advisor
Advisor
Accepted solution

@murmanator ,

 

Just remove this piece and it will force the user to select items instead:

 

(if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)))))

 

0 Likes
Message 3 of 5

murmanator
Advocate
Advocate

Thanks @CodeDing , I tried this and it returned ; error: bad argument type: lselsetp nil

 

(defun c:changevis ( / blk idx obj sel vis ) ;;;<<< CHANGES VISIBILITY STATE OF ALL BLOCKS IN MODEL SPACE
(setq blk "SCHEM-SPA-RTN" ;; Block Name
vis "90" ;; New Visibility State
)

(repeat (setq idx (sslength sel))
(if (= (strcase blk) (strcase (LM:blockname (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))))))
(LM:SetVisibilityState obj vis)
)
)

(princ)
)

0 Likes
Message 4 of 5

CodeDing
Advisor
Advisor

@murmanator ,

 

I did not mean for the entire line to be deleted. Only remove this part:

 

"_X"

 

Sorry, I thought my formatting would have made that clear. 

0 Likes
Message 5 of 5

murmanator
Advocate
Advocate

My apologies, the formatting did not come through in the email, it looked like the whole line. That did do the trick, thank you again!