โค้ดตัวนี้ เป็น คำสั่ง แทนที่ วัตถุ ที่เลือก อันที่1 ด้วย วัตถุที่เลือกอันที่ 2
ใช้กับ บล้อคได้นะครับ แต่ จุดอ้างอิงการวาง จะถือตาม วัตถุที่เลือก
ลอง เอาไปรันดู ครับ คำสั่ง คือ or1
(defun c:or1() ;object replace
(setq obj1 (car (entsel "\nSelect the object to be replaced: ")))
(setq obj2 (car (entsel "\nSelect the replacement object: ")))
; Check if both objects are valid
(if (and obj1 obj2)
(progn
; Get the properties of the replacement object
(setq obj2Data (entget obj2))
; Get the insertion point of the object to be replaced
(setq obj1Data (entget obj1))
(setq obj1Pos (cdr (assoc 10 obj1Data)))
(setq obj2Pos (cdr (assoc 10 obj2Data)))
(command "copy" obj2 "" obj2Pos obj1Pos)
; Delete the original object
(entdel obj1)
(princ "\nObject replaced successfully.")
)
(princ "\nInvalid selection. Please select valid objects.")
)
(princ)
)