;select the block to copy
;locate to new location with DUCS
;
;It gets the block name and layer and locates using the face.
; yes/no to continue
;4/5/26



(defun c:copyblock (/ ent blkName blklay conblk)
  (setq curlay (getvar "clayer")
        ent (car (entsel "\nSelect source block in drawing: "))
  )
  (if (and ent (= (cdr (assoc 0 (entget ent))) "INSERT"))
    (progn
      (setq blkName (cdr (assoc 2 (entget ent)))
            blklay (cdr (assoc 8 (entget ent)))
            conblk "Y"
      )
      (setvar "clayer" blklay)
      (command "_.-insert" blkName pause "1" "1" "0")
      (while (= (ukword 0 "Y N" "Continue placing block Y/N" conblk) "Y") 
        (command "_.-insert" blkName pause "1" "1" "0")
      )
      (setvar "clayer" curlay)
    )
    (princ "\nError: Selected object is not a block.")
    
  )
  (princ)
)
(defun ukword (bit kwd msg def / msg bit inp)
    (if def
       (setq msg (strcat "\n" msg " <" def "> ")
             bit (* 2 (fix (/ bit 2))))
       (setq msg (strcat "\n" msg ))      
    )
    (if (and def(> bit 0)) (setq bit (1- bit)))
    (initget bit kwd)
    (setq inp (getkword msg))
    (if inp inp def)
)


