Change Block Visibility depending on File Name using LISP

Change Block Visibility depending on File Name using LISP

kieran.leadbetter
Advocate Advocate
341 Views
3 Replies
Message 1 of 4

Change Block Visibility depending on File Name using LISP

kieran.leadbetter
Advocate
Advocate

Good morning. Would anyone know of a lisp which is easily adjustable to add multiple outcomes for this request:

I am needing a lisp which will update a dynamic-visibility block (which has 10 different visibilities), which I change depending on the file name

File Name: 01 - Visibility: First Floor 

File Name: 02 - Visibility: Second Floor 

File Name: 03 - Visibility: Third Floor 

File Name: 04 - Visibility: Fourth Floor etc...

I have a lisp I recieved from LeeMac which allows me to manually adjust a blocks visibility which is super useful, I only use the first portion of said lisp.

 

If someone could help me merge this into a lisp which detects a file name and changes the visibility depending on this, then my titleblocks will be nearly fully automatic and save so much time and error.

(defun c:changevis-BLOCKNAME ( / blk idx obj sel vis )

(setq blk "BLOCK" ;; Block Name
vis "VISIBILITY" ;; New Visibility State
)
(if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)) '(410 . "~Model"))))
(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
342 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant

Just use some functions from  THIS list to extract the visibility name for the filename and save it to the vis variable on the 4th line of the code. You know little of DIESEL... so that won't be too difficult for you.

 

vis (substr.... (getvar 'dwgname) ....

0 Likes
Message 3 of 4

Sea-Haven
Mentor
Mentor

(strcat "`*U*," blk) will find differentdynamic  blocks not just the name of the one you want to change, as its dynamic you need to go through the *Uxx blocks and look at their effective names if they match blk then change the visibilty. 

 

; loop through selection set and if name is "*U..." 
(if (and (vlax-property-available-p blk 'effectivename)
    (= (vla-get-effectivename blk) "yourblockname"))
(do something)
)
0 Likes
Message 4 of 4

komondormrex
Mentor
Mentor

are the file names and visibility states supposed to be like ones in quotes?

File Name: "01[.dwg]" - Visibility: "First Floor"
File Name: "02[.dwg]" - Visibility: "Second Floor"
File Name: "03[.dwg]" - Visibility: "Third Floor"
File Name: "04[.dwg]" - Visibility: "Fourth Floor"
...
File Name: "10[.dwg]" - Visibility: "Tenth Floor"

0 Likes