Jump to content

Export text and coordinates of text center to csv


BangVD

Recommended Posts

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 by Steven P
Corrected spelling
  • Like 1
Link to comment
Share on other sites

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

image.thumb.png.2100ac74cbe1c983d6574a3ba6d487e7.pngimage.png.b875d3fef6c970eb7617fe1189f470f8.png 

  

Sample (2).dwg

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

 

  • Thanks 1
Link to comment
Share on other sites

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 

  • Thanks 1
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...