iztok13 Posted January 12, 2009 Share Posted January 12, 2009 Hello, I have problem to make lsp file, that will read vertices of polilyine x,y,z coordinates to txt file with named polyline. I have a bunch of polyline and i need to mark them with name and attach x,y,z coordinates of them. So basicly i need to pick the polilyine, then must ask me the name of polilyine then record in to the txt file with the name and coordinates x,y,z. I have a lot of them so i need to be asked for another polyline and again and again and put to same txt file. any suggestions? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 12, 2009 Share Posted January 12, 2009 Perhaps this? (defun c:plco (/ File oFile pLin pStr nlist pLen wLine) (if (setq File (getfiled "Create a Text File" "C:\\" "txt" 9)) (progn (setq oFile (open file "W")) (while (setq pLin (ssget ":S" (list (cons 0 "LWPOLYLINE,POLYLINE") (cons 410 (getvar "CTAB")) ) ;_ end list ) ;_ end ssget ) ;_ end setq (sssetfirst nil pLin) (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "") (progn (foreach x (entget (ssname pLin 0)) (if (eq 10 (car x)) (setq nlist (cons (cdr x) nlist)) ) ;_ end if ) ;_ end foreach (setq pLen (length nlist)) (while (not (minusp (setq pLen (1- pLen)))) (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2) "," (rtos (cadr (nth pLen nlist)) 2 2) ) ;_ end strcat ) ;_ end setq (if (caddr (nth pLen nlist)) (strcat wLine "," (rtos (caddr (nth pLen nlist)) 2 2)) ) ;_ end if ) ;_ end while (write-line (strcat pStr "\t" wLine) oFile) ) ;_ end progn (princ "\n<!> No Line Name Specified. <!>") ) ;_ end if (sssetfirst nil) ) ;_ end while (close oFile) ) ;_ end progn (princ "\n<!> No File Selected. <!> ") ) ;_ end if (princ) ) ;_ end defun Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 12, 2009 Share Posted January 12, 2009 Sorry, my mistake, initial post would only read first vertex. (defun c:plco (/ File oFile pLin pStr nlist pLen wLine wfLine) (if (setq File (getfiled "Create a Text File" "C:\\" "txt" 9)) (progn (setq oFile (open file "W")) (while (setq pLin (ssget ":S" (list (cons 0 "LWPOLYLINE") (cons 410 (getvar "CTAB"))))) (sssetfirst nil pLin) (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "") (progn (foreach x (entget (ssname pLin 0)) (if (eq 10 (car x)) (setq nlist (cons (cdr x) nlist)))) (setq nlist (reverse nlist) pLen (length nlist) wfLine "") (while (not (minusp (setq pLen (1- pLen)))) (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2) "," (rtos (cadr (nth pLen nlist)) 2 2))) (if (caddr (nth pLen nlist)) (strcat wLine "," (rtos (caddr (nth pLen nlist)) 2 2))) (setq wfLine (strcat wLine "\t" wfLine)) ) ;_ end while (write-line (strcat pStr "\t" wfLine) oFile) ) ;_ end progn (princ "\n<!> No Line Name Specified. <!>") ) ;_ end if (sssetfirst nil) ) ;_ end while (close oFile) ) ;_ end progn (princ "\n<!> No File Selected. <!> ") ) ;_ end if (princ)) Quote Link to comment Share on other sites More sharing options...
CarlB Posted January 12, 2009 Share Posted January 12, 2009 Lee, It doesn't appear this code would work for "polylines"? I see they can be selected, but code seems to use just group code 10 for vertices (so works for 'lwpolylinwes'). To get vertices of a regular (heavyweight) polyline you'll need a different method, such as stepping through with 'entnext'. Seeing that the OP asked for z values as well, he might even want it to work for 3d polylines. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 12, 2009 Share Posted January 12, 2009 Sorry Carl, will sort it. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 12, 2009 Share Posted January 12, 2009 Ok, try this: (defun c:plco (/ File oFile pLin pStr pEnt nlist pLen wLine wfLine vPt wvLine) (if (setq File (getfiled "Create a Text File" "C:\\" "txt" 9)) (progn (setq oFile (open file "W")) (while (setq pLin (ssget ":S" (list (cons 0 "LWPOLYLINE,POLYLINE") (cons 410 (getvar "CTAB"))))) (sssetfirst nil pLin) (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "") (progn (setq pEnt (ssname pLin 0)) (cond ((= "LWPOLYLINE" (cdr (assoc 0 (entget pEnt)))) (foreach x (entget pEnt) (if (eq 10 (car x)) (setq nlist (cons (cdr x) nlist)) ) ;_ end if ) ;_ end foreach (setq nlist (reverse nlist) pLen (length nlist) wfLine "" ) ;_ end setq (while (not (minusp (setq pLen (1- pLen)))) (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2) "," (rtos (cadr (nth pLen nlist)) 2 2) ) ;_ end strcat ) ;_ end setq (setq wfLine (strcat wLine "\t" wfLine)) ) ;_ end while (write-line (strcat pStr "\t" wfLine) oFile) ) ((= "POLYLINE" (cdr (assoc 0 (entget pEnt)))) (setq wvLine "" pEnt (entnext pEnt) ) ;_ end setq (while (/= (cdr (assoc 0 (entget pEnt))) "SEQEND") (setq vPt (cdr (assoc 10 (entget pEnt))) wvLine (strcat (rtos (car vPt) 2 2) "," (rtos (cadr vPt) 2 2) "," (rtos (caddr vPt) 2 2) "\t" wvLine ) ;_ end strcat pEnt (entnext pEnt) ) ;_ end setq ) ;_ end while (write-line (strcat pStr "\t" wvLine) oFile) ) ) ;_ end cond ) ;_ end progn (princ "\n<!> No Line Name Specified. <!>") ) ;_ end if (sssetfirst nil) ) ;_ end while (close oFile) ) ;_ end progn (princ "\n<!> No File Selected. <!> ") ) ;_ end if (princ) ) ;_ end defun Quote Link to comment Share on other sites More sharing options...
iztok13 Posted January 13, 2009 Author Share Posted January 13, 2009 thx Lee Mac, works perfect. This is what i need. thx again Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 13, 2009 Share Posted January 13, 2009 Excellent, glad it worked OK for you. I had to mess around with it a bit to work with 3DPolylines, as I normally only work in 2D - but got it working in the end Quote Link to comment Share on other sites More sharing options...
iztok13 Posted January 27, 2009 Author Share Posted January 27, 2009 Lee mac: sorry it doesnt work like a charm, i notice that if i had a lot of polilys , coordinates get in mess, basicly the first poly is OK then the second poly had 2 times more vertex, i try to corect this but i didnt succses. any idea. & also if can be in front of coordinates the name of poly? thx Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 27, 2009 Share Posted January 27, 2009 I'll have a look at it Quote Link to comment Share on other sites More sharing options...
iztok13 Posted January 27, 2009 Author Share Posted January 27, 2009 o that was fast replay, thx in advance so i have one more wish, if can be every vertex in one line. if i have name of poly : vertex_name and x, y, coordinates vertex_name x y vertex_name x y vertex_name x y vertex_name x y i hope u understand, & again thx in advance Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 27, 2009 Share Posted January 27, 2009 This is a quick fix for the multiple coordinate issue: (defun c:plco (/ File oFile pLin pStr pEnt nlist pLen wLine wfLine vPt wvLine) (if (setq File (getfiled "Create a Text File" "C:\\" "txt" 9)) (progn (setq oFile (open file "W")) (while (setq pLin (ssget "_:S" (list (cons 0 "LWPOLYLINE,POLYLINE") (cons 410 (getvar "CTAB"))))) (sssetfirst nil pLin) (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "") (progn (setq pEnt (ssname pLin 0)) (cond ((= "LWPOLYLINE" (cdr (assoc 0 (entget pEnt)))) (foreach x (entget pEnt) (if (eq 10 (car x)) (setq nlist (cons (cdr x) nlist)) ) ;_ end if ) ;_ end foreach (setq nlist (reverse nlist) pLen (length nlist) wfLine "" ) ;_ end setq (while (not (minusp (setq pLen (1- pLen)))) (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2) "," (rtos (cadr (nth pLen nlist)) 2 2) ) ;_ end strcat ) ;_ end setq (setq wfLine (strcat wLine "\t" wfLine)) ) ;_ end while (write-line (strcat pStr "\t" wfLine) oFile) (setq nlist nil wfLine nil ) ) ((= "POLYLINE" (cdr (assoc 0 (entget pEnt)))) (setq wvLine "" pEnt (entnext pEnt) ) ;_ end setq (while (/= (cdr (assoc 0 (entget pEnt))) "SEQEND") (setq vPt (cdr (assoc 10 (entget pEnt))) wvLine (strcat (rtos (car vPt) 2 2) "," (rtos (cadr vPt) 2 2) "," (rtos (caddr vPt) 2 2) "\t" wvLine ) ;_ end strcat pEnt (entnext pEnt) ) ;_ end setq ) ;_ end while (write-line (strcat pStr "\t" wvLine) oFile) (setq wvLine nil) ) ) ;_ end cond ) ;_ end progn (princ "\n<!> No Line Name Specified. <!>") ) ;_ end if (sssetfirst nil) ) ;_ end while (close oFile) ) ;_ end progn (princ "\n<!> No File Selected. <!> ") ) ;_ end if (princ) ) ;_ end defun But I may consider re-writing this LISP as I am not happy with it. As for the other request - would you like the name of the polyline after all the coordinates? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 27, 2009 Share Posted January 27, 2009 One more question --> Will you only be working with POLYLINES (3D) or will I have to encompass LWPOLYLINES (2d) also? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 27, 2009 Share Posted January 27, 2009 Ok, this is better I think: ;| Polyline Coordinate Writer by Lee McDonnell 27.01.2009 |; (defun c:plco2 (/ File oFile ss eLst Selss pName aEnt vLst i vNme) (vl-load-com) (if (setq File (getfiled "Create a Text File" "C:\\" "txt" 9)) (progn (setq oFile (open File "W")) (if (setq ss (ssget (list (cons 0 "POLYLINE") (if (getvar "CTAB") (cons 410 (getvar "CTAB"))(cons 67 (- 1 (getvar "TILEMODE"))))))) (progn (setq eLst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) Selss (ssadd)) (foreach ent eLst (ssadd ent Selss) (sssetfirst nil Selss) (if (not (setq pName (getstring t "\nSpecify Name for Selected Polyline > "))) (setq pName (vl-princ-to-string ent))) (write-line (strcat "Polyline: " pName "\n\n") oFile) (setq aEnt (entnext ent)) (while (/= "SEQEND" (cdr (assoc 0 (entget aEnt)))) (setq vLst (cons (cdr (assoc 10 (entget aEnt))) vLst) aEnt (entnext aEnt))) (setq i (length vLst) vNme "Vertex No: " vt 1) (while (not (minusp (setq i (1- i)))) (write-line (strcat vNme (rtos vt) "\t" (rtos (car (nth i vLst)) 2 2) "," (rtos (cadr (nth i vLst)) 2 2) "," (rtos (caddr (nth i vLst)) 2 2) "\n") oFile) (setq vt (1+ vt))) (write-line "\n" oFile) (setq vLst nil) (ssdel ent Selss) (sssetfirst nil nil))) (princ "\n<!> No Polyline Selected <!>"))) (princ "\n<!> No File Selected <!>")) (close oFile) (princ "\n...Vertices Written to File...") (princ)) Only works on POLYLINES for the minute, but if you need it expanded I shall write another. Select as many POLYLINES as you like at a time Quote Link to comment Share on other sites More sharing options...
iztok13 Posted January 28, 2009 Author Share Posted January 28, 2009 A big thx for the effort. But this is complitly different from the first one. I will explain: I have normal Polyline not 2d or 3d polys. All polylines are closed. Every single polyiline have a different name. So I need to be ask for each poly what is a name of it. Basicly is somthing like the first lisp you wrote. It s workin only coordinates of the second, thrd ,.., are wrong or they are repeat. I dont now why? Example, if I have four closed normal poly (not 2D or 3D) with name A,B,C and D. A have 4 vertices, B have 4 vertices, C have 7 vertices and D have 3 vertices, the TXT file should looks like that: A x,y A x,y A x,y A x,y B x,y B x,y B x,y B x,y C x,y C x,y C x,y C x,y C x,y C x,y C x,y D x,y D x,y D x,y Here is a preview of example drawing: [/url] A,B,C,D are the name of polys, x and y are coordinates of them. I hope i dont make a lot of trouble for this.. Thx in advance.. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 28, 2009 Share Posted January 28, 2009 Did my other posted LISP not fix the multiple co-ordinate issue? Quote Link to comment Share on other sites More sharing options...
iztok13 Posted January 28, 2009 Author Share Posted January 28, 2009 I didnt try on 3d or 2d polyline, only on normal polyline, when i select the polyline it say nothing selected???? Mybe because is not 2 or 3D poly?? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 28, 2009 Share Posted January 28, 2009 Is can only be a 2D or 3D poly - unless you are working in 4D which I highly doubt... :wink: I am surprised it says nothing selected... could you post a sample drawing in 2000 format that I could work from? Quote Link to comment Share on other sites More sharing options...
iztok13 Posted January 28, 2009 Author Share Posted January 28, 2009 ok, thx here is an example of my drawing of polylines: http://www.2shared.com/file/4743843/d6e1e7a4/polylines.html thx Name of polyline is like this :"SEM-S3-10"...... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 28, 2009 Share Posted January 28, 2009 Ok, Please look at the documents attached and verify that the notepad doc "desired" is what you wish: Desired.txt First Result.txt PLCO2.zip 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.