SlopeSilviu Posted April 13, 2011 Posted April 13, 2011 I need a LISP that extracts "Length" and "Angle" from multiple lines, so I can transfer them in a word/excel format. I would of used _DATAEXTRACTION, but here at the office we use AutoCAD 2006, and as some may know, AutoCAD 2006 doesn't have the _DATAEXTRACTION option. I my case I have 2D geometric shapes, drawn with polyline only. Also I have a point. I need to draw from that point, lines to every polyline turning and then extract the Length and Angle from those lines. I have a LOT of this kind of shapes daily, so doing this manually every day is a real pain. Here's an image attachment for better understanding my situation. Quote
JohnM Posted April 13, 2011 Posted April 13, 2011 Do all of the lines from the point connect to each vertex of the polyline shape above? Do the collections of lengths and angles have to be in a specific order? Quote
SlopeSilviu Posted April 13, 2011 Author Posted April 13, 2011 Sorry, I forgot to mention this. Every line is independent, drawn from the point to the polyline vertex. EX: -point is X -vertexes are 1,2,3,4,5,6 All lines are drawn from X to 1, next line from X to 2, next line from X to 3, and so on. Quote
Tyke Posted April 13, 2011 Posted April 13, 2011 This question has been recently asked by someone else too. See this link: http://www.cadtutor.net/forum/showthread.php?58199-Extracting-multiple-3d-lengths-for-lines-in-AutoCAD-2007 Also check the similar threads at the bottom of this page. Quote
Tyke Posted April 13, 2011 Posted April 13, 2011 @ SlopeSilviu: Isn't this the same post as your other one? Extracting Length & Angle Getting an idea of what I do: I have the base point X and the secondary points from lets say 1 to 20 (total of 21 points) I draw lines from X to every one of the secondary point (from point X to point 1; from point X to point 2; from point X to point 3; ........from point X to point 20) If you click proprieties on one of the lines, you will see that it has a Length and an Angle. I need to manually copy the length and the angle of every line, and paste it in a table on Excel/Word. Problem: I have about 100 points a day of this kind, so manually copying their length & angle is a real pain. Is there any way faster to do this. A specific command in AutoCad (2006) I was thinking if anyone know a name of a certain LISP, or if someone possess one that can help me with this problem. If I wasn't specific enough, I will submit an example. Quote
SlopeSilviu Posted April 13, 2011 Author Posted April 13, 2011 Approximately, yes, but it has some different base lines. Also I got to the conclusion that only a LISP can help me, so I "remade" a post here. Quote
JohnM Posted April 13, 2011 Posted April 13, 2011 I just threw this together for fun Why not have it do as much as possible. This will draw the lines to each vertex and make a comma-separated file named lineinfo.txt located on “C:\” After running the program open excel and import the txt file. (defun c:mklns (/ pt1 ss ent lsttxt txlst ff) (setq pt1 (getpoint "Pick The Point"));_base point (setq ss (ssget '((0 . "LWPOLYLINE"))));_polyline object (if ss (progn (setq ent (entget(ssname ss 0)));_entity info for poly object (foreach item ent (if (= (car item) 10) (progn (command "pline" pt1 (cdr item) "");_draw lines (setq lsttxt (strcat ;_make comma seperated list of length and angle (rtos(distance pt1 (cdr item))) "," (angtos (angle pt1 (cdr item))0 4) );_strcat );_setq (setq txlst (cons lsttxt txlst));_compiled list of all line length and angles );_progn );_if );_foreach (setq ff (open "C:/LineInfo.txt" "w"));_write to file (foreach item txlst (write-line item ff) );_foreach (close ff) );_progn (alert "No Polyline Object Selected") );_if );_defun Quote
SlopeSilviu Posted April 14, 2011 Author Posted April 14, 2011 Thank you John for the quick reply. I tried to load the LISP, and it does load, but it doesn't do anything, maybe a command line is missing something, or there must be something I don't understand. Here's a picture: I hope it's just me being stupid... Quote
pBe Posted April 14, 2011 Posted April 14, 2011 (defun c:test (/ adoc Pline Xpoint PtList PtAngleList NewLine) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (if (setq Pline (car (entsel "\nSelect Pline:")) Xpoint (getpoint "\nSelect \"X\" Point: ")) (progn (setq PtList (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget Pline)))) (setq PtAngleList (open (strcat (getvar 'Dwgprefix)(vl-filename-base (getvar 'Dwgname)) ".csv") "A")) (foreach Pts (cdr PtList) (setq NewLine (vla-addline (vlax-get (vla-get-activelayout adoc) 'Block) (vlax-3d-point Xpoint) (vlax-3d-point Pts))) (write-line (strcat (rtos (vla-get-length NewLine) 2 2) "," (rtos (vla-get-Angle NewLine) 2 2)) PtAngleList) ) (print PtAngleList) (close PtAngleList) ) ) (princ) ) Quote
Tiger Posted April 14, 2011 Posted April 14, 2011 Thank you John for the quick reply.I tried to load the LISP, and it does load, but it doesn't do anything, maybe a command line is missing something, or there must be something I don't understand. Here's a picture I hope it's just me being stupid... Type MKLNS to run the Lisp after you have loaded it. Quote
JohnM Posted April 14, 2011 Posted April 14, 2011 Copy the code from this post Paste it into notepad Save the notepad as “test.lsp” (use the quotes in the save as dialog to save type as .lsp) In AutoCAD appload the test.lsp Type mklns on the command line Quote
fuccaro Posted April 15, 2011 Posted April 15, 2011 For a quick test: copy the source from the forum and paste it in AutoCAD's command line. Next type the name (klns) to start it. If you saved the lisp file, you may load it using the Appload command, or just drag the file in AutoCAD's drawing area. Quote
pBe Posted April 15, 2011 Posted April 15, 2011 (defun c:test (/ CreateList _grAngle adoc Plines obj cnt ent ObjectPointList PtAngleList Xpoint gr NewLine ) ;;; pBe April 2011 ;;; (vl-load-com) (defun CreateList (p) (setq ObjectPointList (cons (cdr p) ObjectPointList)) ) ;;; Alanjt ;;; (defun _grAngle (a b) (grdraw (trans a 0 1) (cadr gr) 1 -1) (angle a b) ) ;;; ;;; (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (if (setq Plines (ssget ":L" '((0 . "LWPOLYLINE")))) (progn (repeat (setq cnt (sslength Plines)) (setq obj (ssname Plines (setq cnt (1- cnt))) ent (entget obj) ) (mapcar 'CreateList (vl-remove-if-not '(lambda (x) (= (car x) 10)) ent) ) (ssdel obj Plines) ) (if ObjectPointList (progn (setq PtAngleList (open (strcat (getvar 'Dwgprefix)(vl-filename-base (getvar 'Dwgname)) ".csv") "A")) ;;; Alanjt ;;; (while (eq 5 (car (setq gr (grread T 15 0)))) (setq Xpoint (trans (cadr gr) 1 0)) (redraw) (foreach pts ObjectPointList (_grAngle pts Xpoint)) ) ;;; ;;; (redraw) (foreach itm ObjectPointList (setq NewLine (vla-addline (vlax-get (vla-get-activelayout adoc) 'Block) (vlax-3d-point Xpoint) (vlax-3d-point itm) ) ) (write-line (strcat (rtos (vla-get-length NewLine) 2 2) "," (rtos (vla-get-Angle NewLine) 2 2)) PtAngleList) ) (close PtAngleList) ) ) ) ) (princ) ) Quote
Lee Mac Posted April 15, 2011 Posted April 15, 2011 pBe, Some constructive criticism, I hope it helps: note that there is no need for the angle calculation within the grRead loop, since you are not using the return of '_grAngle', also, it might be quicker to use the distance and angle functions when measuring the length and angle of the lines. This is how I might go about it: (defun c:test ( / e fl gr i pt pu pw ss ) (if (and (setq ss (ssget '((0 . "LWPOLYLINE")))) (setq fl (getfiled "Output File" "" "csv" 1)) ) (progn (repeat (setq i (sslength ss)) (foreach x (entget (setq e (ssname ss (setq i (1- i))))) (if (= 10 (car x)) (setq pw (cons (trans (cdr x) e 0) pw) pu (cons (trans (cdr x) e 1) pu) ) ) ) ) (while (= 5 (car (setq gr (grread t 13 0)))) (redraw) (setq pt (cadr gr)) (foreach x pu (grdraw x pt 1 -1)) ) (setq pt (trans pt 1 0)) (if (setq fl (open fl "w")) (progn (foreach x pw (entmakex (list (cons 0 "LINE") (cons 10 x) (cons 11 pt))) (write-line (strcat (rtos (distance pt x)) "," (angtos (angle pt x))) fl) ) (close fl) ) ) ) ) (redraw) (princ) ) Quote
pBe Posted April 16, 2011 Posted April 16, 2011 Your criticism does help a lot and always welcome. I was wondering back then why i keep getting an error after (while... grread...) line using (cond...) . thanks for the heads up. I was thinking of eliminating the creation of the LINE altogether and used distance and angels from the point list since the purpose of the code is to write datas into a file. I recognized the value of your criticism Lee. Tnaks a mil Quote
pBe Posted April 17, 2011 Posted April 17, 2011 (edited) To eliminate the issue of not being able to use running osnap (defun c:test ( / e fl gr i pt pu pw ss Op accept ) (if (and (setq ss (ssget '((0 . "LWPOLYLINE")))) (setq fl (getfiled "Output File" "" "csv" 1)) ) (progn (repeat (setq i (sslength ss)) (foreach x (entget (setq e (ssname ss (setq i (1- i))))) (if (= 10 (car x)) (setq pw (cons (trans (cdr x) e 0) pw) pu (cons (trans (cdr x) e 1) pu) ) ) ) ) [color=blue](while (not accept) [/color] [color=darkolivegreen] (setq pt (getpoint "\nSelect Point: ") op nil) [/color] [color=blue] (foreach x pu (grdraw x pt 1 -1))[/color] [color=blue] (while (not (member Op '(97 32))) [/color] [color=blue] (princ "\n<A>ccept Spacebar for other point")(princ)[/color] [color=blue] (setq Op (cadr (grread))))[/color] [color=blue] (if ( = Op 97)(setq accept T))[/color] [color=blue] (redraw))[/color] [color=darkolivegreen](setq pt (trans pt 1 0))[/color] (if (setq fl (open fl "w")) (progn (foreach x pw (entmakex (list (cons 0 "LINE") (cons 10 x) (cons 11 pt))) (write-line (strcat (rtos (distance pt x)) "," (angtos (angle pt x))) fl) ) (close fl) ) ) ) ) (redraw) (princ) ) Edited April 17, 2011 by pBe Trans function location Quote
Lee Mac Posted April 17, 2011 Posted April 17, 2011 Nice idea! Beware of (trans nil) and also that grdraw uses UCS points Another way might be to use getkword: (defun c:test ( / e fl gr go i pt pu pw ss ) (if (and (setq ss (ssget '((0 . "LWPOLYLINE")))) (setq fl (getfiled "Output File" "" "csv" 1)) ) (progn (repeat (setq i (sslength ss)) (foreach x (entget (setq e (ssname ss (setq i (1- i))))) (if (= 10 (car x)) (setq pw (cons (trans (cdr x) e 0) pw) pu (cons (trans (cdr x) e 1) pu) ) ) ) ) (while (and (not go) (setq pt (getpoint "\nSpecify Point: "))) (redraw) (foreach x pu (grdraw x pt 1 -1)) (initget "Yes No") (setq go (/= "No" (getkword "\nAccept Point? [Yes/No] <Yes>: "))) ) (if (and pt (setq fl (open fl "w"))) (progn (setq pt (trans pt 1 0)) (foreach x pw (entmakex (list (cons 0 "LINE") (cons 10 x) (cons 11 pt))) (write-line (strcat (rtos (distance pt x)) "," (angtos (angle pt x))) fl) ) (close fl) ) ) ) ) (redraw) (princ) ) Quote
pBe Posted April 17, 2011 Posted April 17, 2011 Nice idea!Beware of (trans nil) and also that grdraw uses UCS points Your dead-on about the trans Lee (modified the code) tnx Can you explain to me the horrors of Grdraw with regards to UCS points Quote
Lee Mac Posted April 17, 2011 Posted April 17, 2011 Your dead-on about the trans Lee (modified the code) tnx Can you explain to me the horrors of Grdraw with regards to UCS points Thats better Sorry, what do you mean about the 'horrors of Grdraw with regards to UCS points'? 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.