mousho Posted April 6, 2016 Share Posted April 6, 2016 I hope that someone can help me. im looking for a lisp that will add a points at each corner/intersection of Pline. Thanks ahead. Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted April 6, 2016 Share Posted April 6, 2016 im looking for a lisp that will add a points at each corner/intersection of Pline. See this thread: http://www.cadtutor.net/forum/showthread.php?46891-Insert-a-point-at-each-vertex-of-selected-polys Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 7, 2016 Share Posted April 7, 2016 Are there arcs ? So need inters pt ? Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted April 7, 2016 Share Posted April 7, 2016 Test to see if it needs debugging... (defun c:verts2pts ( / sspl i pl vertl v ptlst ) (prompt "\nSelect polyline type curves to process...") (setq sspl (ssget '((0 . "*POLYLINE")))) (while (not sspl) (prompt "\nEmpty sel.set... Please select polyline type curves to process again...") (setq sspl (ssget '((0 . "*POLYLINE")))) ) (repeat (setq i (sslength sspl)) (setq pl (ssname sspl (setq i (1- i)))) (if (= (cdr (assoc 0 (entget pl))) "LWPOLYLINE") (setq vertl (mapcar '(lambda ( p ) (trans (list (car p) (cadr p) (cdr (assoc 38 (entget pl)))) pl 0)) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= (car x) 10)) (entget pl)) ) ) ) (progn (setq v pl) (while (= (cdr (assoc 0 (entget (setq v (entnext v))))) "VERTEX") (setq vertl (cons (cdr (assoc 10 (entget v))) vertl)) ) (setq vertl (reverse vertl)) ) ) (setq ptlst (cons vertl ptlst)) ) (setq ptlst (apply 'append (reverse ptlst))) (foreach p ptlst (entmake (list '(0 . "POINT") (cons 10 p) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
mousho Posted April 7, 2016 Author Share Posted April 7, 2016 thanks to all marko the lisp work perfect rkmcswain the thread help me to Quote Link to comment Share on other sites More sharing options...
samifox Posted April 8, 2016 Share Posted April 8, 2016 can you please review my demo. this lisp attend to post points at line ends (defun demo(/ x s) (setvar "pdmode" 34) (defun createPoint (p) (entmake (list (cons 0 "POINT") ;*** (cons 6 "BYLAYER") (cons 8 "0") (cons 10 p) ;*** (cons 39 0.0) (cons 50 0.0) (cons 62 256) (cons 210 (list 0.0 0.0 1.0)) ) ) ) (if (setq x (entget(car(entsel)))) (progn (setq s (cons (cadr(assoc 10 x))s) s (cons(cadr(assoc 11 x))s) ) (apply 'createPoint s) ) ) ) Quote Link to comment Share on other sites More sharing options...
sanjeeve Posted April 9, 2016 Share Posted April 9, 2016 This lisp could be very handy if any can change this to insert points for line end instead of pline.is it possible anybody please. Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted April 9, 2016 Share Posted April 9, 2016 This lisp could be very handy if any can change this to insert points for line end instead of pline.is it possible anybody please. So simple... (defun c:lineends2pts ( / ss i li p1 p2 ) (prompt "\nSelect line entities...") (setq ss (ssget '((0 . "LINE")))) (while (not ss) (prompt "\nEmpty sel.set... Please select line entities again...") (setq ss (ssget '((0 . "LINE")))) ) (repeat (setq i (sslength ss)) (setq li (ssname ss (setq i (1- i)))) (setq p1 (cdr (assoc 10 (entget li))) p2 (cdr (assoc 11 (entget li)))) (entmake (list '(0 . "POINT") (cons 10 p1) ) ) (entmake (list '(0 . "POINT") (cons 10 p2) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Grrr Posted April 9, 2016 Share Posted April 9, 2016 Hi Marko, I tried to modify your code, to add the midpoints of the segments. Can't figure out whats wrong with it: (defun c:test ( / sspl i pl vertl v ptlst ) (prompt "\nSelect polyline type curves to process...") (setq sspl (ssget '((0 . "*POLYLINE")))) (while (not sspl) (prompt "\nEmpty sel.set... Please select polyline type curves to process again...") (setq sspl (ssget '((0 . "*POLYLINE")))) ) (repeat (setq i (sslength sspl)) (setq pl (ssname sspl (setq i (1- i)))) (if (= (cdr (assoc 0 (entget pl))) "LWPOLYLINE") (setq vertl (mapcar '(lambda ( p ) (trans (list (car p) (cadr p) (cdr (assoc 38 (entget pl)))) pl 0)) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= (car x) 10)) (entget pl)) ) ) ) (progn (setq v pl) (while (= (cdr (assoc 0 (entget (setq v (entnext v))))) "VERTEX") (setq vertl (cons (cdr (assoc 10 (entget v))) vertl)) ) (setq vertl (reverse vertl)) ) ) (setq ptlst (cons vertl ptlst)) ) (setq ptlst (apply 'append (reverse ptlst))) (setq step 0) (foreach p ptlst (command "_.POINT" p) (setq midpt (mid (nth step '(ptlst)) (nth (+ step 1) '(ptlst)) ) ) (command "_.POINT" midpt) ) (princ) ) ;gile (defun mid (p1 p2) (mapcar '(lambda (x1 x2) (/ (+ x1 x2) 2.0)) p1 p2) ) Quote Link to comment Share on other sites More sharing options...
sanjeeve Posted April 9, 2016 Share Posted April 9, 2016 So simple... (defun c:lineends2pts ( / ss i li p1 p2 ) (prompt "\nSelect line entities...") (setq ss (ssget '((0 . "LINE")))) (while (not ss) (prompt "\nEmpty sel.set... Please select line entities again...") (setq ss (ssget '((0 . "LINE")))) ) (repeat (setq i (sslength ss)) (setq li (ssname ss (setq i (1- i)))) (setq p1 (cdr (assoc 10 (entget li))) p2 (cdr (assoc 11 (entget li)))) (entmake (list '(0 . "POINT") (cons 10 p1) ) ) (entmake (list '(0 . "POINT") (cons 10 p2) ) ) ) (princ) ) Thanks it is working, May be I am asking too much sorry for that. is there a way to make these points in sequence order because when coordinate first insert point get 1. 2nd get 2 I want my numbers sequence Thanks again Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted April 9, 2016 Share Posted April 9, 2016 (edited) Hi Marko,I tried to modify your code, to add the midpoints of the segments. Can't figure out whats wrong with it: ... Try this... (defun c:verts2pts ( / sspl i pl k p mp vertl ptlst ) (vl-load-com) (prompt "\nSelect polyline type curves to process...") (setq sspl (ssget '((0 . "*POLYLINE")))) (while (not sspl) (prompt "\nEmpty sel.set... Please select polyline type curves to process again...") (setq sspl (ssget '((0 . "*POLYLINE")))) ) (repeat (setq i (sslength sspl)) (setq pl (ssname sspl (setq i (1- i)))) (setq k -1) (repeat (fix (1+ (vlax-curve-getendparam pl))) (setq p (vlax-curve-getpointatparam pl (setq k (1+ k)))) (setq vertl (cons p vertl)) (if (< k (vlax-curve-getendparam pl)) (progn (setq mp (vlax-curve-getpointatparam pl (+ k 0.5))) (setq vertl (cons mp vertl)) ) ) ) (setq vertl (reverse vertl)) (setq ptlst (cons vertl ptlst)) ) (setq ptlst (apply 'append (reverse ptlst))) (foreach p ptlst (entmake (list '(0 . "POINT") (cons 10 p) ) ) ) (princ) ) HTH, M.R. Edited April 20, 2016 by marko_ribar code debugged... Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted April 9, 2016 Share Posted April 9, 2016 Thanks it is working, May be I am asking too much sorry for that. is there a way to make these points in sequence order because when coordinate first insert point get 1. 2nd get 2 I want my numbers sequence Thanks again We don't know what is correct sequence... Explain what do you want - to label those points ? BTW. My name is Marko, not Mark... Quote Link to comment Share on other sites More sharing options...
Grrr Posted April 9, 2016 Share Posted April 9, 2016 Try this... (defun c:verts2pts ( / sspl i pl k p mp vertl ptlst ) (vl-load-com) (prompt "\nSelect polyline type curves to process...") (setq sspl (ssget '((0 . "*POLYLINE")))) (while (not sspl) (prompt "\nEmpty sel.set... Please select polyline type curves to process again...") (setq sspl (ssget '((0 . "*POLYLINE")))) ) (repeat (setq i (sslength sspl)) (setq pl (ssname sspl (setq i (1- i)))) (setq k -1) (repeat (1+ (vlax-curve-getendparam pl)) (setq p (vlax-curve-getpointatparam pl (setq k (1+ k)))) (setq vertl (cons p vertl)) (setq mp (vlax-curve-getpointatparam pl (+ k 0.5))) (setq vertl (cons mp vertl)) ) (setq vertl (reverse vertl)) (setq ptlst (cons vertl ptlst)) ) (setq ptlst (apply 'append (reverse ptlst))) (foreach p ptlst (entmake (list '(0 . "POINT") (cons 10 p) ) ) ) (princ) ) HTH, M.R. Marko, I get: Error: bad argument type: fixnump: 7.0 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 9, 2016 Share Posted April 9, 2016 Marko, I get: Error: bad argument type: fixnump: 7.0 Have a look at the following LINK to fix the error by yourself. Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted April 9, 2016 Share Posted April 9, 2016 I fixed it with (fix) function... Thanks for heads up... Quote Link to comment Share on other sites More sharing options...
Grrr Posted April 9, 2016 Share Posted April 9, 2016 So the whole problem was that "repeat" requires an integer ? Thanks for trying to help, Tharwat! Still IDK if you were hinting me for vla-object conversion, but I've found this line from Marko: ;; (vlax-ename->vla-object pl) ;; - unnecessary line (vlax-curve-xxx) functions work with both 'ename and 'vla-object, but it's better to use 'ename because it's faster approach and with less typing I wanted to ask you guys is there a method where you find where exactly a program crashes, so you repair it quickly. And also is there a way to trace check what each line of the code returned? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 9, 2016 Share Posted April 9, 2016 Grrr, The function vlax-curve-getendparam would return a real number representing the number of param and repeat function as you already asked and the answer to your question is YES , repeat function requires an Integer type of variable or an integer number. For me when I encounter program crashes I try to analyze the message first then I re-read the codes once again very carefully and that should lead to a solution. In regard to your last question, try to debug your codes when you are unsure where the breakdown of your codes is SEE THIS TUTORIAL Quote Link to comment Share on other sites More sharing options...
Grrr Posted April 9, 2016 Share Posted April 9, 2016 (edited) Thanks, Tharwat! I often check the Error Message Troubleshooter from LM's website, and almost everytime I have his kind of error: argument has been passed an argument of incorrect data type. Ofcourse the ACAD help file with AutoLISP functions helps alot, If I knew in which rows might be the problem. The solution I had was by commenting different parts from the code and to see if the rest of it works. I'll try to use VLIDE now to see how it goes (currently I'm on Notepad++). EDIT: I just tested on debugging Marko's broken version of the code, stopped on the repeat as expected. (couldn't add watch to any variable to see why it failed) Fixed it and continued: there was a 2nd break on error on the entmake function with error: Error: bad DXF group: (10) Here I watched the P and PTLST variables: P = (32.1364 190.604 0.0) PTLST = ((32.1364 190.604 0.0) (109.457 224.887 0.0) (186.777 259.169 0.0) (252.118 229.784 0.0) (317.459 200.399 0.0) nil nil (317.459 200.399 0.0) (252.118 229.784 0.0) (186.777 259.169 0.0) (109.457 224.887 0.0) (32.1364 190.604 0.0) ... ) Two polylines were selected, and it appears that (cons 10 p) at some point within the foreach function returns (10), maybe when the lists switches to the next pline. Well I did my first debugging of a code, and it seems easier to answer "Where did the code fail?", rather than "Why did the code fail?" I'll continue practicing and I hope I'm doing this right. Edited April 9, 2016 by Grrr Quote Link to comment Share on other sites More sharing options...
sanjeeve Posted April 15, 2016 Share Posted April 15, 2016 We don't know what is correct sequence... Explain what do you want - to label those points ?BTW. My name is Marko, not Mark... Hi Marko sorry I am asking too much is it possible to change insert points to the intersection for lines, that may be solve my sequence problem. Thanks Quote Link to comment Share on other sites More sharing options...
sanjeeve Posted April 19, 2016 Share Posted April 19, 2016 Hi Marko sorry I am asking too much is it possible to change insert points to the intersection for lines, that may be solve my sequence problem. Thanks still I am waiting 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.