October 21, 2008

Generating the Layers in a Layer Key Style

2/13/2019 - Updated to support ACA 2019.
11/2/2017 - Updated to support ACA 2018.
1/26/2017 - Updated to support ACA 2013 through 2017.
4/3/2011 - Updated to support ACA 2012.
1/27/2010 - Updated to support ACA 2010 & 2011.

Making use of the AecGenerateLayerKey function noted in this previous article, along with the code shown there for loading the appropriate ARX file (updated to work for versions from ADT 3.3 through ACD-A 2009), the AutoLISP code shown below will generate all of the layers associated with the Layer Keys in the current Layer Key Style.
(defun C:LKL (                           ; No arguments.
              / ;_ Local variables:
               flag                      ; Set to T if ARX loaded, nil otherwise.
               sacdvr                    ; String stored in ACADVER system variable.
             ) ;_ End arguments and local variables.
  (setq sacdvr (getvar "ACADVER")) ; Get AutoCAD version.
  ;; ARXload proper ARX function:
  (cond     ; cond A.
    ((= "15.06" sacdvr)
     ;; ARXload ADT3.3 function:
     (if (not (member "aeclayermanagerui30.arx" (arx)))
                                         ; If the ARX file is not currently loaded...
       (progn                            ; ...do the following:
         (prompt "\nARXloading \"aeclayermanagerui30.arx\". ")
                                         ; Display prompt noting file to be loaded.
         (if (arxload "aeclayermanagerui30.arx" nil)
                                         ; If ARX file loads successfully...
           (setq flag T)                        ; ...set flag to T.
           (prompt "\n; error: ARXLOAD failed")
                                         ; ...else display prompt and return nil.
         ) ;_ End if.
       ) ;_ End progn.
       (setq flag T)   ; ...else already loaded, set flag to T.
     ) ;_ End if.
    ) ;_ End condition A1.
    ((= "16.0" sacdvr)
     ;; ARXload ADT2004 function:
     (if (not (member "aeclmgrlisp40.arx" (arx)))
                                         ; If the ARX file is not currently loaded...
       (progn    ; ...do the following:
         (prompt "\nARXloading \"aeclmgrlisp40.arx\". ")
                                         ; Display prompt noting file to be loaded.
         (if (arxload "aeclmgrlisp40.arx" nil)
                                         ; If ARX file loads successfully...
           (setq flag T)  ; ...set flag to T.
           (prompt "\n; error: ARXLOAD failed")
                                         ; ...else display prompt and return nil.
         ) ;_ End if.
       ) ;_ End progn.
       (setq flag T)   ; ...else already loaded, set flag to T.
     ) ;_ End if.
    ) ;_ End condition A2.
    ((= 16.1 (atof sacdvr))
     ;; ARXload ADT2005 function:
     (if (not (member "aeclmgrlisp45.arx" (arx)))
                                         ; If the ARX file is not currently loaded...
       (progn    ; ...do the following:
         (prompt "\nARXloading \"aeclmgrlisp45.arx\". ")
                                         ; Display prompt noting file to be loaded.
         (if (arxload "aeclmgrlisp45.arx" nil)
                                         ; If ARX file loads successfully...
           (setq flag T)  ; ...set flag to T.
           (prompt "\n; error: ARXLOAD failed")
                                         ; ...else display prompt and return nil.
         ) ;_ End if.
       ) ;_ End progn.
       (setq flag T)   ; ...else already loaded, set flag to T.
     ) ;_ End if.
    ) ;_ End condition A3.
    ((= 16.2 (atof sacdvr))
     ;; ARXload ADT2006 function:
     (if (not (member "aeclmgrlisp47.arx" (arx)))
                                         ; If the ARX file is not currently loaded...
       (progn    ; ...do the following:
         (prompt "\nARXloading \"aeclmgrlisp47.arx\". ")
                                         ; Display prompt noting file to be loaded.
         (if (arxload "aeclmgrlisp47.arx" nil)
                                         ; If ARX file loads successfully...
           (setq flag T)  ; ...set flag to T.
           (prompt "\n; error: ARXLOAD failed")
                                         ; ...else display prompt and return nil.
         ) ;_ End if.
       ) ;_ End progn.
       (setq flag T)   ; ...else already loaded, set flag to T.
     ) ;_ End if.
    ) ;_ End condition A4.
    ((= 17.0 (atof sacdvr))
     ;; ARXload ADT2007 function:
     (if (not (member "aeclmgrlisp50.arx" (arx)))
                                         ; If the ARX file is not currently loaded...
       (progn    ; ...do the following:
         (prompt "\nARXloading \"aeclmgrlisp50.arx\". ")
                                         ; Display prompt noting file to be loaded.
         (if (arxload "aeclmgrlisp50.arx" nil)
                                         ; If ARX file loads successfully...
           (setq flag T)  ; ...set flag to T.
           (prompt "\n; error: ARXLOAD failed")
                                         ; ...else display prompt and return nil.
         ) ;_ End if.
       ) ;_ End progn.
       (setq flag T)                     ; ...else already loaded, set flag to T.
     ) ;_ End if.
    ) ;_ End condition A5.
    ((or (= 17.1 (atof sacdvr))
         (= 17.2 (atof sacdvr))
         (= 18.0 (atof sacdvr))
         (= 18.1 (atof sacdvr))
         (= 18.2 (atof sacdvr))
         (= 19.0 (atof sacdvr))
         (= 19.1 (atof sacdvr))
         (= 20.0 (atof sacdvr))
         (= 20.1 (atof sacdvr))
         (= 21.0 (atof sacdvr))
         (= 22.0 (atof sacdvr))
         (= 23.0 (atof sacdvr))
     ) ;_ End or.
     ;; ARXload ACA 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 or 2019 function:
     (if (not (member "aeclmgrlisp.arx" (arx)))
                                         ; If the ARX file is not currently loaded...
       (progn    ; ...do the following:
         (prompt "\nARXloading \"aeclmgrlisp.arx\". ")
                                         ; Display prompt noting file to be loaded.
         (if (arxload "aeclmgrlisp.arx" nil)
                                         ; If ARX file loads successfully...
           (setq flag T)  ; ...set flag to T.
           (prompt "\n; error: ARXLOAD failed")
                                         ; ...else display prompt and return nil.
         ) ;_ End if.
       ) ;_ End progn.
       (setq flag T)   ; ...else already loaded, set flag to T.
     ) ;_ End if.
    ) ;_ End condition A6.
    (T
     (alert
       (strcat
         "Unsupported version of AutoCAD is running."
         "\nACADVER = "
         sacdvr
         "."
       ) ;_ End strcat.
     ) ;_ End alert.
     nil    ; Return nil.
    ) ;_ End condition A7.
  ) ;_ End cond A.
  (if flag
    (progn
      (mapcar 'AecGenerateLayerKey (AecLayerKeyList))
      (alert
        (strcat
          "\nLayers generated from current Layer Key Style. "
          "\nAny previously defined layers not overwritten! "
        ) ;_ End strcat.
      ) ;_ End prompt.
    ) ;_ End progn.
  ) ;_ End if.
  (prin1)
) ;_ End C:LKL.

Keep in mind that if the drawing file in which the LKL command function is run already has one or more layers with the same name as those defined in the current Layer Key Style, those layers will be left "as is" and will not have the layer attributes that are assigned in the Layer Key Style imposed upon them. If Layer Key Overrides are enabled, any Layer Key Overrides that are set will be applied to the generated layer names.

You can find a ZIP file with the "old" AutoLISP code (supports 3.3 through 2009 only) in this thread in the Autodesk AutoCAD® Architecture Discussion Group. 4/3/2011 - A ZIP file with version 1.2 that supports 3.3 through 2012 has been posted to that thread.

1/26/2017: An updated version that supports 3.3 through 2017 has been posted to this thread in the AutoCAD® Architecture Forum.
11/2/2017: An updated version that supports 2018 has been posted to that same thread, in my post dated 11/2/2017 at 6:54 pm United States Eastern Time Zone Daylight Savings Time (your local date and time may vary).
2/13/2019: An updated version that supports 2019 has been posted to that same thread, in my post dated 2/13/2019 at 9:14 pm United States Eastern Time Zone Standard Time (your local date and time may vary).

No comments: