Results 1 to 7 of 7

Thread: freeze all objects in a selection set

  1. #1
    Login to Give a bone
    0

    Default freeze all objects in a selection set

    Hi guys,

    I'm trying to write some lisp that will freeze all the layers of a particular group of objects. E.g. it could go through and find all the dimension objects and freeze the layers they're on. Is there an easy way to freeze the layers of a selection set? Any help appreciated.

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: freeze all objects in a selection set

    Quote Originally Posted by james.randjelovic355350 View Post
    Hi guys,

    I'm trying to write some lisp that will freeze all the layers of a particular group of objects. E.g. it could go through and find all the dimension objects and freeze the layers they're on. Is there an easy way to freeze the layers of a selection set? Any help appreciated.
    What about the built in Layer Freeze command?
    It lets you pick any number of objects (selection set) and it freezes the layers those objects are on.

    -OR- are you trying to use lisp to feed this routine a particular set of layer names (i.e., so you don't have to pick)?
    R.K. McSwain | CAD Panacea |

  3. #3
    Login to Give a bone
    0

    Default Re: freeze all objects in a selection set

    I'd prefer it if I could automate the process so that I didn't have to select the objects myself. Would the best approach be to -

    1) go through every object in a drawing
    2) check if it's a dimension
    3) if it is, store the layer that the object is on in a list
    4) use the freeze command to freeze all those layers

    This was what I originally intended to do but I got stuck determining if the object was a dimension. E.g. to select objects of a particular type you can just do

    (ssget "X" '((0 . "DIMENSION"))))

    but then how do you extract the layer information of each of those objects?

  4. #4
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: freeze all objects in a selection set

    Here is a very basic example. The result is a list in the variable "lst"

    Code:
    (setq sset (ssget "_X" '((0 . "DIMENSION"))) i 0 lst '()) ; Select all the dims
    (if sset                                                  ; if there were any, proceed
      (repeat (sslength sset)                                 ; loop
        (setq item (ssname sset i))                           ; get an item
        (setq data (entget item))                             ; get its data
        (setq layr (cdr (assoc 8 data)))                      ; find the layer
        (setq lst (cons layr lst))                            ; add it to the list
        (setq i (1+ i))                                       ; increment the counter
      )
    )
    R.K. McSwain | CAD Panacea |

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: freeze all objects in a selection set

    Written quickly, this uses the -LAYER Command in order to support both UNDO, and LAYERP functionality.

    Code:
    (vl-load-com)
    
    (defun c:LayFrzDim (/ *error* ss layerName layers oldCmdecho clayer)
    
      (defun *error* (msg)
        (and oldCmdecho (setvar 'cmdecho oldCmdecho))
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
        )
        (princ)
      )
    
      (if (setq ss (ssget "_x" '((0 . "DIMENSION"))))
        (progn
          (vlax-for x (setq ss
                             (vla-get-activeselectionset
                               (vla-get-activedocument (vlax-get-acad-object))
                             )
                      )
            (if
              (not
                (vl-position (setq layername (vla-get-layer x)) layers)
              )
               (setq layers (cons layerName layers))
            )
          )
          (vla-delete ss)
          (setq oldCmdecho (getvar 'cmdecho))
          (setvar 'cmdecho 0)
          (setq clayer (getvar 'clayer))
          (vl-cmdf
            "._-layer"
            "freeze"
            (vl-string-right-trim
              ","
              (apply 'strcat
                     (mapcar (function (lambda (x) (strcat x ",")))
                             (vl-remove-if
                               (function
                                 (lambda (x) (= clayer x))
                               )
                               layers
                             )
                     )
              )
            )
            ""
          )
        )
        (prompt "\n** No dimensions found ** ")
      )
      (*error* nil)
    )
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  6. #6
    Login to Give a bone
    0

    Default Re: freeze all objects in a selection set

    Thanks a lot, those are really helpful. I found another script on these forums and changed it a bit, so that I can move all the dimension objects to a new layer, "dimensions", just in case an architect puts dimensions on the same layer as stuff we don't want frozen. Minor issue, but is there an easy way to combine this code with the script you wrote Renderman? I tried combining it in the obvious way, making one big function which had the input arguments of both, but it didn't seem to work. Here's the code I wanted to add.

    Code:
    (defun C:mvlay ( / sset)
      ; if the layer dimensions does not exist, then create it 
      (if (not (tblsearch "LAYER" "dimensions"))
        (command "._LAYER" "_N" "dimensions" "_C" "5" "dimensions" "" "")
      )
      ; grab everything that's dimensions 
      (setq sset (ssget "_X" '((0 . "DIMENSION"))))
      ; change it to layer dimensions
      (command "._change" sset "" "_P" "_LA" "dimensions" "")
      (princ)
    )

  7. #7
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: freeze all objects in a selection set

    For simplicity, there's no need to create a list of each layer a dimension resides on to feed to the -LAYER Command, if your intention is to move all Dimensions to a "DIMENSIONS" Layer... Instead, consider this simple adaptation of the code you posted:

    Code:
    (defun c:FOO (/ layerName ss)
      
      ;; if the layer dimensions does not exist, then create it 
      (if (not (tblsearch "layer" (setq layerName "DIMENSIONS")))
        (command "._-layer" "new" layerName "color" "5" layerName "" ""
                )
      )
    
      ;; grab everything that's dimensions 
      (if (setq ss (ssget "_x" '((0 . "DIMENSION"))))
        (progn
          
          ;; change it to layer dimensions
          (command "._change" ss "" "properties" "layer" layerName "")
    
          ;; freeze only the dimensions layer
          (command "._-layer" "freeze" layerName "")
        )
        (prompt "\n** No dimensions found ** ")
      )
      (princ)
    )
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. ISOLATEOBJECTS to include the option to Lock, Freeze & VP Freeze
    By Wish List System in forum AutoCAD Wish List
    Replies: 3
    Last Post: 2014-11-08, 06:22 PM
  2. HIDEOBJECTS to include the option to Freeze & VP Freeze
    By Wish List System in forum AutoCAD Wish List
    Replies: 2
    Last Post: 2014-10-28, 02:20 PM
  3. Freeze individual Objects in Viewport
    By chris4455 in forum ACA Wish List
    Replies: 5
    Last Post: 2011-09-28, 06:54 PM
  4. VP Freeze - Objects appear on Save
    By wpeacock in forum AutoCAD General
    Replies: 1
    Last Post: 2011-02-18, 07:03 PM
  5. I Freeze Layers on the Sheet but wont Save what I Freeze
    By jrosario in forum AutoCAD General
    Replies: 3
    Last Post: 2008-02-15, 11:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •