Craig.Baldie
2007-10-11, 05:23 AM
Hi all
After some help with a LISP routine I'm currently writing. I have got the routine to work fine the way I want it but i need to modify it to include checking to see if layers exists and if they dont skip down to the next part of the code.
We use XREFs in our drawings which have 3 different layers im interested in.
heres my code below:
(defun c:safetylayers ()
(setvar "cmdecho" 0)
(acet-autoload2 '("FLATTENSUP.LSP" (acet-flatn ss hide))) ;load flatten command function
(command "-layer" "s" "0" "") ;set layer 0 active
(command "-layer" "f" "*" "") ;freeze all layers
(while (setq LAYER (tblnext "LAYER" (null LAYER))) ;check to see if similar layer exists
(if (wcmatch (cdr (assoc 2 LAYER)) "*|SAFETY")
(setq layercheck 1)
); end if
); end while
(if (= layercheck 1) ;if layer exists perform function
(progn
(command "-layer" "t" "*|SAFETY" "")
(setq ss1 (ssget))
(command "copy" "p" "" "0,0,0" "0,0,0")
(acet-flatn ss1 T)
(command ".chprop" "p" "" "la" "AS4685 SAFETY LAYER" "")
); end progn
); end if
(while (setq LAYER2 (tblnext "LAYER" (null LAYER2)))
(if (wcmatch (cdr (assoc 2 LAYER2)) "*|SAFETY FREE SPACE")
(setq layercheck2 1)
); end if
); end while
(if (= layercheck2 1)
(progn
(command "-layer" "f" "*" "")
(command "-layer" "t" "0" "")
(command "-layer" "t" "*|SAFETY FREE SPACE" "")
(setq ss2 (ssget))
(command "copy" "p" "" "0,0,0" "0,0,0")
(acet-flatn ss2 T)
(command ".chprop" "p" "" "la" "AS4685 SAFETY LAYER" "")
(command ".chprop" "p" "" "co" "green" "")
(command "-layer" "f" "*" "")
); end progn
); end if
(while (setq LAYER3 (tblnext "LAYER" (null LAYER3)))
(if (wcmatch (cdr (assoc 2 LAYER3)) "*|SAFETY499")
(setq layercheck3 1)
); end if
); end while
(if (= layercheck3 1)
(progn
(command "-layer" "f" "*" "")
(command "-layer" "t" "0" "")
(command "-layer" "t" "*|SAFETY499" "")
(setq ss3 (ssget))
(command "copy" "p" "" "0,0,0" "0,0,0")
(acet-flatn ss3 T)
(command ".chprop" "p" "" "la" "AS4685 SAFETY LAYER" "")
(command ".chprop" "p" "" "co" "30" "")
); end progn
); end if
(command "-layer" "f" "*safety*" "t" "AS4685 SAFETY LAYER" "")
) ; end c:safetylayers function
The part I have got stuck on is the check with the while loop and using the WCMATCH.
I would like the routine to search and see if a certain layer exists on an XREF, if it does perform the flatten function etc If it doesnt then just go onto the next check. I'm only new to LISP so my programming probably isnt too great but like I said before the routine works great for me if all the 3 layers are present in a drawing (without the need for checking)
Any help would be greatly appreciated
thanks
Craig
After some help with a LISP routine I'm currently writing. I have got the routine to work fine the way I want it but i need to modify it to include checking to see if layers exists and if they dont skip down to the next part of the code.
We use XREFs in our drawings which have 3 different layers im interested in.
heres my code below:
(defun c:safetylayers ()
(setvar "cmdecho" 0)
(acet-autoload2 '("FLATTENSUP.LSP" (acet-flatn ss hide))) ;load flatten command function
(command "-layer" "s" "0" "") ;set layer 0 active
(command "-layer" "f" "*" "") ;freeze all layers
(while (setq LAYER (tblnext "LAYER" (null LAYER))) ;check to see if similar layer exists
(if (wcmatch (cdr (assoc 2 LAYER)) "*|SAFETY")
(setq layercheck 1)
); end if
); end while
(if (= layercheck 1) ;if layer exists perform function
(progn
(command "-layer" "t" "*|SAFETY" "")
(setq ss1 (ssget))
(command "copy" "p" "" "0,0,0" "0,0,0")
(acet-flatn ss1 T)
(command ".chprop" "p" "" "la" "AS4685 SAFETY LAYER" "")
); end progn
); end if
(while (setq LAYER2 (tblnext "LAYER" (null LAYER2)))
(if (wcmatch (cdr (assoc 2 LAYER2)) "*|SAFETY FREE SPACE")
(setq layercheck2 1)
); end if
); end while
(if (= layercheck2 1)
(progn
(command "-layer" "f" "*" "")
(command "-layer" "t" "0" "")
(command "-layer" "t" "*|SAFETY FREE SPACE" "")
(setq ss2 (ssget))
(command "copy" "p" "" "0,0,0" "0,0,0")
(acet-flatn ss2 T)
(command ".chprop" "p" "" "la" "AS4685 SAFETY LAYER" "")
(command ".chprop" "p" "" "co" "green" "")
(command "-layer" "f" "*" "")
); end progn
); end if
(while (setq LAYER3 (tblnext "LAYER" (null LAYER3)))
(if (wcmatch (cdr (assoc 2 LAYER3)) "*|SAFETY499")
(setq layercheck3 1)
); end if
); end while
(if (= layercheck3 1)
(progn
(command "-layer" "f" "*" "")
(command "-layer" "t" "0" "")
(command "-layer" "t" "*|SAFETY499" "")
(setq ss3 (ssget))
(command "copy" "p" "" "0,0,0" "0,0,0")
(acet-flatn ss3 T)
(command ".chprop" "p" "" "la" "AS4685 SAFETY LAYER" "")
(command ".chprop" "p" "" "co" "30" "")
); end progn
); end if
(command "-layer" "f" "*safety*" "t" "AS4685 SAFETY LAYER" "")
) ; end c:safetylayers function
The part I have got stuck on is the check with the while loop and using the WCMATCH.
I would like the routine to search and see if a certain layer exists on an XREF, if it does perform the flatten function etc If it doesnt then just go onto the next check. I'm only new to LISP so my programming probably isnt too great but like I said before the routine works great for me if all the 3 layers are present in a drawing (without the need for checking)
Any help would be greatly appreciated
thanks
Craig