BangVD Posted December 7, 2021 Posted December 7, 2021 Hello, I need some help with text,mtext,dtext... , I want to get text with its center position in csv expl: Quote
Steven P Posted December 7, 2021 Posted December 7, 2021 (edited) So where are you stuck with this? This should give you the centre point of a text, ;;centre point of text (defun c:txtcentre ( / txtset myent acount alignment Edata pt) (defun gettextalign ( myent / txtset Edata ptx_old pty_old pty_new ptx_new mycons) (setq Edata (entget myent)) (setq mycons 10) (if (/= 0 (nth 1 (cdr (assoc 11 Edata))))(setq mycons 11)) (setq ptx_old (nth 1 (assoc mycons Edata))) (setq pty_old (nth 2 (assoc mycons Edata))) (command "_.justifytext" myent "" "MC") (setq Edata (entget myent)) (setq ptx_new (nth 1 (assoc mycons Edata))) (setq pty_new (nth 2 (assoc mycons Edata))) (if (< ptx_old ptx_new)(setq alignx "L")) (if (> ptx_old ptx_new)(setq alignx "R")) (if (= ptx_old ptx_new)(setq alignx "C")) (if (> pty_old pty_new)(setq aligny "T")) (if (< pty_old pty_new)(setq aligny "B")) (if (= pty_old pty_new)(setq aligny "M")) (setq xyalign (strcat aligny alignx)) (command "_.justifytext" myent "" xyalign) xyalign ) (princ "\nSelect Text") (setq txtset (ssget '((0 . "*TEXT")))) (setq acount 0) ;;Loop from here if needed (setq myent (ssname txtset acount)) (setq Edata (entget myent)) (setq alignment (gettextalign myent)) (command "_.justifytext" myent "" "MC") (if (= (cdr (assoc 0 Edata)) "MTEXT") (setq pt (assoc 10 (entget myent))) (setq pt (assoc 11 (entget myent))) ) (setq ptx (car pt)) (setq pty (cdr pt)) (command "_.justifytext" myent "" alignment) ;;end loop here if needed (princ "x:")(princ ptx) (princ "\nY:")(princ pty) ) There are lots of examples out there to export to CSV and you should be able to build that up from above, the drawing and the text string (again lots of examples out there) Lee Mac also had this to find the centre of the text, either in this forum or on his website: (defun LM:txtcentre ( / b e centretext) (cond ( (not (setq e (car (nentsel))))) ( (not (setq b (LM:textbox (entget e)))) (princ "\nInvalid object selected - please select text, mtext or attribute.") ) ( (entmake (list '(000 . "POINT") (cons 010 (trans (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) (car b) (caddr b)) e 0)) (assoc 210 (entget e)) ) ) ) ( (princ "\nUnable to create central point.")) ) (setq centretext (trans (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) (car b) (caddr b)) e 0) ) (list centretext e) ) So back to my question, where are you stuck with this? Edited December 7, 2021 by Steven P Corrected spelling 1 Quote
BangVD Posted December 8, 2021 Author Posted December 8, 2021 Thank you very much for your reply however I am a new user so it will take some time to develop your lisps, I attached here is an example drawing, I want to get both the text and its position to csv for example "TB 59" X:-9676.737 Y:-4473.2727 Sample (2).dwg Quote
BangVD Posted December 8, 2021 Author Posted December 8, 2021 5 hours ago, Steven P said: So where are you stuck with this? This should give you the centre point of a text, ;;centre point of text (defun c:txtcentre ( / txtset myent acount alignment Edata pt) (defun gettextalign ( myent / txtset Edata ptx_old pty_old pty_new ptx_new mycons) (setq Edata (entget myent)) (setq mycons 10) (if (/= 0 (nth 1 (cdr (assoc 11 Edata))))(setq mycons 11)) (setq ptx_old (nth 1 (assoc mycons Edata))) (setq pty_old (nth 2 (assoc mycons Edata))) (command "_.justifytext" myent "" "MC") (setq Edata (entget myent)) (setq ptx_new (nth 1 (assoc mycons Edata))) (setq pty_new (nth 2 (assoc mycons Edata))) (if (< ptx_old ptx_new)(setq alignx "L")) (if (> ptx_old ptx_new)(setq alignx "R")) (if (= ptx_old ptx_new)(setq alignx "C")) (if (> pty_old pty_new)(setq aligny "T")) (if (< pty_old pty_new)(setq aligny "B")) (if (= pty_old pty_new)(setq aligny "M")) (setq xyalign (strcat aligny alignx)) (command "_.justifytext" myent "" xyalign) xyalign ) (princ "\nSelect Text") (setq txtset (ssget '((0 . "*TEXT")))) (setq acount 0) ;;Loop from here if needed (setq myent (ssname txtset acount)) (setq Edata (entget myent)) (setq alignment (gettextalign myent)) (command "_.justifytext" myent "" "MC") (if (= (cdr (assoc 0 Edata)) "MTEXT") (setq pt (assoc 10 (entget myent))) (setq pt (assoc 11 (entget myent))) ) (setq ptx (car pt)) (setq pty (cdr pt)) (command "_.justifytext" myent "" alignment) ;;end loop here if needed (princ "x:")(princ ptx) (princ "\nY:")(princ pty) ) There are lots of examples out there to export to CSV and you should be able to build that up from above, the drawing and the text string (again lots of examples out there) Lee Mac also had this to find the centre of the text, either in this forum or on his website: (defun LM:txtcentre ( / b e centretext) (cond ( (not (setq e (car (nentsel))))) ( (not (setq b (LM:textbox (entget e)))) (princ "\nInvalid object selected - please select text, mtext or attribute.") ) ( (entmake (list '(000 . "POINT") (cons 010 (trans (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) (car b) (caddr b)) e 0)) (assoc 210 (entget e)) ) ) ) ( (princ "\nUnable to create central point.")) ) (setq centretext (trans (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) (car b) (caddr b)) e 0) ) (list centretext e) ) So back to my question, where are you stuck with this? sorry for not quoting your answer Quote
hosneyalaa Posted December 8, 2021 Posted December 8, 2021 TRY (defun c:QQQQTest ( / int sel ent get ins txt src tar srt) (setq int -1 sel (ssget '((0 . "TEXT") ))) (setq file2open (vl-filename-mktemp "tmp" (getvar 'dwgprefix) ".csv")) (setq f_open (open file2open "w")) (princ "TEXT" f_open) (princ ";" f_open) (princ "X" f_open) (princ ";" f_open) (princ "Y" f_open) (princ "\n" f_open) (while (setq int (1+ int) ent (ssname sel int)) (setq get (entget ent) ins (cdr (assoc 11 get)) txt (cdr (assoc 01 get)) ) (princ txt f_open) (princ ";" f_open) (princ (rtos (car ins) 2 3) f_open) (princ ";" f_open) (princ (rtos (caDr ins) 2 3) f_open) (princ "\n" f_open) ) (close f_open) (startapp "explorer" file2open);opin excel (princ) ) (vl-load-com) 1 Quote
BangVD Posted December 8, 2021 Author Posted December 8, 2021 7 minutes ago, hosneyalaa said: TRY (defun c:QQQQTest ( / int sel ent get ins txt src tar srt) (setq int -1 sel (ssget '((0 . "TEXT") ))) (setq file2open (vl-filename-mktemp "tmp" (getvar 'dwgprefix) ".csv")) (setq f_open (open file2open "w")) (princ "TEXT" f_open) (princ ";" f_open) (princ "X" f_open) (princ ";" f_open) (princ "Y" f_open) (princ "\n" f_open) (while (setq int (1+ int) ent (ssname sel int)) (setq get (entget ent) ins (cdr (assoc 11 get)) txt (cdr (assoc 01 get)) ) (princ txt f_open) (princ ";" f_open) (princ (rtos (car ins) 2 3) f_open) (princ ";" f_open) (princ (rtos (caDr ins) 2 3) f_open) (princ "\n" f_open) ) (close f_open) (startapp "explorer" file2open);opin excel (princ) ) (vl-load-com) Great! I did it, Thank you so much 1 Quote
Tharwat Posted December 8, 2021 Posted December 8, 2021 @hosneyalaa Please don't use my codes in such a missy way of coding via copying and pasting then removing my name from my routine. CHECK Always try to write yours to get experience via practicing. 2 1 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.