Jump to content

Recommended Posts

Posted

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))

Posted

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.

Posted

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.

Posted

Use the not function to negate the test expression, i.e.:

 

(if (not (tblsearch "LTYPE" "Your Linetype"))
    ... do something ...
)

Posted

Traci Dennis,

 

Please edit your original post to include code tags for the code.

Posted

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))

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...