Tại bảng Properties, khi người dùng thay đổi thuộc tính từ TextOverwrite sang Measurement hoặc ngược lại của textDim thì biểu thức field đã gán cho text có sẵn sẽ không update được vì nó chỉ update giá trị của thuộc tính đã định sẵn trong biểu thức field, không update việc thay đổi thuộc tính. Lisp sau Thiep đã update, cho trường này. Tuy nhiên, sau khi thay đổi thuộc tính từ TextOverwrite sang Measurement hoặc ngược lại, các bạn phải đánh lệnh RE1 thay cho lệnh RE để tái tạo tạo màn hình. Sau đó, trên màn hình các bạn chỉnh sửa giá trị textDim (TextOverwrite)  hoặc co giản dim (Measurement) thì vẫn dùng lệnh RE để update giá trị thuộc tính thay đổi. Chú ý: Lệnh Re1, chỉ hoạt động khi bản vẽ dùng lệnh fdt1 của lisp, khi đó giá trị biến trong lisp chưa bị mất đi. Còn khi người dùng tắt bản vẽ và mở lại, lệnh Re1 không thực hiện được nữa, khi đó phải tải lisp dưới đây và dùng lệnh fdt1 trở lại.   ;;; LISP FIELD SUM DIMENSIONS, TEXTs, MTEXTs, LENGTHs, AREAs, CIRCUMFERENCEs TO A TEXT ;;; by TrânThiêp 04/2020 ;;; 09188411230 ;;;======================================================= ;;; command fdt1 : field sum DIMENSIONS ;;; command fdt2 : field sum TEXTs, MTEXTs ;;; command fdt3 : field sum LENGTHs ;;; command fdt4 : field sum AREAs ;;; command fdt5 : field sum CIRCUMFERENCEs ;;; command re1 : update field sum DIMENSIONs when change properti TextOverride dim to Measurement dim or reverse ;;; (defun DXF (code en) (cdr (assoc code (entget en)))) (vl-load-com) (defun *error* (msg) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")) ) (acet-sysvar-restore) (command "undo" "en") (princ) ) ;;;===========================================================================1: sum DIMENSIONs ========= (defun c:fdt1 (/ ss ent_T) (command "undo" "be") (acet-sysvar-set '("cmdecho" 0 "osmode" 0)) (acet-ui-status "Select DIMENSIONs FOR GET SUM" "Prompt") (setq ss (ssget '((0 . "DIMENSION")))) (acet-ui-status) (while (OR (NOT (setq ent_T (car (entsel "\nPick a Text object for set sum dimensions" ) ) ) ) (NOT (eq (cdr (assoc 0 (entget ent_T))) "TEXT")) ) (prompt "\nPick not right TEXT object, please pick again") ) (setq Obj_Text_thiep (vlax-ename->vla-object ent_T)) (if (null (setq prec_thiep (getint (acet-str-format "\nEnter number of decimal places: <%1> " (itoa (getvar "useri1")) ) ) ) ) (setq prec_thiep (getvar "useri1")) ) (setvar "useri1" prec_thiep) (if ss (progn (mapcar '(lambda (x) (setq Lobj_dim_thiep (CONS (vlax-ename->vla-object x) Lobj_dim_thiep ) ) ) (acet-ss-to-list ss) ) (setq ID_Dim_lst_thiep (mapcar 'vla-get-objectid Lobj_dim_thiep)) (Setq field_lst (mapcar '(lambda (ob id) (if (distof (vla-get-TextOverride ob)) (acet-str-format "%<\\AcObjProp Object(%<\\_ObjId %1>%).%2>%+" (itoa id) "TextOverride" ) (acet-str-format "%<\\AcObjProp Object(%<\\_ObjId %1>%).%3 \\f \"%lu2%pr%2\">%+" (itoa id) (itoa prec_thiep) "Measurement" ) ) ) Lobj_dim_thiep ID_Dim_lst_thiep ) ) (setq strThiep (acet-str-format "%<\\AcExpr (%1) \\f \"%lu2%pr%2\">%" (vl-string-right-trim "+" (apply 'strcat field_lst) ) (itoa prec_thiep) ) ) (vla-put-TextString Obj_Text_thiep strThiep) ) ;_PROGN ) ;_IF (ACET-SYSVAR-RESTORE) (command "undo" "en") (PRINC str) (princ "\nOK") ) ;;;===========================================================================2: sum TEXTs, MTEXTs NUMBER========= (defun c:fdt2 (/ ss ent_T Obj_Text str prec Lobj_text ID_text_lst field_lst) (command "undo" "be") (acet-sysvar-set '("cmdecho" 0 "osmode" 0)) (acet-ui-status "Select: TEXT, MTEXT NUMBER FOR GET SUM" "Prompt") (setq ss (ssget '((0 . "*TEXT")))) (acet-ui-status) (if ss (progn (while (OR (NOT (setq ent_T (car (entsel "\nPick a Text object for set sum text number" ) ) ) ) (NOT (eq (cdr (assoc 0 (entget ent_T))) "TEXT")) ) (prompt "\nPick not right TEXT object, please pick again") ) (setq Obj_Text (vlax-ename->vla-object ent_T)) (if (null (setq prec (getint (acet-str-format "\nEnter number of decimal places: <%1> " (itoa (getvar "useri2")) ) ) ) ) (setq prec (getvar "useri2")) ) (setvar "useri2" prec) (mapcar '(lambda (x) (if (Numberp (atof (dxf 1 x))) (setq Lobj_text (CONS (vlax-ename->vla-object x) Lobj_text ) ) ) ) (acet-ss-to-list ss) ) (setq ID_text_lst (mapcar 'vla-get-objectid Lobj_text)) (setq field_lst (mapcar '(lambda (x) (acet-str-format "%<\\AcObjProp Object(%<\\_ObjId %1>%).TextString>% +" (itoa x) ) ) ID_text_lst ) ) (setq str (acet-str-format "%<\\AcExpr (%1)>%" (vl-string-right-trim "+" (apply 'strcat field_lst)) ) ) (dos_clipboard str) (vla-put-TextString Obj_Text str) ) ;_PROGN ) ;_IF (ACET-SYSVAR-RESTORE) (command "undo" "en") (princ "\nOK") (PRINC) ) ;;;===========================================================================3: LENGTHs========= (defun c:fdt3 (/ ss ent_T Obj_Text str prec Lobj_leng ID_leng_lst field_lst) (command "undo" "be") (acet-sysvar-set '("cmdecho" 0 "osmode" 0)) (acet-ui-status "Select: LINE, POLYLINE, for GET SUM LENGTH" "Prompt") (setq ss (ssget '((0 . "LINE,*POLYLINE")))) (acet-ui-status) (if ss (progn (while (OR (NOT (setq ent_T (car (entsel "\nPick a Text object for set sum length value" ) ) ) ) (NOT (eq (cdr (assoc 0 (entget ent_T))) "TEXT")) ) (prompt "\nPick not right TEXT object, please pick again") ) (setq Obj_Text (vlax-ename->vla-object ent_T)) (if (null (setq prec (getint (acet-str-format "\nEnter number of decimal places: <%1> " (itoa (getvar "useri3")) ) ) ) ) (setq prec (getvar "useri3")) ) (setvar "useri3" prec) (mapcar '(lambda (x) (if (vlax-property-available-p (vlax-ename->vla-object x) 'length ) (setq Lobj_leng (CONS (vlax-ename->vla-object x) Lobj_leng ) ) ) ) (acet-ss-to-list ss) ) (setq ID_leng_lst (mapcar 'vla-get-objectid Lobj_leng)) (setq field_lst (mapcar '(lambda (id) (acet-str-format "%<\\AcObjProp Object(%<\\_ObjId %1>%).Length \\f \"%lu2%pr%2\">%+" (itoa id) (itoa prec) ) ) ID_leng_lst ) ) (setq str (acet-str-format "%<\\AcExpr (%1) \\f \"%lu2%pr%2\">%" (vl-string-right-trim "+" (apply 'strcat field_lst)) (itoa prec) ) ) (vla-put-TextString Obj_Text str) ) ;_PROGN ) ;_IF (ACET-SYSVAR-RESTORE) (command "undo" "en") (princ "\nOK") (PRINC) ) ;;;===========================================================================4: AREAs========= (defun c:fdt4 (/ ss ent_T Obj_Text Lobj_area ID_area_lst str prec field_lst) (command "undo" "be") (acet-sysvar-set '("cmdecho" 0 "osmode" 0)) (acet-ui-status "Select: POLYLINE, HATCH, ARC, CIRCLE, REGION, ELLIPSE for GET SUM AREA" "Prompt" ) (setq ss (ssget '((0 . "*POLYLINE,HATCH,ARC,CIRCLE,ELLIPSE,REGION")))) (acet-ui-status) (if ss (progn (mapcar '(lambda (x) (if (vlax-property-available-p (vlax-ename->vla-object x) 'area ) (setq Lobj_area (CONS (vlax-ename->vla-object x) Lobj_area ) ) ) ) (acet-ss-to-list ss) ) (if (null (setq prec (getint (acet-str-format "\nEnter number of decimal places: <%1> " (itoa (getvar "useri4")) ) ) ) ) (setq prec (getvar "useri4")) ) (setvar "useri4" prec) (setq ID_area_lst (mapcar 'vla-get-objectid Lobj_area)) (setq field_lst (mapcar '(lambda (id) (acet-str-format "%<\\AcObjProp Object(%<\\_ObjId %1>%).Area \\f \"%lu2%pr%2\">%+" (itoa id) (itoa prec) ) ) ID_area_lst ) ) (setq str (acet-str-format "%<\\AcExpr (%1) \\f \"%lu2%pr%2\">%" (vl-string-right-trim "+" (apply 'strcat field_lst)) (itoa prec) ) ) (while (OR (NOT (setq ent_T (car (entsel "\nPick a Text object for set sum area value" ) ) ) ) (NOT (eq (cdr (assoc 0 (entget ent_T))) "TEXT")) ) (prompt "\nPick not right TEXT object, please pick again") ) (setq Obj_Text (vlax-ename->vla-object ent_T)) (vla-put-TextString Obj_Text str) ) ;_PROGN ) ;_IF (ACET-SYSVAR-RESTORE) (command "undo" "en") (princ "\nOK") (PRINC) ) ;;;================================================================== 5: CIRCUMFERENCEs: CHU VI VÒNG TRÒN (defun c:fdt5 (/ ss ent_T Obj_Text Lobj_CIR ID_CIR_lst str prec field_lst) (command "undo" "be") (acet-sysvar-set '("cmdecho" 0 "osmode" 0)) (acet-ui-status "Select: CIRCLE for GET SUM CIRCUMFERENCE" "Prompt") (setq ss (ssget '((0 . "CIRCLE")))) (acet-ui-status) (while (OR (NOT (setq ent_T (car (entsel "\nPick a Text object for set sum circumference value" ) ) ) ) (NOT (eq (cdr (assoc 0 (entget ent_T))) "TEXT")) ) (prompt "\nPick not right TEXT object, please pick again") ) (setq Obj_Text (vlax-ename->vla-object ent_T)) (if ss (progn (mapcar '(lambda (x) (setq Lobj_CIR (CONS (vlax-ename->vla-object x) Lobj_CIR)) ) (acet-ss-to-list ss) ) (if (null (setq prec (getint (acet-str-format "\nEnter number of decimal places: <%1> " (itoa (getvar "useri5")) ) ) ) ) (setq prec (getvar "useri5")) ) (setvar "useri5" prec) (setq ID_CIR_lst (mapcar 'vla-get-objectid Lobj_CIR)) (setq field_lst (mapcar '(lambda (id) (acet-str-format "%<\\AcObjProp Object(%<\\_ObjId %1>%).Circumference \\f \"%lu2%pr%2\">%+" (itoa id) (itoa prec) ) ) ID_CIR_lst ) ) (setq str (acet-str-format "%<\\AcExpr (%1) \\f \"%lu2%pr%2\">%" (vl-string-right-trim "+" (apply 'strcat field_lst)) (itoa prec) ) ) (vla-put-TextString Obj_Text str) ) ;_PROGN ) ;_IF (ACET-SYSVAR-RESTORE) (command "undo" "en") (princ "\nOK") (PRINC) ) ;;;===================update field sum DIMENSIONs when change properti TextOverride dim to Measurement dim or reverse ===== (defun c:re1 (/) (command "undo" "be") (setq ID_Dim_lst_thiep (mapcar 'vla-get-objectid Lobj_dim_thiep)) (Setq field_lst (mapcar '(lambda (ob id) (if (distof (vla-get-TextOverride ob)) (acet-str-format "%<\\AcObjProp Object(%<\\_ObjId %1>%).%2>%+" (itoa id) "TextOverride" ) (acet-str-format "%<\\AcObjProp Object(%<\\_ObjId %1>%).%3 \\f \"%lu2%pr%2\">%+" (itoa id) (itoa prec_thiep) "Measurement" ) ) ) Lobj_dim_thiep ID_Dim_lst_thiep ) ) (setq strThiep (acet-str-format "%<\\AcExpr (%1) \\f \"%lu2%pr%2\">%" (vl-string-right-trim "+" (apply 'strcat field_lst)) (itoa prec_thiep) ) ) (vla-put-TextString Obj_Text_thiep strThiep) (command "undo" "en") (princ "\nOK") )   field-sumOBJ2TEXT.LSP
    • Like
    2