Jump to content

Add POINT at Pline corners


mousho

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • marko_ribar

    6

  • Grrr

    4

  • sanjeeve

    4

  • mousho

    2

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)
)

Link to comment
Share on other sites

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)
     )
     )
   )
 
    

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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)
)		

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by marko_ribar
code debugged...
Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by Grrr
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...