Adjust Attribute - decimal number with two digits after the point

Adjust Attribute - decimal number with two digits after the point

yu85.info
Collaborator Collaborator
626 Views
4 Replies
Message 1 of 5

Adjust Attribute - decimal number with two digits after the point

yu85.info
Collaborator
Collaborator

Hi, I have this block attached in the DWG file. I am looking for a lisp to change all the numbers in the attribute to a decimal number with two digits after the point. If possible I would be glad if  it will fit to any block and any attribute regardless the name of the block or the name of the attribute, and will just modify any blocks in the drawing so the value in the attributes will be a decimal number with two digits after the point.

Thank you all very much in advance

 

0 Likes
Accepted solutions (1)
627 Views
4 Replies
Replies (4)
Message 2 of 5

devitg
Advisor
Advisor

@yu85.info Please give it a test.

 

;; Design by Gabo CALOS DE VIT from CORDOBA ARGENTINA
;;;    Copyleft 1995-2024 by Gabriel Calos De Vit ; DEVITG@GMAIL.COM    
;;

 ; Hecho por  Gabo CALOS DE VIT de CORDOBA ARGENTINA
;;;    Copyleft 1995-2024 por Gabriel Calos De Vit 
;; DEVITG@GMAIL.COM 
;;; inicio-defun-17-04-2024

(defun c:chg-att-to-2x (/
ACAD-OBJ ADOC ALL-BLK-REF-ENT-SS ALL-BLK-REF-OBJ-SS ATT ATT-LIST
	      )
(VL-LOAD-COM)
(SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) ;_ 
(SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ)) ;_ 
  (setq all-blk-ref-ent-ss (ssget "_X" '((0 . "insert"))))
  (setq all-blk-ref-obj-ss (VLA-GET-ACTIVESELECTIONSET adoc))
  (vlax-for blk-ref-obj	all-blk-ref-obj-ss
    (if	(= :vlax-true (VLA-GET-HASATTRIBUTES blk-ref-obj))
      (progn
	(setq
	  att-list
	   (VLAX-SAFEARRAY->LIST
	     (VLAX-VARIANT-VALUE (VLA-GETATTRIBUTES blk-ref-obj))
	   ) ;_ end of VLAX-SAFEARRAY->LIST
	) ;_ end of setq
	(setq att (car att-list))
	(foreach att att-list
	  (vla-put-textstring
	    att
	    (rtos (atof (VLA-GET-TEXTSTRING att)) 2 2)
	  ) ;_ end of vla-put-textstring
	) ;_ end of foreach
      ) ;_ end of progn
    ) ;_ end if
  ) ;_ end of vlax-for
) ;_ end of defun
;|«Visual LISP© Format Options»
(72 2 40 2 T "end of " 60 9 0 0 0 T T nil T)
;*** DO NOT add text below the comment! ***|;

 

 

Message 3 of 5

yu85.info
Collaborator
Collaborator

Hi, thanks. I do not know why. but it doesn't seem to work. I have attached another DWG file I tested your LSP file on it.

In addition, sorry for my rudeness, if it possible that if there is a mark like " or $  after the number  lisp wont modify this number.

Thanks again very much sir

0 Likes
Message 4 of 5

yu85.info
Collaborator
Collaborator
Accepted solution

Sorry for disturbing you sir. I tried Google harder and found what i need

I appreciate your kindly help 

https://www.cadforum.cz/en/rounding-decimal-numbers-in-drawing-texts-tip8181

0 Likes
Message 5 of 5

devitg
Advisor
Advisor

@yu85.info I will check it now .