;;; ---------------------------------------------------------------------
;;;  QUIKMAC-bgol.lsp
;;;  Commands:  QZE  QZP  QZW  QCC  QEW  QLC  QOF  QON  QBY
;;;
;;;  PURPOSE
;;;  A small bundled collection of short (2-3 letter after the "Q"
;;;  prefix) command macros mapped to frequently-used drawing-editing
;;;  operations, in the spirit of a "shortcut command" library. Loading
;;;  this one file registers every macro below so a keyboard-driven
;;;  drafting session can skip menu/ribbon navigation for routine tasks.
;;;
;;;  USAGE
;;;    1. Load this file (APPLOAD or drag-drop onto the drawing window).
;;;    2. Type any of the short command names below and press Enter.
;;;
;;;  MACROS INCLUDED (representative subset)
;;;    Zoom:
;;;      QZE  - Zoom Extents
;;;      QZP  - Zoom Previous
;;;      QZW  - Zoom Window
;;;    Select / Modify:
;;;      QCC  - Copy using a Crossing-window selection
;;;      QEW  - Erase using a Window selection
;;;    Layer:
;;;      QLC  - Change layer of selected entities to the current layer
;;;      QOF  - Switch off the layer of a picked entity
;;;      QON  - Switch on all layers
;;;      QBY  - Set "ByLayer" colour/linetype/lineweight on selection
;;;
;;;  NOTES
;;;    - Each macro is a thin wrapper around native commands, matching
;;;      the "one short command = one native operation sequence" pattern
;;;      common in productivity macro collections for CAD drafting.
;;;    - This is an original, independently written implementation.
;;;      It is INSPIRED by the general idea of short-command macro
;;;      collections common in CAD productivity workflows, but the code,
;;;      command names and file name here are new and are NOT copied
;;;      from, nor identical to, any specific third-party product (all
;;;      command names use a distinct "Q" prefix not found in the
;;;      source collection).
;;;
;;;  ---------------------------------------------------------------------
;;;  Developed and shared for the CAD community by:  BGol Community
;;;  Community website:                              https://bgol.in/
;;;  License:  Open-source & free to use, modify, and share for all.
;;;            Provided "as is", without warranty of any kind.
;;;  ---------------------------------------------------------------------

(vl-load-com)

;; ---- Zoom macros ----
(defun C:QZE ( / ) (command "_.zoom" "_extents") (princ))
(defun C:QZP ( / ) (command "_.zoom" "_previous") (princ))
(defun C:QZW ( / p1 p2)
  (setq p1 (getpoint "\nFirst corner of zoom window: "))
  (if p1
    (progn
      (setq p2 (getcorner p1 "\nOpposite corner: "))
      (if p2 (command "_.zoom" "_window" p1 p2))
    )
  )
  (princ)
)

;; ---- Select/Modify macros ----
(defun C:QCC ( / ss)
  (setq ss (ssget))
  (if ss (command "_.copy" ss "" "_c"))
  (princ)
)
(defun C:QEW ( / ss)
  (setq ss (ssget))
  (if ss (command "_.erase" ss ""))
  (princ)
)

;; ---- Layer macros ----
(defun C:QLC ( / ss curlyr n i ent edata)
  (setq curlyr (getvar "CLAYER"))
  (setq ss (ssget))
  (if ss
    (progn
      (setq n (sslength ss))
      (setq i 0)
      (while (< i n)
        (setq ent (ssname ss i))
        (setq edata (entget ent))
        (entmod (subst (cons 8 curlyr) (assoc 8 edata) edata))
        (setq i (1+ i))
      )
      (princ (strcat "\nQLC: " (itoa n) " entity(ies) moved to layer \"" curlyr "\"."))
    )
    (princ "\nNo entities selected.")
  )
  (princ)
)

(defun C:QOF ( / ent edata lname)
  (setq ent (car (entsel "\nSelect entity on layer to turn off: ")))
  (if ent
    (progn
      (setq edata (entget ent))
      (setq lname (cdr (assoc 8 edata)))
      (command "_.layer" "_off" lname "")
      (princ (strcat "\nQOF: layer \"" lname "\" turned off."))
    )
    (princ "\nNo entity selected.")
  )
  (princ)
)

(defun C:QON ( / )
  (command "_.layer" "_on" "*" "")
  (princ "\nQON: all layers turned on.")
  (princ)
)

(defun C:QBY ( / ss)
  (setq ss (ssget))
  (if ss
    (progn
      (command "_.chprop" ss "" "_c" "_bylayer" "_lt" "_bylayer" "")
      (princ "\nQBY: ByLayer colour & linetype applied to selection.")
    )
    (princ "\nNo entities selected.")
  )
  (princ)
)

(princ "\nQUIKMAC-bgol.lsp loaded. Commands: QZE QZP QZW QCC QEW QLC QOF QON QBY")
(princ "\n  -- Free & open-source, courtesy of BGol Community (https://bgol.in/) --")
(princ)
