Traci Dennis Posted September 20, 2012 Posted September 20, 2012 This routine crashes if the layer "electplan" already exists. How do I ad an if or cond statement. The routine will take a line and convert it to a pline. (defun c:EPL2 (/ taa taa1 taa2 ds) (SETQ DS (GETVAR "DIMSCALE")) (setvar "cmdecho" 0) (setq oldlayer (getvar "clayer")) (setq taa (getvar "dimscale")) (setq taa1 (* 0.035 taa)) (command "-layer" "m" "E-POWR-COND" "c" "54" "" "") ;;;;;;;;;crashed if linetype already exists;;;;;;;;;;;;;;;;;;;;;;; (command "-linetype" "l" "electplan" "P:/CAD dept/AutoCAD Support Files/Special Ltype/TristarCustom.lin" "") ;;;;;;;;;crashed if linetype already exists;;;;;;;;;;;;;;;;;;;;;;; (prompt "Select entities for pline") (SETQ SEL (SSGET)) (setq PR (ssget "p")) (COMMAND "PEDIT" PR "Y" "W" TAA1 "J" SEL "" "lt" "on" "") (setq PR2 (ssget "L")) (COMMAND "CHANGE" PR2 "" "P" "LA" "E-POWR-COND" "C" "2" "LT" "ELECTplan" "") (setvar "clayer" oldlayer) (setvar "cmdecho" 1) (princ)) Quote
Lee Mac Posted September 20, 2012 Posted September 20, 2012 Welcome to the forum Traci You can use the tblsearch function to test either the Layer or Linetype Tables in the drawing, e.g.: (if (tblsearch "LAYER" "Your Layer") (princ "\nLayer already exists.") (princ "\nLayer doesn't exist.") ) (if (tblsearch "LTYPE" "Your Linetype") (princ "\nLinetype already exists.") (princ "\nLinetype doesn't exist.") ) PS: Formatting code in your posts. Quote
Traci Dennis Posted September 20, 2012 Author Posted September 20, 2012 Thanks, If the ltype exists I want the routine to ignore the load linetype line. How do I do that? Welcome to the forum Traci You can use the tblsearch function to test either the Layer or Linetype Tables in the drawing, e.g.: (if (tblsearch "LAYER" "Your Layer") (princ "\nLayer already exists.") (princ "\nLayer doesn't exist.") ) (if (tblsearch "LTYPE" "Your Linetype") (princ "\nLinetype already exists.") (princ "\nLinetype doesn't exist.") ) PS: Formatting code in your posts. Quote
Lee Mac Posted September 20, 2012 Posted September 20, 2012 Use the not function to negate the test expression, i.e.: (if (not (tblsearch "LTYPE" "Your Linetype")) ... do something ... ) Quote
SLW210 Posted September 20, 2012 Posted September 20, 2012 Traci Dennis, Please edit your original post to include code tags for the code. Quote
Traci Dennis Posted September 21, 2012 Author Posted September 21, 2012 The if not statement worked. Thanks This routine crashes if the layer "electplan" already exists. How do I ad an if or cond statement. The routine will take a line and convert it to a pline. (defun c:EPL2 (/ taa taa1 taa2 ds) (SETQ DS (GETVAR "DIMSCALE")) (setvar "cmdecho" 0) (setq oldlayer (getvar "clayer")) (setq taa (getvar "dimscale")) (setq taa1 (* 0.035 taa)) (command "-layer" "m" "E-POWR-COND" "c" "54" "" "") ;;;;;;;;;crashed if linetype already exists;;;;;;;;;;;;;;;;;;;;;;; (command "-linetype" "l" "electplan" "P:/CAD dept/AutoCAD Support Files/Special Ltype/TristarCustom.lin" "") ;;;;;;;;;crashed if linetype already exists;;;;;;;;;;;;;;;;;;;;;;; (prompt "Select entities for pline") (SETQ SEL (SSGET)) (setq PR (ssget "p")) (COMMAND "PEDIT" PR "Y" "W" TAA1 "J" SEL "" "lt" "on" "") (setq PR2 (ssget "L")) (COMMAND "CHANGE" PR2 "" "P" "LA" "E-POWR-COND" "C" "2" "LT" "ELECTplan" "") (setvar "clayer" oldlayer) (setvar "cmdecho" 1) (princ)) 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.