Need a help in modification of lisp code.

Need a help in modification of lisp code.

Anonymous
Not applicable
811 Views
2 Replies
Message 1 of 3

Need a help in modification of lisp code.

Anonymous
Not applicable

I stucked at this lisp to make changes. The following code has a multipication factor of 0.9. But I need this multiplication factor as a variable user input value. The lisp code should ask for user input value then the code should multiply with user value to final summation. Advanced thnak you.

 

(defun C:9FS (/ cpent elist en ip newtxt pt ss sum sumtxt txt)
(princ "\n\t\t>>> Select text to get summ >>>")
(if
;;select texts/mtexts on screen :
(setq ss (ssget '((0 . "*TEXT"))))
;; if selected then :
(progn
;; store the first text entity for using 'em further :
(setq cpent (ssname ss 0))
;; set initial sum to zero :
(setq sum 0.)
;; loop trough selected texts/mtexts :
(while
;; get the first text in selection :
(setq en (ssname ss 0))
;; get entity list of them :
(setq elist (entget en))
;; get the textstring by key 1 from entity list :
(setq txt (cdr (assoc 1 elist)))
;; create output string :
(setq sumtxt
;; concatenate strings :
(strcat
;; convert digits to string :
(rtos
;; add to summ the digital value of text :
(setq sum (+ (* 0.9 (atof txt)) sum))
;; 2 is for metric units (3 for engineering) :
2
;; set precision by current :
(getvar "dimdec")))
)
;; delete entity from selection set :
(ssdel en ss)
)
;; display message in the command line:
(princ (strcat "\nSumm=" sumtxt))
(setq pt (getpoint "\nSpecify the new text location: "))
;; get the insertion point of stored entity :
(setq ip (cdr (assoc 10 (entget cpent))))
;; copy text entity to the new destination point :
(command "_copy" cpent "" "_non" ip "_non" pt)
;; get the last created entity :
(setq newtxt (entlast))
;; get entity list of them :
(setq elist (entget newtxt))
;; modify entity list with new text string :
(entmod (subst (cons 1 sumtxt) (assoc 1 elist) elist))
;; update changes :
(entupd newtxt)
)
)
(princ)
)
(princ "\nStart command with STX...")
(princ)

0 Likes
Accepted solutions (1)
812 Views
2 Replies
Replies (2)
Message 2 of 3

pbejse
Mentor
Mentor
Accepted solution
(defun C:9FS (/ cpent elist en ip newtxt pt ss sum sumtxt txt factor)
  (princ "\n\t\t>>> Select text to get summ >>>")
  (if
    ;;select texts/mtexts on screen :
    (and
      	(setq ss (ssget '((0 . "*TEXT"))))
	(setq factor (getreal "\nEnter factor: "))
	)
     ;; if selected then :
     (progn
       ;; store the first text entity for using 'em further :
       (setq cpent (ssname ss 0))
       ;; set initial sum to zero :
       (setq sum 0.)
       ;; loop trough selected texts/mtexts :
       (while
	 ;; get the first text in selection :
	 (setq en (ssname ss 0))
	  ;; get entity list of them :
	  (setq elist (entget en))
	  ;; get the textstring by key 1 from entity list :
	  (setq txt (cdr (assoc 1 elist)))
	  ;; create output string :
	  (setq	sumtxt
		 ;; concatenate strings :
		 (strcat
		   ;; convert digits to string :
		   (rtos
		     ;; add to summ the digital value of text :
		     (setq sum (+ (* factor (atof txt)) sum))
		     ;; 2 is for metric units (3 for engineering) :
		     2
		     ;; set precision by current :
		     (getvar "dimdec")
		   )
		 )
	  )
	  ;; delete entity from selection set :
	  (ssdel en ss)
       )
       ;; display message in the command line:
       (princ (strcat "\nSumm=" sumtxt))
       (setq pt (getpoint "\nSpecify the new text location: "))
       ;; get the insertion point of stored entity :
       (setq ip (cdr (assoc 10 (entget cpent))))
       ;; copy text entity to the new destination point :
       (command "_copy" cpent "" "_non" ip "_non" pt)
       ;; get the last created entity :
       (setq newtxt (entlast))
       ;; get entity list of them :
       (setq elist (entget newtxt))
       ;; modify entity list with new text string :
       (entmod (subst (cons 1 sumtxt) (assoc 1 elist) elist))
       ;; update changes :
       (entupd newtxt)
     )
  )
  (princ)
)
Message 3 of 3

Anonymous
Not applicable

Thank you So much you Sir for your immediate reply, which will made me happy.

0 Likes