mdbdesign Posted October 31, 2012 Posted October 31, 2012 After converting pdf to dxf, all converted text shown as a single character (as shown on picture). Is there way to convert it back to words and sentences by using lisp? Quote
BIGAL Posted November 1, 2012 Posted November 1, 2012 Could be done just make a "list" of characters and their x insert position the reason for x is that they may not have been created in the order viewed so your list has to reflect a continuous string as viewed, you could then use a distance factor bewteen characters to imply a space as a space does not exist. Sloping text ?? A quick thought for text not perp use the lower left bounding box point compared to insert pt to work out order. Quote
Tharwat Posted November 1, 2012 Posted November 1, 2012 Try this Marek . (defun c:GatherTexts (/ ss i sn e lst l st) ;;;;; Tharwat 01. Nov. 2012 ;;;;; ;;;;; gathering TEXT entities all together in ;;;;; ;;;;; the first left entity from the selection set ;;;;; (or acdoc (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))) (if (setq ss (ssget "_:L" '((0 . "TEXT")))) (progn (repeat (setq i (sslength ss)) (setq sn (ssname ss (setq i (1- i)))) (setq e (entget sn)) (setq lst (cons (list (cdr (assoc 10 e)) (cdr (assoc 1 e)) sn) lst)) ) (setq l (vl-sort lst '(lambda (a b) (< (car (car a)) (car (car b)))))) (setq st (apply 'strcat (mapcar 'cadr l))) (vla-StartUndoMark acdoc) (if (entmod (subst (cons 1 st) (assoc 1 (entget (caddr (car l)))) (entget (caddr (car l))))) (progn (setq l (reverse l)) (setq l (vl-remove (last l) l)) (mapcar 'entdel (mapcar 'caddr l))) ) (vla-EndUndomark acdoc) ) (princ) ) (princ) ) Quote
mdbdesign Posted November 1, 2012 Author Posted November 1, 2012 Tank you Tharwat, it work great but only for horizontal and sloped text. If text is vertical: it reverse it. I don't know if it is matter of selection way (I think I try all of it) or something need to be done for code. There is one sample dwg for testing if you like. test.dwg Quote
Tharwat Posted November 1, 2012 Posted November 1, 2012 I am sorry for the confusion , and that took a place because I worked on the code for horizontal texts only , so try it now . (defun c:Test (/ ss i sn e lst l st p r) ;;;;; Tharwat 01. Nov. 2012 ;;;;; ;;;;; gathering TEXT entities all together in ;;;;; ;;;;; the first left entity from the selection set ;;;;; (or acdoc (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))) (if (setq ss (ssget "_:L" '((0 . "TEXT")))) (progn (repeat (setq i (sslength ss)) (setq sn (ssname ss (setq i (1- i)))) (setq e (entget sn)) (setq lst (cons (list (cdr (assoc 10 e)) (cdr (assoc 1 e)) sn) lst)) ) (setq l (vl-sort lst '(lambda (a b) (< (car (car a)) (car (car b)))))) (setq st (apply 'strcat (mapcar 'cadr l))) (setq p (mapcar 'car (mapcar 'car lst))) (foreach x p (if (equal x (car p)) (setq r (cons x r)) ) ) (vla-StartUndoMark acdoc) (if (eq (length r) (length p)) (progn (setq st (vl-list->string (reverse (vl-string->list st)))) (if (entmod (subst (cons 1 st) (assoc 1 (entget (caddr (last l)))) (entget (caddr (last l))))) (progn (setq l (reverse l)) (setq l (vl-remove (car l) l)) (mapcar 'entdel (mapcar 'caddr l))) ) ) (if (entmod (subst (cons 1 st) (assoc 1 (entget (caddr (car l)))) (entget (caddr (car l))))) (progn (setq l (reverse l)) (setq l (vl-remove (last l) l)) (mapcar 'entdel (mapcar 'caddr l))) ) ) (vla-EndUndomark acdoc) ) (princ) ) (princ) ) Quote
mdbdesign Posted November 1, 2012 Author Posted November 1, 2012 Tharwat, you are perfect man. I want to apologize for not to mention about various text rotation. Work great, thank you very much. I really appreciate. Quote
Tharwat Posted November 1, 2012 Posted November 1, 2012 Tharwat, you are perfect man. Work great, thank you very much. I really appreciate. I am very happy to hear that . You're very welcome Marek . Quote
Lee Mac Posted November 4, 2012 Posted November 4, 2012 (edited) Here is my version: ;;----------------------=={ Merge Text }==--------------------;; ;; ;; ;; Converts a selection of single-character text objects ;; ;; into one or more text objects containing characters ;; ;; aligned by their insertion points & angle of rotation. ;; ;; Currently restricted to text containing no spaces. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2012 - www.lee-mac.com ;; ;;------------------------------------------------------------;; (defun c:mergetext ( / i l s ) (if (setq s (ssget "_:L" '((0 . "TEXT")))) (progn (repeat (setq i (sslength s)) (setq l (cons (entget (ssname s (setq i (1- i)))) l)) ) (foreach g (LM:GroupByFunction l (lambda ( a b / n r z ) (and (equal (setq r (cdr (assoc 050 a))) (cdr (assoc 050 b)) 0.001) (equal (setq z (cdr (assoc 210 a))) (cdr (assoc 210 b)) 0.001) (setq n (list (cos r) (sin r))) (equal (car (trans (cdr (assoc 10 a)) z n)) (car (trans (cdr (assoc 10 b)) z n)) 0.001 ) ) ) ) (if (cdr g) (progn (setq g (vl-sort g (function (lambda ( a b / n r z ) (setq r (cdr (assoc 050 a)) z (cdr (assoc 210 a)) n (list (cos r) (sin r)) ) (< (last (trans (cdr (assoc 10 a)) z n)) (last (trans (cdr (assoc 10 b)) z n)) ) ) ) ) ) (entmod (subst (cons 1 (apply 'strcat (mapcar '(lambda ( x ) (cdr (assoc 1 x))) g))) (assoc 1 (car g)) (car g) ) ) (foreach e (cdr g) (entdel (cdr (assoc -1 e)))) ) ) ) ) ) (princ) ) ;; Group By Function - Lee Mac ;; Groups items considered equal by a given predicate function (defun LM:GroupByFunction ( lst fun / tmp1 tmp2 x1 ) (if (setq x1 (car lst)) (progn (foreach x2 (cdr lst) (if (fun x1 x2) (setq tmp1 (cons x2 tmp1)) (setq tmp2 (cons x2 tmp2)) ) ) (cons (cons x1 (reverse tmp1)) (LM:GroupByFunction (reverse tmp2) fun)) ) ) ) (princ) The above should correctly process characters aligned at any rotation. Using an example from your file: Edited November 9, 2020 by Lee Mac Quote
mdbdesign Posted November 5, 2012 Author Posted November 5, 2012 Another great one. Thank you Lee. Now I can selected all at a time and it is done in one shot. Perfect. Thank you so much. Quote
Lee Mac Posted November 5, 2012 Posted November 5, 2012 Another great one. Thank you Lee. Now I can selected all at a time and it is done in one shot. Perfect. Thank you so much. Thank you Marek, you're very welcome. 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.