Read attribute value, create string and write into a different block as attribute value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i've been struggling with a code. the general idea is to create a string using the block name, and 1 or 2 attribute values (if the second doesnot exist, skip)
Here's the code
(defun c:Rced ()
(while t
;; Select first block
(setq bloq1 (entsel "\nSelect the first block: "))
(if (not bloq1) (exit))
(setq bloq1 (car bloq1))
(setq bloqD1 (entget bloq1))
;; Get name of first block and store as IN1
(setq IN1 (cdr (assoc 2 bloqD1)))
;; Initialize attribute variables
(setq IN2 "" IN3 "" CIR "")
(setq atrb (entnext bloq1))
(while atrb
(setq atrbD (entget atrb))
(cond
((eq (cdr (assoc 2 atrbD)) "Control") (setq IN2 (cdr (assoc 1 atrbD))))
((eq (cdr (assoc 2 atrbD)) "Consecutivo") (setq IN3 (cdr (assoc 1 atrbD))))
((eq (cdr (assoc 2 atrbD)) "Circuito") (setq CIR (cdr (assoc 1 atrbD))))
)
(setq atrb (entnext atrb))
)
;; Select second block
(setq bloq2 (entsel "\nSelect the second block: "))
(if (not bloq2) (exit))
(setq bloq2 (car bloq2))
(setq bloqD2 (entget bloq2))
;; Get name of second block and store as FI1
(setq FI1 (cdr (assoc 2 bloqD2)))
;; Initialize attribute variables
(setq FI2 "" FI3 "")
(setq atrb (entnext bloq2))
(while atrb
(setq atrbD (entget atrb))
(cond
((eq (cdr (assoc 2 atrbD)) "Control") (setq FI2 (cdr (assoc 1 atrbD))))
((eq (cdr (assoc 2 atrbD)) "Consecutivo") (setq FI3 (cdr (assoc 1 atrbD))))
)
(setq atrb (entnext atrb))
)
;; Create text string INI
(setq INI (strcat IN1 " " IN2))
(if (not (equal IN3 "")) (setq INI (strcat INI " " IN3)))
;; Create text string SFI
(setq SFI (strcat FI1 " " FI2))
(if (not (equal FI3 "")) (setq SFI (strcat SFI " " FI3)))
;; Select destination block
(setq Cedula (entsel "\nSelect the destination block: "))
(if (not Cedula) (exit))
(setq Cedula (car Cedula))
(setq CedulaD (entget Cedula))
;; Apply values to destination block
(setq atrb (entnext Cedula))
(while atrb
(setq atrbD (entget atrb))
(cond
((and (eq (cdr (assoc 2 atrbD)) "SI") (not (equal INI ""))) (entmod (subst (cons 1 INI) (assoc 1 atrbD) atrbD)))
((and (eq (cdr (assoc 2 atrbD)) "SF") (not (equal SFI ""))) (entmod (subst (cons 1 SFI) (assoc 1 atrbD) atrbD)))
((and (eq (cdr (assoc 2 atrbD)) "Circuito") (not (equal CIR ""))) (entmod (subst (cons 1 CIR) (assoc 1 atrbD) atrbD)))
)
(setq atrb (entnext atrb))
)
)
(princ)
)