Jump to content

Combining two text right near eachother into one text


Fleybovich

Recommended Posts

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)
)

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • MSasu

    6

  • alanjt

    5

  • antistar

    4

  • Fleybovich

    3

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?

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

Thank You my friend.

 

This will save me a lot of time!

 

This forum is really amazing :)

 

Have a great day

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

(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,

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 month later...

Alan,

 

There are changing your routine for combining multiple texts into a new text without modifying the previous ones?

 

Thanks in advance.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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 by alanjt
Link to comment
Share on other sites

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...