Below are the changes I made:
I'm not sure if you only want to select 1 Block at a time but if you do then change the following:
(setq ss (ssget '((0 . "INSERT") (2 . "POINTBORNE"))))
To this:
; filter selection to only 1 block
(setq ss (ssget "_+.:E:S" '((0 . "INSERT") (2 . "POINTBORNE"))))
If selected item then first things to do are the following:
(setq ss (ssname ss 0)) ; get entity of first/only item in selection set
(setq attreq (getvar"attreq")) ; save current setting
(setvar "attreq" 0) ; set attribute value prompt off
Then instead of these lines of code that doesn't work:
; (setq nbornier (entget (car ss) '("NBORNIER")))
; (setq nbornier (cdr (assoc 1 nbornier)))
; (setq pborne (entget (car ss) '("PBORNE")))
; (setq pborne (cdr (assoc 1 pborne)))
; (setq nfils (entget (car ss) '("NFILS")))
; (setq nfils (cdr (assoc 1 nfils)))
; (setq ptborne (entget (car ss) '("POINTBORNE")))
; (setq ptborne (cdr (assoc 10 ptborne)))
Use the following:
(setq nbornier (getpropertyvalue ss "NBORNIER")) ; get block attribute values
(setq pborne (getpropertyvalue ss "PBORNE"))
(setq nfils (getpropertyvalue ss "NFILS"))
(setq ptborne (cdr (assoc 10 (entget ss)))) ; get block's insertion point
Instead of the following to insert new block & fill out attributes:
;; Insertion du bloc "BORNIER"
; (command "INSERT" "BORNIER" ptborne "1" "1" "0" "")
; (setq bornier (entlast))
; (command "-ATTEDIT" "1" bornier "" "ALL" nbornier "")
Use the following:
;; Insertion du bloc "BORNIER"
(command "_.INSERT" "BORNIER" ptborne "1" "1" "0") ; insert block using selected block's insertion point
(setpropertyvalue (entlast) "NBORNIER" nbornier) ; place value into inserted block's attribute
Then for inserting the next block instead of these lines of code:
;; Insertion des blocs "BORNE"
; (setq borne_pt ptborne)
; (repeat (length ss)
; (command "INSERT" "BORNE" borne_pt "1" "1" "0" "")
; (setq borne (entlast))
; (command "-ATTEDIT" "1" borne "" "NFILS" nfils "")
; (command "-ATTEDIT" "1" borne "" "PBORNE" pborne "")
; (setq borne_pt (mapcar '+ borne_pt '(10 0))) ;; Décalage horizontal de 10 unités
; )
Use the following:
;; Insertion des blocs "BORNE"
(command "_.INSERT" "BORNE" ptborne "1" "1" "0") ; insert block using selected block's insertion point
(setpropertyvalue (entlast) "PBORNE" pborne) ; place value into inserted block's attribute
(setpropertyvalue (entlast) "NFILS" nfils) ; place value into inserted block's attribute
Now I'm not sure what you want to do with this...do you want to move this newly inserted block 10 units to the right?
; (setq borne_pt (mapcar '+ borne_pt '(10 0))) ;; Décalage horizontal de 10 unités
After all done then restore original setting:
(setvar "attreq" attreq) ; restore original setting