layer add lock lsp

layer add lock lsp

Anonymous
Not applicable
1,899 Views
5 Replies
Message 1 of 6

layer add lock lsp

Anonymous
Not applicable

hello. always I really thank you everyone. when I need some help, many help me. thank you

I need a lsp to add layer lock. some help me at this time.

 

this lsp is select block and layer off lsp

I often use this command -(defun C:LOP ()   (defun C:LOPN ()  - LOP, LOPN are good lsp - block layer off in select block

and

I want to add command -  (defun C:LOK ()  (defun C:LOPK () - layer lock

 

some help, thank you all,


;;  LayerQuellPick.lsp [command names: LOP, LOPN, LFP, LFPN]
;;  To "Quell" [turn Off or Freeze] Layers of Picked objects or Picked Nested objects.
;;  If selected object is on current Layer, changes current Layer to first one in Layer table
;;    that is neither off/frozen nor Xref-dependent nor that of selected object, and notifies
;;    User of new current Layer.  [Starting current Layer remains shown in Layer Properties
;;    Toolbar pull-down until command is terminated, but if Properties box is up, changes
;;    of current Layer are reflected immediately in its General section, Layer slot.]
;;  If selected nested object is part of a Block/Xref, and on Layer 0 within that reference's
;;    definition, turns off or freezes not Layer 0, but the deepest-nested non-0 Layer on which
;;    that reference or a containing reference is inserted, i.e. where nested object "appears."
;;  [Quirk I haven't found a way around yet: if Layer 0 is off or frozen, things on Defpoints
;;    Layer, even if visible, can't be selected; that Layer can't be quelled while Layer 0 is
;;    (using these commands, though it can be via Layer Manager or Toolbar).]
;;  Kent Cooper, November 2011

(defun C:LOP (); = Layer Off by Picking object(s) [top-level]
    (LQC entsel "" "turn Off" "_off")
)
(defun C:LOPN (); = Layer Off by Picking object(s) or Nested object(s)
    (LQC nentsel "/nested object" "turn Off" "_off")
)
(defun C:LFP (); = Layer Freeze by Picking object(s) [top-level]
    (LQC entsel "" "Freeze" "_freeze")
)
(defun C:LFPN (); = Layer Freeze by picking object(s) or Nested object(s)
    (LQC nentsel "/nested object" "Freeze" "_freeze")
)
(defun LQC (func pr1 pr2 opt / *error* cmde ent edata layq nestlist nlayq ldata layc)
  ; = Layer Quell with Current layer changed if necessary
  (defun *error* (errmsg); don't display error message if cancelled with Esc
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); end if
    (setvar 'cmdecho cmde)
  ); defun - *error*
  (setq cmde (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (while
    (and
      (not ; to return T when (while) loop below is satisfied
        (while
          (and
            (not (setq ent (func (strcat "\nSelect object" pr1 " on Layer to " pr2 ": "))))
            (= (getvar 'errno) 7)
          ); and
          (prompt "\nNothing selected -- try again.")
        ); end while
      ); not
      ent ; something selected
    ); and
    (setq
      edata (entget (car ent))
      layq ; = LAYer to Quell [turn Off or Freeze]
        (if (= (cdr (assoc 8 edata)) "0"); on Layer 0
          (cond ; then
            ((> (length ent) 2); nested entity [other than Attribute] in Block/Xref
              (setq nestlist (last (nentselp (cadr ent)))); stack of references nested in
              (while
                (and
                  nestlist ; still nesting level(s) remaining
                  (= (setq nlayq (cdr (assoc 8 (entget (car nestlist))))) "0"); = Nested [non-0] LAYer to Quell
                ); and
                (setq nestlist (cdr nestlist)); move up a level if present
              ); while
              nlayq
                ; lowest-level non-0 Layer of nested or containing reference(s); 0 if that all the way up
            ); non-Attribute nested entity on Layer 0 condition
            ((= (cdr (assoc 0 edata)) "ATTRIB"); Attribute in Block
              (cdr (assoc 8 (entget (cdr (assoc 330 edata))))); Block's Layer
            ); Attribute on Layer 0 condition
            ("0"); none-of-the-above condition
          ); cond - then
          (cdr (assoc 8 edata)); else - Layer of entity/nested entity
        ); if & layq
    ); setq
    (if (= layq (getvar 'clayer)); selected object is on current Layer - find another
      (progn ; then
        (while ; look for Layer that's on, thawed, non-Xref-dependent, not selected object's
          (and
            (setq ldata (tblnext "layer" (not ldata))); still Layer(s) left in table
              ; nil if it gets to end of table without finding qualifying Layer
            (or
              (=
                (setq layc (cdr (assoc 2 ldata))); = LAYer to [possibly] make Current
                layq ; selected object's Layer
              ); =
              (minusp (cdr (assoc 62 ldata))); off [could be made current, but...]
              (= (logand (cdr (assoc 70 ldata)) 1) 1); frozen [can't be made current]
              (wcmatch layc "*|*"); Xref-dependent [can't be made current]
            ); or
          ); and
        ); while
        (if ldata ; found a qualifying Layer
          (setvar 'clayer layc); then - set it current
          (progn ; else - no qualifying Layer
            (alert "No available Layer to make current\nin place of selected object's Layer.")
            (quit)
          ); progn
        ); if
      ); progn
    ); if
    (command "_.layer" opt layq ""); turn off or freeze Layer of selected object
    (if ldata (prompt (strcat "\nCurrent Layer has been changed to " layc ".")))
  ); while
  (setvar 'cmdecho cmde)
  (princ)
); defun - LQC

 

0 Likes
Accepted solutions (2)
1,900 Views
5 Replies
Replies (5)
Message 2 of 6

m_badran
Advocate
Advocate

Hi,you can lock any layer by LAYLCK command already built in cad.

HTH

0 Likes
Message 3 of 6

john.uhden
Mentor
Mentor

I would think, with your style, that locking would be just like offing except you would use the command "_Lock."

John F. Uhden

0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

Just add these in there somewhere:

 

(defun C:LLP (); = Layer Lock by Picking object(s) [top-level]
    (LQC entsel "" "Lock" "_lock")
)
(defun C:LLPN (); = Layer Lock by Picking object(s) or Nested object(s)
    (LQC nentsel "/nested object" "Lock" "_lock")
)

 

I used different names than you suggest.  The P and N in the command names are for "by Picking" and "Nested," both of which would also apply in a Layer-locking command.  The other command names have a second letter O for Off or F for Freeze, so I made these equivalent with the L for Lock.

 

EDIT:  Technically, you can draw on a locked Layer, so it wouldn't be necessary for it to change the current Layer if you pick something on it, as it is with turning Off and Freezing.  If you want it to lock the current Layer when something on it is picked but leave it current, that could be accounted for.

Kent Cooper, AIA
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@mostafabadran wrote:

Hi,you can lock any layer by LAYLCK command already built in cad.


Just so you know, that command didn't exist in the version under which LayerQuellPick.lsp was written.  Also, LAYLCK only gives you one pick, so if you want to lock more than one Layer that way, you need to recall the command for each one -- mine let you keep picking more things and locking more Layers, as long as you want to keep going [until you run out of Layers], in one running of the command.  And LAYLCK doesn't have Nested-object capability.

Kent Cooper, AIA
Message 6 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@Kent1Cooper wrote:

Just add these in there somewhere:

 

(defun C:LLP (); = Layer Lock by Picking object(s) [top-level]
    (LQC entsel "" "Lock" "_lock")
)
(defun C:LLPN (); = Layer Lock by Picking object(s) or Nested object(s)
    (LQC nentsel "/nested object" "Lock" "_lock")
)

.....


Here's a complete file incorporating those additions, and with its commentary adjusted to include things about them.

Kent Cooper, AIA