Set layer at end of lisp

Set layer at end of lisp

bemmer7MZ3G
Contributor Contributor
437 Views
3 Replies
Message 1 of 4

Set layer at end of lisp

bemmer7MZ3G
Contributor
Contributor

I have this lisp file that when I specify a maximum distance and select two points, it will print points divided on a layer called "Rivet Hole". One thing I was trying to do was get the program when it finishes to set the layer to a different layer called "Text", but I am having some trouble figuring out how to do that.

0 Likes
Accepted solutions (1)
438 Views
3 Replies
Replies (3)
Message 2 of 4

ec-cad
Collaborator
Collaborator
Accepted solution

You could 'save' the existing current layer.. e.g.

(setq olay (getvar 'clayer))

Then reset it on exit .. e.g.

(setvar 'clayer olay)

For your request to set to Layer "Text" on exit, try following.

(defun C:DDP (/ cc1 cc2 range spcs spc)
  ; = DIVide Distance [not object] using Points, at user-specified Maximum spacing
(command "-layer" "s" "Rivet Hole" "")
  (initget (if *DIVDPmax* 6 7)); no zero, no negative, no Enter on first use
  (setq
    *DIVDPmax* ; global variable with routine-specific name
    (cond
      ( (getdist ; returns nil on Enter when permitted
          (strcat
            "\nMaximum Point spacing"
            (if *DIVDPmax* (strcat " <" (rtos *DIVDPmax*) ">") "")
            ": "
          ); strcat
        ); getdist
      ); User-input condition
      (*DIVDPmax*); prior value if present, on Enter
    ); cond & *DIVDPmax*
    p1 (getpoint "\nOne end of range: ")
    p2 (getpoint "\nOther end: ")
    range (distance p1 p2)
    spcs (+ (fix (/ range *DIVDPmax*)) (if (equal (rem range *DIVDPmax*) 0 1e-4) 0 1))
    spc (/ range spcs)
  ); setq
  (setvar 'lastpoint p1); kind of interesting that that's allowed...
  (repeat (1- spcs)
    (command "_.point" "_none" (polar (getvar 'lastpoint) (angle p1 p2) spc))
  ); repeat
;; Add the next 2 lines
 (command "_.layer" "_M" "TEXT" ""); Case no Layer Text exists (nil if exists)
 (command "_.layer" "_S" "TEXT" ""); Set to Layer Text
); defun

ECCAD

0 Likes
Message 3 of 4

Kent1Cooper
Consultant
Consultant

[Line 30 is extraneous.  The Make option makes the Layer current in the process, so there no need for the Set option after Making it.]

Kent Cooper, AIA
0 Likes
Message 4 of 4

ec-cad
Collaborator
Collaborator

Well, I know that, but it may be more 'clear' what's happening with (2) calls.

Geez

0 Likes