LISP TO REVERT IN PREVIOUS LAYER

LISP TO REVERT IN PREVIOUS LAYER

rsocampo1827
Participant Participant
1,271 Views
2 Replies
Message 1 of 3

LISP TO REVERT IN PREVIOUS LAYER

rsocampo1827
Participant
Participant

Hi,

Please help me to improve below lisp.

The lisp works to create new layer for new dimension and revert back to previous layer.

But once you cancelled the command it wont back to previous layer instead it stay to the new layer created.

Any suggestion to return it to previous layer even after cancelling the command?

Thanks.

 

(defun c:dimstraight()
(command ".layer" "M" "dimension" "C" "white" "dimension" "L" "continuous" "dimension" ""
".dimlinear" pause pause pause ".layerp")
(princ)
)

0 Likes
Accepted solutions (2)
1,272 Views
2 Replies
Replies (2)
Message 2 of 3

dlanorh
Advisor
Advisor
Accepted solution

You need a local error trap to reset. Try this :

 

(defun c:dimstraight( / *error* clay cme)
(defun *error* ( msg )
(setvar 'clayer clay)
(if cme (setvar 'cmdecho cme))
(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
(princ)
);end_*error*_defun

(setq clay (getvar 'clayer))
(cond ( (/= 0 (getvar 'cmdecho)) (setq cme (getvar 'cmdecho)) (setvar 'cmdecho 0)))

(command ".layer" "M" "dimension" "C" "white" "dimension" "L" "continuous" "dimension" ""
".dimlinear" pause pause pause ".layerp")

(if cme (setvar 'cmdecho cme))
(princ)
)

I am not one of the robots you're looking for

Message 3 of 3

ВeekeeCZ
Consultant
Consultant
Accepted solution

I would not recommend using LAYERP command. It might happen that dimension layer is already current and in that case your "-LAYER Make" makes no difference in layer state (which supposed to be returned by layerp)... so then LAYERP returns whatever previous change you 've done before. It could be just a previous current layer, but it also could be some change in layer properties... eg. color... So changing 'clayer sysvar to its previous value would be more predictable.

 

Also made little change to DIMLINEAR command to give you more freedom in usage...

 

(defun c:DimStraight( / *error* clay)

  (defun *error* ( msg )
    (setvar 'clayer clay)
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
    (princ)
  )

  (setq clay (getvar 'clayer))
  
  (command "_.LAYER" "_T" "dimension" "M" "dimension" "C" "white" "dimension" "")
  (command-s ".DIMLINEAR")

  (setvar 'clayer clay)
  (princ)
)