Jump to content

Recommended Posts

Posted

I stucked in modification of this lisp code. This lisp code multiplies the final summation of value to a fixed value of "0.9". But I need a change in this lisp code, that the code should take a user input value from command prompt. That means the the multiplication factor is a variable value. Pleas help. Advanced Thank 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)

Posted
1 hour ago, tnvsb said:

I stucked in modification of this lisp code. This lisp code multiplies the final summation of value to a fixed value of "0.9". But I need a change in this lisp code, that the code should take a user input value from command prompt. That means the the multiplication factor is a variable value. Pleas help. Advanced Thank you.

 

(defun C:9FS (/ mf cpent elist en ip newtxt pt ss sum sumtxt txt)

(initget (+ 1 2 4))
(setq mf (getreal "\nEnter Multiplication Factor : "))

 

(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 (+ (* mf (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) 

 

Add the red lines and the variable (top of code) Change your code to match the green line (substitute mf for 0.9)

Posted

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

But small problem is there in code that, if it has alphabets before numbers, then it's not working. Could you please help me.

Posted
5 hours ago, tnvsb said:

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

But small problem is there in code that, if it has alphabets before numbers, then it's not working. Could you please help me.

 

If this is only happening with MTEXT then they are more than likely MTEXT format strings. That aside, please post a drawing with the problem TEXT/MTEXT in Autocad 2010 format, or give examples of the strings you are getting.

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...