mikman Posted August 12, 2008 Posted August 12, 2008 I was recently using a lisp that added up text and created a text string with the sum. It stopped working and quoted the function "mktext" as the problem. It will still add the strings but it will not create a new string. I can't modify the routine, its locked and the owner doesn't work with me anymore. /:D Where can I find a place that would have a lisp that I could read and learn for myself? 1 Quote
fixo Posted August 12, 2008 Posted August 12, 2008 Hi Mike Take a look at this page, I think it's the best one you could be able to find on the web: http://afralisp.net/ FYI, I've started to learn lisp and VBA from there ~'J'~ 2 Quote
fixo Posted August 12, 2008 Posted August 12, 2008 Here is a quick example, hope this helps (defun C:STX (/ elist en 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 ;; 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 (+ (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 : (alert (strcat "\nSumm = " sumtxt)) ) ) (princ) ) (princ "\nStart command with STX...") (princ) Sorry for my poor english ~'J'~ 1 Quote
mikman Posted August 12, 2008 Author Posted August 12, 2008 (alert (strcat "\nSumm = " sumtxt)) That works pretty good Fixo. At this point where the window pops up with the number, do you know how to make a new text string? You are miles ahead of me so I hope you can help? Quote
fixo Posted August 12, 2008 Posted August 12, 2008 You are miles ahead of me so I hope you can help? Do not agreed with you The Earth is so small, take a look on map - just 5-6 thousand of miles or so Here is edited version This will create the new text entity with the same properties as the first selected text has (defun C:STX (/ 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 (+ (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 "" ip 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) ~'J'~ 1 Quote
mikman Posted August 12, 2008 Author Posted August 12, 2008 Fixo that worked great. I learned some new things and what you wrote was exactly what I needed. Thanks heaps! Quote
fixo Posted August 12, 2008 Posted August 12, 2008 You are welcome Happy computing, Cheers ~'J'~ Quote
sanalmakina Posted August 6, 2010 Posted August 6, 2010 hi! i'm using this lisp but if it's possible i want an addition. i want to sum texts with unit. for example: i will select: 1, 2, and 3 it sums and creates a text which is: 6 m³/h or 6 Watt etc. how can i do this? Here is a quick example, hope this helps (defun C:STX (/ elist en 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 ;; 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 (+ (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 : (alert (strcat "\nSumm = " sumtxt)) ) ) (princ) ) (princ "\nStart command with STX...") (princ) Sorry for my poor english ~'J'~ Quote
Lt Dan's legs Posted August 6, 2010 Posted August 6, 2010 (edited) Look near the end of the code for ;; display message : and replace the line below with (setq ins (getpoint "\nSpecify text location: ")) (entmake (list (cons 0 "text") (cons 1 (strcat sumtxt "m3/h"));;text (cons 7 "ROMANS");;text style (cons 8 "acc");;textlayer (cons 10 ins);;insertion point (cons 11 ins) (cons 40 2);;text height (cons 62 256);;bylayer (cons 72 1);;horizontal justification ) ) and replace ;; 2 is for metric units (3 for engineering) : 2 with 5 by the way great routine fixo! Why not put your name on it fixo? Edited August 6, 2010 by Lt Dan's legs additional info and question to fixo Quote
sanalmakina Posted August 6, 2010 Posted August 6, 2010 i'm sorry i couldn't make it. i changed the (setq ins ... code with your code but, it did not work. Could you add the whole code please? I will really appreciate it. -i saw your changed message after my post sorry. -yes i didn't want to see decimal part, so i changed "2" with so many numbers and catch the 5 (by luck) -sorry for my poor English. Quote
Lt Dan's legs Posted August 6, 2010 Posted August 6, 2010 (edited) (defun C:STX (/ elist en ss sum sumtxt txt ins) ;;created by Fixo ;;revised by Reid B. for sanalmakina (princ "\n\t\t>>> Select text to get summ >>>") (if ;;select texts/mtexts on screen : (setq ss (ssget '((0 . "*TEXT")))) ;; if selected then : (progn ;; 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 (+ (atof txt) sum)) ;; 2 is for metric units (3 for engineering) : 5;;revised by Reid B. ;; set precision by current : (getvar "dimdec"))) ) ;; delete entity from selection set : (ssdel en ss) ) ;; Change to text : (setq ins (getpoint "\nSpecify text location: "));;start revision by Reid B. (entmake (list '(0 . "text") (cons 100 "AcDbEntity") (cons 100 "AcDbText") (cons 1 (strcat sumtxt "m3/h"));;text (cons 7 "ROMANS");;text style (cons 8 "acc");;textlayer (cons 10 ins);;insertion point (cons 11 ins) (cons 40 2);;text height (cons 41 1);;text width (cons 50 0);;text rotation (cons 62 256);;bylayer (cons 72 0);;horizontal justification ) );;end revision by Reid B. ) ) (princ) ) (princ "\nStart command with STX...") (princ) Edited August 6, 2010 by Lt Dan's legs Quote
sanalmakina Posted August 6, 2010 Posted August 6, 2010 (defun C:STX (/ elist en ss sum sumtxt txt ins) ;;created by Fixo ;;revised by Reid B. for sanalmakina (princ "\n\t\t>>> Select text to get summ >>>") (if ;;select texts/mtexts on screen : (setq ss (ssget '((0 . "*TEXT")))) ;; if selected then : (progn ;; 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 (+ (atof txt) sum)) ;; 2 is for metric units (3 for engineering) : 5;;revised by Reid B. ;; set precision by current : (getvar "dimdec"))) ) ;; delete entity from selection set : (ssdel en ss) ) ;; Change to text : (setq ins (getpoint "\nSpecify text location: "));;start revision by Reid B. (entmake (list (cons 0 "text") (cons 1 (strcat sumtxt "m3/h"));;text (cons 7 "ROMANS");;text style (cons 8 "acc");;textlayer (cons 10 ins);;insertion point (cons 11 ins) (cons 40 2);;text height (cons 41 1);;text width (cons 50 0);;text rotation (cons 62 256);;bylayer (cons 72 0);;horizontal justification ) );;end revision by Reid B. ) ) (princ) ) (princ "\nStart command with STX...") (princ) Thank you Lt Dan's legs but, it doesn't work for me :s when i clicked for insertation, nothing happened. Quote
Lt Dan's legs Posted August 6, 2010 Posted August 6, 2010 code above revised Let me know if that solves the problem Quote
David Bethel Posted August 6, 2010 Posted August 6, 2010 if I understand the OP correctly, you can simplify the deal: [color=#8b4513];;;Given a true numeric string list[/color] [b][color=BLACK]([/color][/b]setq s1 [color=#2f4f4f]"3.4 5.6 7 8. 9"[/color][b][color=BLACK])[/color][/b] [color=#8b4513];;;Format the string into an autolisp funtion[/color] [b][color=BLACK]([/color][/b]setq as [b][color=FUCHSIA]([/color][/b]strcat [color=#2f4f4f]"[b][color=NAVY]([/color][/b]+ "[/color] s1 [color=#2f4f4f]"[b][color=NAVY])[/color][/b]"[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [color=#8b4513];;;Evaluate the string[/color] [b][color=BLACK]([/color][/b]setq av [b][color=FUCHSIA]([/color][/b]eval [b][color=NAVY]([/color][/b]read as[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [color=#8b4513];;;Contevrt the results into a string[/color] [b][color=BLACK]([/color][/b]setq ar [b][color=FUCHSIA]([/color][/b]rtos av[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [color=#8b4513];;;Print the results[/color] [b][color=BLACK]([/color][/b]princ ar[b][color=BLACK])[/color][/b] -David Quote
Tharwat Posted August 6, 2010 Posted August 6, 2010 I think he means the following adds to meet his desire... (defun C:STX (/ elist en ss sum sumtxt txt ins) ;;created by Fixo ;;revised by Reid B. for sanalmakina (princ "\n\t\t>>> Select text to get summ >>>") (if ;;select texts/mtexts on screen : (setq ss (ssget '((0 . "*TEXT")))) ;; if selected then : (progn ;; 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 (+ (atof txt) sum)) ;; 2 is for metric units (3 for engineering) : 5;;revised by Reid B. ;; set precision by current : (getvar "dimdec"))" " [color="red"]"m3/h"[/color]) ) ;; delete entity from selection set : (ssdel en ss) ) ;; Change to text : (setq ins (getpoint "\nSpecify text location: "));;start revision by Reid B. (command "_.text" ins "" "" sumtxt) ) ) (princ) ) (princ "\nStart command with STX...") (princ) Quote
sanalmakina Posted August 6, 2010 Posted August 6, 2010 (defun C:STX (/ elist en ss sum sumtxt txt ins) ;;created by Fixo ;;revised by Reid B. for sanalmakina (princ "\n\t\t>>> Select text to get summ >>>") (if ;;select texts/mtexts on screen : (setq ss (ssget '((0 . "*TEXT")))) ;; if selected then : (progn ;; 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 (+ (atof txt) sum)) ;; 2 is for metric units (3 for engineering) : 5;;revised by Reid B. ;; set precision by current : (getvar "dimdec"))) ) ;; delete entity from selection set : (ssdel en ss) ) ;; Change to text : (setq ins (getpoint "\nSpecify text location: "));;start revision by Reid B. (entmake (list '(0 . "text") (cons 100 "AcDbEntity") (cons 100 "AcDbText") (cons 1 (strcat sumtxt "m3/h"));;text (cons 7 "ROMANS");;text style (cons 8 "acc");;textlayer (cons 10 ins);;insertion point (cons 11 ins) (cons 40 2);;text height (cons 41 1);;text width (cons 50 0);;text rotation (cons 62 256);;bylayer (cons 72 0);;horizontal justification ) );;end revision by Reid B. ) ) (princ) ) (princ "\nStart command with STX...") (princ) i tried but it didn't work . command text: Command: apploadasd.lsp successfully loaded. asd.lsp successfully loaded. Command: Start command with STX... Command: Start command with STX... Command: Command: text Current text style: "K2000Style" Text height: 0.1000 Annotative: No Specify start point of text or [Justify/Style]: Specify rotation angle of text : Command: Specify opposite corner: Command: c COPY 1 found Current settings: Copy mode = Multiple Specify base point or [Displacement/mOde] : Specify second point or : Specify second point or [Exit/Undo] : *Cancel* Command: stx >>> Select text to get summ >>> Select objects: 1 found Select objects: 1 found' date=' 2 total Select objects: Specify text location:[/quote'] I think he means the following adds to meet his desire... (defun C:STX (/ elist en ss sum sumtxt txt ins) ;;created by Fixo ;;revised by Reid B. for sanalmakina (princ "\n\t\t>>> Select text to get summ >>>") (if ;;select texts/mtexts on screen : (setq ss (ssget '((0 . "*TEXT")))) ;; if selected then : (progn ;; 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 (+ (atof txt) sum)) ;; 2 is for metric units (3 for engineering) : 5;;revised by Reid B. ;; set precision by current : (getvar "dimdec"))" " [color="red"]"m3/h"[/color]) ) ;; delete entity from selection set : (ssdel en ss) ) ;; Change to text : (setq ins (getpoint "\nSpecify text location: "));;start revision by Reid B. (command "_.text" ins "" "" sumtxt) ) ) (princ) ) (princ "\nStart command with STX...") (princ) it writes it to command bar, not to the drawing:(. command text: Current text style: "K2000Style" Text height: 0.1000 Annotative: No Specify start point of text or [Justify/Style]: Specify rotation angle of text : Command: Command: c COPY 1 found Current settings: Copy mode = Multiple Specify base point or [Displacement/mOde] : Specify second point or : Specify second point or [Exit/Undo] : *Cancel* Command: stx >>> Select text to get summ >>> Select objects: 1 found Select objects: 1 found, 2 total Select objects: Specify text location: _.text Current text style: "K2000Style" Text height: 0.1000 Annotative: No Specify start point of text or [Justify/Style]: Specify rotation angle of text : Enter text: Command: 246246 m3/h Unknown command "246246 M3/H". Press F1 for help. Command: Quote
alanjt Posted August 6, 2010 Posted August 6, 2010 (cons 7 "ROMANS");;text style You are relying on this textstyle actually existing. Replace with (cons 7 (getvar 'textstyle)) Quote
Tharwat Posted August 6, 2010 Posted August 6, 2010 The problem is with the Text Style which is current , I mean put the Text height for it zero and try again. Quote
alanjt Posted August 6, 2010 Posted August 6, 2010 The problem is with the Text Style which is current , I mean put the Text height for it zero and try again.No, use entmake. Text in command is the most temperamental function that can be called. Quote
Lt Dan's legs Posted August 6, 2010 Posted August 6, 2010 (cons 7 (getvar 'textstyle)) thank you Alan! I'll definitely use this one Quote
Recommended Posts
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.