My god that took an incredible amount of hours learning how to write lisps and all the basic syntax but at the end I reached my desired result to a tea! there was hours upon hours of debugging but I managed to pull it of!!!
(defun c:MergeBlocks ()
(setq block1 (car (entsel "\nSelect the first block: ")))
(setq block2 (car (entsel "\nSelect the second block: ")))
(setq basePoint1 (getpoint "\nPick a base point for the first block: "))
(setq basePoint2 (getpoint "\nPick a base point for the second block: "))
(setq blockBasePoint (getpoint "\nPick a base point for the merged block: "))
; Move the second block to align with the first block
(command "_.MOVE" block2 "" basePoint2 basePoint1)
; Get the names of the first and second blocks
(setq block1Name (cdr (assoc 2 (entget block1))))
(setq block2Name (cdr (assoc 2 (entget block2))))
; Create a unique block name by adding 'dynamic'
(setq mergedBlockName (strcat block1Name "_dynamic"))
; Merge the blocks into a new block with the unique name
(command "-BLOCK" mergedBlockName blockBasePoint block1 block2 "")
; Calculate the new basePoint1 relative to the blockBasePoint
(setq gripBasePoint (list (- (car basePoint1) (car blockBasePoint)) (- (cadr basePoint1) (cadr blockBasePoint)) (caddr basePoint1)))
; Go into block editor for the merged block
(command "_BEDIT" mergedBlockName)
; Define a filter for selecting entities by name
(setq block1Filter (list (cons 2 block1Name)))
(setq block2Filter (list (cons 2 block2Name)))
; Select block1 entities by name within the block editor
(setq block1Entity (ssget "_X" block1Filter))
; Select block2 entities by name within the block editor
(setq block2Entity (ssget "_X" block2Filter))
; Set the visibility state grip to newBasePoint1
(command "_bparameter" "_visibility" gripBasePoint "1")
; Create new visibility state "Colored"
(command "_bvstate" "_new" "Colored" "_hide")
(command "_bvstate" "_set" "Colored")
; Set block1 to visibility state "Colored"
(command "_bvshow" block1Entity "" "current")
; Create new visibility state "Colored"
(command "_bvstate" "_new" "Gray" "_hide")
(command "_bvstate" "_set" "Gray")
; Set block1 to visibility state "Colored"
(command "_bvshow" block2Entity "" "current")
; Delete default state
(command "bvstate" "delete" "VisibilityState0")
; Save and exit
(command "_bsave")
(command "_bclose")
; Insert block at the spot of creation
(command "_.INSERT" mergedBlockName blockBasePoint "" "" "")
(princ (strcat "\nBlocks merged into '" mergedBlockName "'."))
)