pmxcad Posted January 16, 2019 Share Posted January 16, 2019 (edited) Hello Iam looking for a lisp that select a closed polyline "hidden" layer "shield" color "10", --> select all text on layer "RoomNR" inside this polyline and store the text data in a excel file. And store the Excel file in the dwg root (dwgprefix). Regards, jm Edited February 1, 2019 by pmxcad Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 18, 2019 Share Posted January 18, 2019 (edited) Try this, the question was asked about 2013 a search should have found it. text in polygon.lsp Edited January 18, 2019 by BIGAL Quote Link to comment Share on other sites More sharing options...
pmxcad Posted January 18, 2019 Author Share Posted January 18, 2019 (edited) Thanks BIGAL. I have changed some things. but have two more things. 1 only select text that is on layer (8. "RoomNR"), where I have to place this. 2 only select the polyline that is on layer (8 "Shield"). I do not know where to place. Could you help with this? (defun c:test () (defun getcoords (ent) (vlax-safearray->list (vlax-variant-value (vlax-get-property (vlax-ename->vla-object ent) "Coordinates" ) ) ) ) (defun co-ords2xy () ; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z (setq numb (/ (length co-ords) 2)) (setq I 0) (repeat numb (setq xy (list (nth I co-ords)(nth (+ I 1) co-ords) )) (setq coordsxy (cons xy coordsxy)) (setq I (+ I 2)) ) ; end repeat ) ; end defun ; program starts here ; choose output file change acdatemp to what you want (setq fname (strcat (getvar "DWGPREFIX") (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)) ".csv")) (setq fout (open fname "w")) (setq plobjs (ssget (list (cons 0 "lwpolyline")))) (setq numb1 (sslength plobjs)) (setq x numb1) (repeat numb1 (setq obj (ssname plobjs (setq x (- x 1)))) (setq co-ords (getcoords obj)) (co-ords2xy) ; write pline co-ords here (setq numb3 (length co-ords)) (setq z numb3) (setq ansco-ords "") (repeat numb3 (setq ansco-ords (strcat ansco-ords (rtos (nth (setq z (- z 1)) co-ords) 2 3 ) " " )) ) (setq ans (strcat "Pline " ansco-ords)) ;(write-line ans fout) ;(write-line (getvar "dwgname") fout);----------------------------- (setq ansco-ords "") (setq ss (ssget "WP" coordsxy (list (cons 0 "Text,Mtext")))) ; selection set of text within polygon (if (= ss nil) (princ "\nnothing inside") (progn (setq coordsxy nil) ; reset for next time (setq numb2 (sslength ss)) (setq y numb2) (repeat numb2 (setq anstext (vlax-get-property (vlax-ename->vla-object (ssname ss (setq y (- y 1)))) "Textstring")) (princ anstext) ; change to write text to file ;(write-line (strcat "text " anstext) fout) (write-line anstext fout) (princ "\n") ) ; end repeat2 (setq ss nil) ; reset for next poly ) ) ) ; end repeat1 (close fout) (princ) );defun i think somewhere here: (setq plobjs (ssget (list (cons 0 "lwpolyline")))) ;for the polyline and (setq ss (ssget "WP" coordsxy (list (cons 0 "Text,Mtext")))) ;for the text Regards, JM Edited January 18, 2019 by pmxcad Quote Link to comment Share on other sites More sharing options...
pmxcad Posted January 19, 2019 Author Share Posted January 19, 2019 Solved, (defun c:test () (defun getcoords (ent) (vlax-safearray->list (vlax-variant-value (vlax-get-property (vlax-ename->vla-object ent) "Coordinates" ) ) ) ) (defun co-ords2xy () ; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z (setq numb (/ (length co-ords) 2)) (setq I 0) (repeat numb (setq xy (list (nth I co-ords)(nth (+ I 1) co-ords) )) (setq coordsxy (cons xy coordsxy)) (setq I (+ I 2)) ) ; end repeat ) ; end defun ; program starts here ; choose output file change acdatemp to what you want (setq fname (strcat (getvar "DWGPREFIX") (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)) ".csv")) (setq fout (open fname "w")) (setq plobjs (ssget (list (cons 0 "lwpolyline") (cons 8 "Shield")))) (setq numb1 (sslength plobjs)) (setq x numb1) (repeat numb1 (setq obj (ssname plobjs (setq x (- x 1)))) (setq co-ords (getcoords obj)) (co-ords2xy) ; write pline co-ords here (setq numb3 (length co-ords)) (setq z numb3) (setq ansco-ords "") (repeat numb3 (setq ansco-ords (strcat ansco-ords (rtos (nth (setq z (- z 1)) co-ords) 2 3 ) " " )) ) (setq ans (strcat "Pline " ansco-ords)) ;(write-line ans fout) ;(write-line (getvar "dwgname") fout);----------------------------- (setq ansco-ords "") (setq ss (ssget "WP" coordsxy (list (cons 0 "Text,Mtext") (cons 8 "RoomNR")))) ; selection set of text within polygon (if (= ss nil) (princ "\nnothing inside") (progn (setq coordsxy nil) ; reset for next time (setq numb2 (sslength ss)) (setq y numb2) (repeat numb2 (setq anstext (vlax-get-property (vlax-ename->vla-object (ssname ss (setq y (- y 1)))) "Textstring")) (princ anstext) ; change to write text to file ;(write-line (strcat "text " anstext) fout) (write-line anstext fout) (princ "\n") ) ; end repeat2 (setq ss nil) ; reset for next poly ) ) ) ; end repeat1 (close fout) (princ) );defun JM Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 22, 2019 Share Posted January 22, 2019 Good to hear. Quote Link to comment Share on other sites More sharing options...
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.