Ish Posted January 26, 2022 Posted January 26, 2022 Dear sir. I need a lisp program for export coordinate of objects (point , block) with text label. If have already please share with me. Please see the attached file and image Thanks EXPORT TO EXCEL WITH TEXT AND XY OF OBJECT.dwg Quote
Ish Posted January 27, 2022 Author Posted January 27, 2022 22 hours ago, Ish said: Dear sir. I need a lisp program for export coordinate of objects (point , block) with text label. If have already please share with me. Please see the attached file and image Thanks EXPORT TO EXCEL WITH TEXT AND XY OF OBJECT.dwg 90.69 kB · 1 download Any possibility sir ? Quote
Steven P Posted January 27, 2022 Posted January 27, 2022 (edited) Seeing that you have been on the forum for a while, I guess you know the basics of a LISP. In your example drawing the text and point are not linked so I guess you will need to select the point then it's text and repeat until you have got all you need to get? Using entsel for both selections is a good option: (setq MyEnt (entsel "\nSelect Point")) (setq MyPCoords (cdr (assoc 10 (entget (car MyEnt))))) Will get you a coordinate and change assoc 10 to assoc 1 will get you the text in most instances....should give you a start anyway.. have a go and see where you go with that. If it was me I would use this (setq MyList (list)) (setq DoLoop "Yes") (while (= DoLoop "Yes") (if (setq MyEnt (entsel "\nSelect Point, or Enter or Space to exit")) (progn (setq MyPCoords (cdr (assoc 10 (entget (car MyEnt))))) (setq MyEnt (entsel "\nSelect Text")) (setq MyText (cdr (assoc 1 (entget (car MyEnt))))) (setq MyList (append MyList (list MyText (car MyPCoords) (cadr MyPCoords)) )) ) (setq DoLoop "No") ) ) (princ MyList) This creates short list (x y text) and stores them in a longer list MyList, You could use (nth n list) to extract the information when writing to an excel file.... and there have been questions about writing to excel recently that should help... (setq MyList (list)) (setq DoLoop "Yes") (while (= DoLoop "Yes") (if (setq MyEnt (entsel "\nSelect Point, or Enter or Space to exit")) (progn (setq MyPCoords (cdr (assoc 10 (entget (car MyEnt))))) (setq MyEnt (entsel "\nSelect Text")) (princ "Select Text") (setq MyText (cdr (assoc 1 (entget (car MyEnt))))) (setq MyList (append MyList (list MyText (car MyPCoords) (cadr MyPCoords)) )) ) (setq DoLoop "No") ) ) ;; get data to write to excel 1 set of data at a time (setq acount 0) (while (< acount (length MyList)) (setq Mytext (nth 0 (nth acount MyList))) (setq MyX (nth 1 (nth acount MyList))) (setq MyY (nth 2 (nth acount MyList))) ;;Write Mytext to excel ;;Write MyX to excel ;;Write MyY to excel (setq acount (+ acount 1)) ) Edited January 27, 2022 by Steven P 1 1 Quote
mhupp Posted January 27, 2022 Posted January 27, 2022 I would just evaluate entsel. eliminates if statement. (while (setq MyEnt (entsel "\nSelect Point, or Enter or Space to exit")) (setq MyPCoords (cdr (assoc 10 (entget (car MyEnt))))) (setq MyEnt (entsel "\nSelect Text")) (setq MyText (cdr (assoc 1 (entget (car MyEnt))))) (setq MyList (append MyList (list MyText (car MyPCoords) (cadr MyPCoords)))) ) 2 Quote
Steven P Posted January 27, 2022 Posted January 27, 2022 1 hour ago, mhupp said: I would just evaluate entsel. eliminates if statement. Yes, that's better Quote
BIGAL Posted January 28, 2022 Posted January 28, 2022 (edited) You can take the text and search around it for a block, say using bounding box then offset a pline use the co-ords and (ssget "CP" co-ords.... this way could all be done starting with a single window selection. The only draw back is may get wrong block. Pretty sure been done before. This is an example based on sample dwg, using a bounding box would be better. Just butchered one i already had. Look at LST for result. ; https://www.cadtutor.net/forum/topic/74392-require-lisp-to-export-coordinate-of-objects-along-with-text/ ; By AlanH Jan 2022 (defun c:toff (/ ent CEN CO-ORD LAY LST OBJ OBJ2 OLDSNAP RAD SS SS2 STR X) (setq offd (getreal "\nEnter offset try 2.5")) if text is further away (setq oldsnap (getvar 'osmode)) ; save current osnaps (setvar 'osmode 0) ; turn off osnaps (setq ent (entget (car (entsel "\nPick text for layer and value")))) ; select a text obect (setq lay (cdr (assoc 8 ent))) ; get object layer dxf code 8 (setq ss (ssget (list (cons 0 "*TEXT") (cons 8 lay) ))) ; get objects that are text on layer plus text string (setq lst '()) ; set list to blank in case exists already (repeat (setq x (sslength ss)) ; do for every text in selection (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1))))) ; get each item in selection set (setq ins (vlax-get Obj 'insertionPoint)) ; get text insertion point (setq str (vlax-get Obj 'textstring)) ; get object text dxf code 1 (if (> (vl-string-search "BricsCAD" (getvar 'acadver)) 0) (command "polygon" 20 ins offd) ; for Bricscad (command "polygon" 20 ins "I" offd) ;Autocad Note bricscad is different ) (setq obj2 (entlast)) ; save the name of the last object created (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget obj2)))) ; loops through the pline vertice points (command "erase" obj2 "") ; no longer required as needed points (setq ss2 (ssget "CP" co-ord (list (cons 0 "INSERT,POINT")))) ; looks for insert that touch the polygon (if (= ss2 nil) (princ) (progn (setq obj2 (vlax-ename->vla-object (ssname ss2 0))) (cond ((= (vla-get-objectname obj2) "AcDbBlockReference") (setq cen (vlax-get obj2 'insertionpoint))) ; gets the center point of the block ((= (vla-get-objectname obj2) "AcDbPoint") (setq cen (vlax-get obj2 'coordinates))) ) (setq lst (cons (list str cen) lst)) ; makes a list ) ) ) (setvar 'osmode oldsnap) ; reset the osnaps (princ lst) (princ) ; quite exit of defun ) (c:toff) Edited January 28, 2022 by BIGAL 1 Quote
Ish Posted January 28, 2022 Author Posted January 28, 2022 12 hours ago, BIGAL said: You can take the text and search around it for a block, say using bounding box then offset a pline use the co-ords and (ssget "CP" co-ords.... this way could all be done starting with a single window selection. The only draw back is may get wrong block. Pretty sure been done before. This is an example based on sample dwg, using a bounding box would be better. Just butchered one i already had. Look at LST for result. ; https://www.cadtutor.net/forum/topic/74392-require-lisp-to-export-coordinate-of-objects-along-with-text/ ; By AlanH Jan 2022 (defun c:toff (/ ent CEN CO-ORD LAY LST OBJ OBJ2 OLDSNAP RAD SS SS2 STR X) (setq offd (getreal "\nEnter offset try 2.5")) if text is further away (setq oldsnap (getvar 'osmode)) ; save current osnaps (setvar 'osmode 0) ; turn off osnaps (setq ent (entget (car (entsel "\nPick text for layer and value")))) ; select a text obect (setq lay (cdr (assoc 8 ent))) ; get object layer dxf code 8 (setq ss (ssget (list (cons 0 "*TEXT") (cons 8 lay) ))) ; get objects that are text on layer plus text string (setq lst '()) ; set list to blank in case exists already (repeat (setq x (sslength ss)) ; do for every text in selection (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1))))) ; get each item in selection set (setq ins (vlax-get Obj 'insertionPoint)) ; get text insertion point (setq str (vlax-get Obj 'textstring)) ; get object text dxf code 1 (if (> (vl-string-search "BricsCAD" (getvar 'acadver)) 0) (command "polygon" 20 ins offd) ; for Bricscad (command "polygon" 20 ins "I" offd) ;Autocad Note bricscad is different ) (setq obj2 (entlast)) ; save the name of the last object created (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget obj2)))) ; loops through the pline vertice points (command "erase" obj2 "") ; no longer required as needed points (setq ss2 (ssget "CP" co-ord (list (cons 0 "INSERT,POINT")))) ; looks for insert that touch the polygon (if (= ss2 nil) (princ) (progn (setq obj2 (vlax-ename->vla-object (ssname ss2 0))) (cond ((= (vla-get-objectname obj2) "AcDbBlockReference") (setq cen (vlax-get obj2 'insertionpoint))) ; gets the center point of the block ((= (vla-get-objectname obj2) "AcDbPoint") (setq cen (vlax-get obj2 'coordinates))) ) (setq lst (cons (list str cen) lst)) ; makes a list ) ) ) (setvar 'osmode oldsnap) ; reset the osnaps (princ lst) (princ) ; quite exit of defun ) (c:toff) I follow this, sir, cross window selection is good. After I select text and point, It's delete the point sir, And please add code for table in AutoCAD. Text X. Y. By other lisp I will export in Excel. Thanks sir Quote
Steven P Posted January 28, 2022 Posted January 28, 2022 How far have you got with finding this out for yourself? All well and good asking on a forum for a complete answer... but sometime it is good to have a go and let us see and guide you where to improve. The easiest way to export to excel is to create a CSV file, a text file that excel can open as a table, open this in excel and then 'save as'. Making a text file is quite simple and there is loads out there to show you how. One of my favourite resources is Lee Mac, a load of stuff and somewhere there is usually what I want, though sometimes you have to make adjustments for your own case. He is pretty good at what he does. So... looking at his website, this might do the trick http://lee-mac.com/writecsv.html , follow the example at the bottom of the page to run the lisp you can download from the top of the page, in this case using my example above it might give you this (I haven't checked this though) (setq acount 0) (if (setq fn (getfiled "Create Output File" "" "csv" 1)) (LM:WriteCSV MyList fn) ) ) 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.