Results 1 to 3 of 3

Thread: Create layer from block name and move blocks to the new named layer

  1. #1
    Member
    Join Date
    2018-10
    Posts
    5
    Login to Give a bone
    0

    Default Create layer from block name and move blocks to the new named layer

    Can someone help me with a lisp that creates a layer based on block names and then moves the blocks onto the layers that match the block name? I used to have a lisp called BLKNTOBLKL and lost it. All the blocks are currently on Layer 0 and they need to go on layers with their own name.

    Thanks,

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

    Default Re: Create layer from block name and move blocks to the new named layer

    Welcome to AUGI.

    Code:
    (vl-load-com)
    
    (defun c:BLKNTOBLKL (/ *error* acDoc oBlocks oLayers ss name)
    
      (defun *error* (msg)
        (if ss (vla-delete ss))
        (if acDoc (vla-endundomark acDoc))
        (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 (ssget "_:L" '((0 . "INSERT")))
        (progn
          (vla-startundomark
            (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
          )
          (setq oBlocks (vla-get-blocks acDoc))
          (setq oLayers (vla-get-layers acDoc))
          (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
            (setq name (vla-get-effectivename x))
            (if (= :vlax-false (vla-get-isxref (vla-item oBlocks name)))
               (progn
                 (vla-add oLayers name)
                 (vla-put-layer x name)
               )
            )
          )
        )
      )
    
      (*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

  3. #3
    Member
    Join Date
    2018-10
    Posts
    5
    Login to Give a bone
    0

    Default Re: Create layer from block name and move blocks to the new named layer

    I don't know if my previous message had made it through or not, but having my question answered so quickly was amazing. Thank you very much, I really appreciate it.

Similar Threads

  1. 2015: Layer State Pull-Down Control Not Displaying Named Layer State
    By rbdome in forum AutoCAD General
    Replies: 12
    Last Post: 2017-06-10, 11:00 PM
  2. Replies: 8
    Last Post: 2015-05-18, 12:18 AM
  3. Move all Objects within a Block to Layer 0
    By kwong in forum AutoCAD General
    Replies: 16
    Last Post: 2014-03-26, 09:02 PM
  4. All Autocad Products: Easily move all blocks to zero layer
    By Wish List System in forum AutoCAD Wish List
    Replies: 10
    Last Post: 2013-12-11, 03:57 AM
  5. Replies: 7
    Last Post: 2006-10-23, 04:18 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
  •