Fleybovich Posted June 25, 2010 Share Posted June 25, 2010 Trying to map out a land use and number of floors in a drawing. The two .dxf files are one on top of the other, and separate texts. Is it possible two right a lisp that can combine all the texts that are on top of each with a - in between them. I'm just learning autolisp now, and im a real beginner and i think this would save me a lot of time. So if anybody can help i would really appreciate it so much. I found something on the forums that is similar but not what i need exactly--- (defun c:txts (/ a b aa bb all txtheight) (prompt "\nThis is to goin tow texts in one ... ") (setq a(entget(car(entsel"\nSelect first Text: ")))) (setq aa(cdr (assoc 1 a))) (setq b(entget(car(entsel"\nSelect second Text: ")))) (setq bb(cdr (assoc 1 b))) (setq all(strcat aa bb)) (setq txtheight(cdr(assoc 40 a))) (command "_.text" pause txtheight "" all) (princ) (princ "made By tharwat313@yahoo.com") (princ) ) Quote Link to comment Share on other sites More sharing options...
MSasu Posted June 25, 2010 Share Posted June 25, 2010 This will add the desired character in strings concatenation: (setq all (strcat aa " - " bb)) Regards, Quote Link to comment Share on other sites More sharing options...
Fleybovich Posted June 25, 2010 Author Share Posted June 25, 2010 So it works, although i have to go through every two things that i want to combine separately which is better than editting each one, which includes many steps, but i was reading on the forums that i if you make a matrix with the two lists of characters and numbers, then we can combine all them and put them back to where they belong. Is that correct? Quote Link to comment Share on other sites More sharing options...
MSasu Posted June 25, 2010 Share Posted June 25, 2010 How about repeating the action until user decides to cancel selection? (defun c:txts(/ a b aa bb all txtheight) [color=Red](setvar "CMDECHO" 0)[/color] (prompt "\nThis will merge two texts in one ... ") [color=Red] (while (and[/color] (setq a (entget (car (entsel "\nSelect first Text: ")))) (setq b (entget (car (entsel "\nSelect second Text: "))))[color=Red])[/color] (setq aa (cdr (assoc 1 a)) bb (cdr (assoc 1 b))) (setq all (strcat aa " - " bb)) (setq txtheight (cdr (assoc 40 a))) (command "_.TEXT" pause txtheight "" all) [color=Red] )[/color] (princ) (princ "\nmade By tharwat313@yahoo.com") (princ) ) Regards, Quote Link to comment Share on other sites More sharing options...
MSasu Posted June 25, 2010 Share Posted June 25, 2010 Or, maybe, this one will suit better your need: (defun c:MergeTexts( / Text1st Text2nd ) (setvar "CMDECHO" 0) (prompt "\nThis will merge two texts in one ") (while (and (setq Text1st (entget (car (entsel "\nSelect first text: ")))) (setq Text2nd (entget (car (entsel "\nSelect second text: "))))) (entmod (subst (cons '1 (strcat (cdr (assoc 1 Text1st)) " - " (cdr (assoc 1 Text2nd)))) (assoc 1 Text1st) Text1st)) (entdel (cdr (assoc -1 Text2nd))) ) (princ) ) Regards, Quote Link to comment Share on other sites More sharing options...
Fleybovich Posted June 25, 2010 Author Share Posted June 25, 2010 Thank You my friend. This will save me a lot of time! This forum is really amazing Have a great day Quote Link to comment Share on other sites More sharing options...
MSasu Posted June 25, 2010 Share Posted June 25, 2010 Glad to help you! You're welcome! Regards, Quote Link to comment Share on other sites More sharing options...
alanjt Posted June 25, 2010 Share Posted June 25, 2010 If the the text is stacked above one another, you could use something like this... (defun c:Combine (/ ss del) ;; Combine all selected text into top-most text object (option to delete others). ;; Text sorting based on Y value ;; Alan J. Thompson, 06.25.10 (vl-load-com) (if (setq ss (ssget "_:L" '((0 . "TEXT")))) ((lambda (i / ent lst str) (initget 0 "Yes No") (setq del (eq "Yes" (getkword "\nDelete originals? [Yes/No] <No>: "))) (while (setq e (ssname ss (setq i (1+ i)))) (setq ent (entget e) lst (cons (list (cdr (assoc 1 ent)) e ent (caddr (assoc 10 ent))) lst) ) ) (setq lst (vl-sort lst (function (lambda (a b) (> (last a) (last b))))) str (caar lst) ) (foreach x (cdr lst) (setq str (strcat str " - " (car x))) (and del (entdel (cadr x)))) (entmod (subst (cons 1 str) (assoc 1 (caddar lst)) (caddar lst))) ) -1 ) ) (princ) ) Slow day and having a little fun. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 25, 2010 Share Posted June 25, 2010 I found something on the forums that is similar but not what i need exactly--- (defun c:txts (/ a b aa bb all txtheight) (prompt "\nThis is to goin tow texts in one ... ") (setq a(entget(car(entsel"\nSelect first Text: ")))) (setq aa(cdr (assoc 1 a))) (setq b(entget(car(entsel"\nSelect second Text: ")))) (setq bb(cdr (assoc 1 b))) (setq all(strcat aa bb)) (setq txtheight(cdr(assoc 40 a))) (command "_.text" pause txtheight "" all) (princ) (princ "made By [color="Red"]tharwat313@yahoo.com[/color]") (princ) ) Thank you . Regards Tharwat Quote Link to comment Share on other sites More sharing options...
MSasu Posted June 25, 2010 Share Posted June 25, 2010 (princ "made By user@domain.com") Is not a good idea to expose your e-mail address like this - it is like an invitation to spammers. Regards, Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 25, 2010 Share Posted June 25, 2010 Is not a good idea to expose your e-mail address like this - it is like an invitation to spammers. Regards, I do agree with you completely . But this file I made it along time ago somewhere, and I do not know where did he or she get it from ..... ? I just wanted to pay his or her attention to it .... thats all. Thanks for your concerns. Tharwat Quote Link to comment Share on other sites More sharing options...
jcap91163 Posted July 31, 2010 Share Posted July 31, 2010 I found more useful the Combine routine, even the Mergetexts is great, many thanks Quote Link to comment Share on other sites More sharing options...
antistar Posted August 2, 2010 Share Posted August 2, 2010 Alan, There are changing your routine for combining multiple texts into a new text without modifying the previous ones? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 2, 2010 Share Posted August 2, 2010 Alan, There are changing your routine for combining multiple texts into a new text without modifying the previous ones? Thanks in advance. I apologize, I don't understand your question. Quote Link to comment Share on other sites More sharing options...
antistar Posted August 2, 2010 Share Posted August 2, 2010 His routine is very interesting, but modifies the original text. I need a routine that creates a NEW TEXT with a combination of several texts? Thanks. Quote Link to comment Share on other sites More sharing options...
MSasu Posted August 2, 2010 Share Posted August 2, 2010 I think that @scamaru want that the merged text to be a new entity instead on having the first one modified. If so, please see that the routine from post #4 – the fixed version of OP’s code – is doing just this. Regards, Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 2, 2010 Share Posted August 2, 2010 His routine is very interesting, but modifies the original text. I need a routine that creates a NEW TEXT with a combination of several texts? Thanks. You want my submission routine to combine all values and prompt user to place the amalgamated strings into a new piece of text. Is this correct? Quote Link to comment Share on other sites More sharing options...
antistar Posted August 2, 2010 Share Posted August 2, 2010 Exactly Alan. And in alphabetical order. Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 2, 2010 Share Posted August 2, 2010 (edited) Here, I'm feeling generous and not wanting to work on my current project, at the moment. (defun c:Combine (/ ss) ;; Combine all selected text and place into new text object ;; Text sorting based on alphabetical order ;; Alan J. Thompson, 08.02.10 (if (setq ss (ssget "_:L" '((0 . "TEXT")))) ((lambda (i / del e lst pt) (initget 0 "Yes No") (setq del (eq "Yes" (getkword "\nDelete originals? [Yes/No] <No>: "))) (while (setq e (ssname ss (setq i (1+ i)))) (setq lst (cons (cdr (assoc 1 (entget e))) lst)) (and del (entdel e)) ) (if (setq pt (getpoint "\nSpecify text placement point: ")) (entmake (list '(0 . "TEXT") (cons 10 (trans pt 1 0)) (cons 40 (getvar 'textsize)) (cons 1 (AT:Lst2Str (vl-sort lst '<) " - ")) ) ) ) ) -1 ) ) (princ) ) (defun AT:Lst2Str (L S) ;; Convert List to String ;; L - List to process ;; S - Separator ;; Ex. (AT:Lst2Str '("A" "B" "C") ",") -> "A,B,C" ;; Alan J. Thompson, 04.01.10 (if (cdr L) (strcat (vl-princ-to-string (car L)) S (AT:Lst2Str (cdr L) S)) (vl-princ-to-string (car L)) ) ) Edited August 2, 2010 by alanjt Quote Link to comment Share on other sites More sharing options...
antistar Posted August 2, 2010 Share Posted August 2, 2010 Alan, Great work. Exactly what I need. Thanks for your help and patience. Quote Link to comment Share on other sites More sharing options...
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.