Jump to content

Recommended Posts

Posted

I need a lisp routine to freeze currently selected objects on multi different layers at once.
Instead to run LAYFRZ command and pick them one by one, I would like to select them
first (like window selection) and then run single command to freeze them and so theirs layers all at once.
Any Ideas?

Posted
(defun c:Test (/ i s c e y l b k)
  ;; Tharwat - Date: 24.Mar.2021			;;
  ;; Freeze layers of selected objects			;;
  ;; NOTE: excludes if any of the layers is current.	;;
  (and (princ "\nSelect objects to Freeze their layers : ")
       (setq c (getvar 'CLAYER)
             i -1
             s (ssget '((0 . "~VIEWPORT")))
       )
       (while (setq i (1+ i)
                    e (ssname s i)
              )
         (or (member (setq y (cdr (assoc 8 (entget e)))) l)
             (= c y)
             (and (setq l (cons y l)
                        b (entget (tblobjname "LAYER" y))
                        k (assoc 70 b)
                  )
                  (entmod (subst (cons 70 (1+ (cdr k))) k b))
             )
         )
       )
  )
  (princ)
)

 

  • Like 2
Posted

By the way, could you know the answer to my old post?

 

  • 4 years later...
Posted (edited)
On 3/23/2021 at 9:56 PM, Tharwat said:
(defun c:Test (/ i s c e y l b k)
  ;; Tharwat - Date: 24.Mar.2021			;;
  ;; Freeze layers of selected objects			;;
  ;; NOTE: excludes if any of the layers is current.	;;
  (and (princ "\nSelect objects to Freeze their layers : ")
       (setq c (getvar 'CLAYER)
             i -1
             s (ssget '((0 . "~VIEWPORT")))
       )
       (while (setq i (1+ i)
                    e (ssname s i)
              )
         (or (member (setq y (cdr (assoc 8 (entget e)))) l)
             (= c y)
             (and (setq l (cons y l)
                        b (entget (tblobjname "LAYER" y))
                        k (assoc 70 b)
                  )
                  (entmod (subst (cons 70 (1+ (cdr k))) k b))
             )
         )
       )
  )
  (princ)
)

 

It is brilliant, thank you Tharwat! @Tharwat I know this one is 4 years old, but pure gold! Could this lisp perform in viewport space a Viewport Freeze instead of regular Freeze? Best regards!!

Edited by mikitari
Posted (edited)

Hello, I asked ChatGPT for help, please excuse Tharwat, apparently it nailed it at first shot.

(defun c:TestVPFreeze (/ i s c e y l)
  ;; Tharwat - Date: 24.Mar.2021					;;
  ;; Freeze layers of selected objects				;;
  ;; ChatGPT - Modified for VP Freeze - 20.May.2025	;;
  ;; VP Freeze layers of selected objects in current layout viewport
  ;; NOTE: excludes if any of the layers is current.
  (and
    (princ "\nSelect objects to VP Freeze their layers in the current viewport: ")
    (setq c (getvar 'CLAYER)
          i -1
          s (ssget '((0 . "~VIEWPORT")))
    )
    (while (setq i (1+ i)
                 e (ssname s i))
      (setq y (cdr (assoc 8 (entget e)))) ; Get layer name
      (if (and (/= c y) (not (member y l))) ; Not current and not already processed
        (progn
          (setq l (cons y l)) ; Track processed layers
          ;; Use VPLAYER command to freeze in current viewport
          (command "_.vplayer" "_freeze" y "" "")
        )
      )
    )
  )
  (princ)
)

Notes from Chatgpt:

This uses (command "_.vplayer" "freeze" ...) for viewport-specific freezing.

Ensure the user is inside a layout viewport (i.e., paper space, double-clicked into a viewport).

Skips the current layer and avoids freezing the same layer multiple times.

Edited by mikitari

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