Jump to content

Get '(42 . x) at Param in list data lwpolyline


limfx

Recommended Posts

'42' is a part of each segment in the polyline, so there might be many of then in the description

 

Usually the assoc function will get unique data or the first occurrence in a list, for example

 

(cdr (assoc 42 (entget (car (entsel)))))

 

will get the first occurance. OF course reverse the list to get the last:

(cdr (assoc 42 (reverse (entget (car (entsel))))))

 

And in between these something like mAssoc will return the list of all of them - I tend to use Lee Macs, I trust what he posts generally. In this case 'key' will be 42 and lst will be  the entity definition list from for example (entget (car (entsel)))

 

 

Link to comment
Share on other sites

2 hours ago, Steven P said:

'42' is a part of each segment in the polyline, so there might be many of then in the description

 

Usually the assoc function will get unique data or the first occurrence in a list, for example

 

(cdr (assoc 42 (entget (car (entsel)))))

 

will get the first occurance. OF course reverse the list to get the last:

(cdr (assoc 42 (reverse (entget (car (entsel))))))

 

And in between these something like mAssoc will return the list of all of them - I tend to use Lee Macs, I trust what he posts generally. In this case 'key' will be 42 and lst will be  the entity definition list from for example (entget (car (entsel)))

 

 

Thank you very much!

Link to comment
Share on other sites

I am writing a lisp to create a circular arc for a pline according to a given radius R. I originally intended to "entmod bulge" with Get '(42 . x) at Param in list data lwpolyline; but things are not as simple as I thought.
So I went in another direction. Can someone help me complete the lisp I'm writing for the purpose as shown below. Sincerely thank you!

image.thumb.png.dc8ff093e4e7fcb3361fcb2fd21281d3.png

(defun c:BOR ()
  (while (setq pl (entsel "\nSelect pline: "))
  (setq r (getR))
  (setq plo (vlax-ename->vla-object (car pl)))
  (setq pt (vlax-curve-getclosestpointto plo (cadr pl)))
  (setq n (vlax-curve-getparamatpoint plo pt))
  (setq p2 (vlax-curve-getpointatparam plo (setq par (fix (+ 0.5 n)))))
  (setq p1 (vlax-curve-getpointatparam plo (1- par)))
  (setq l21 (- (vlax-curve-getDistAtPoint plo p2) (vlax-curve-getDistAtPoint plo p1)))
  (setq p3 (vlax-curve-getpointatparam plo (1+ par)))
  (setq l32 (- (vlax-curve-getDistAtPoint plo p3) (vlax-curve-getDistAtPoint plo p2)))
  (setq ang ((lambda (a) (min a (- (+ pi pi) a)))
      (rem (+ pi pi (- (angle p2 p1) (angle p2 p3))) (+ pi pi))
  ))
  (setq ang (/ ang 2))
  (setq lr (/ r (/ (sin ang) (cos ang))))
  (while (or (> lr l21) (> lr l32))
    (progn
      (alert "\nR too big, Enter again R: ")
      (setq r (getR))
      (setq lr (/ r (/ (sin ang) (cos ang))))
    );progn
  );if
	 
  ;(setq lr (* r (atan (/ ang 2))))
  (setq p1t (polar p2 (angle p2 p1) lr))
  (setq p3t (polar p2 (angle p2 p3) lr))
  (setq ptem (mapcar '(lambda (x y) (/ (+ x y) 2)) p1t p3t))
  (setq Lr (sqrt (+ (expt lr 2) (expt r 2))))
  (setq p2t (polar p2 (angle p2 ptem) (- Lr r)))
  (setq bulge ((lambda ( a ) (/ (sin a) (cos a))) (/ (+ (- pi (angle p2t p1t)) (angle p2t p3t)) 2)))
  (setq ocs (trans '(0 0 1) 1 0 t))
  (entmake
            (list
               '(000 . "LWPOLYLINE")
               '(100 . "AcDbEntity")
               '(100 . "AcDbPolyline")
               '(090 . 2)
               '(070 . 0)
                (cons 038 (caddr (trans p1t 1 ocs)))
                (cons 010 (trans p1t 1 ocs))
                (cons 042 bulge)
                (cons 010 (trans p3t 1 ocs))
                (cons 210 ocs)
            )
        )
  );while  
  (print "limfx")
);end

(defun getR ()
  (if r (setq rm (getreal (strcat "\nRadius <" (rtos r 2 1) ">: "))) (setq r (getreal "\n\nEnter radius <1>: ")))
  (if (not r) (setq r 1) (if (not rm) (setq r r) (setq r rm)))
);end

 

Link to comment
Share on other sites

If I understand , so you want 2 plines ? If so easy copy pline to right fixed amount, fillet "polyline" so arcs are created, move pline back to left All done. No code needed.

 

Else make it clearer what you want.

Edited by BIGAL
Link to comment
Share on other sites

BiGAl (Weekend and my CAD is off so haven't checked) but I think the OP has a LISP that fillets the corners and now wants the reverse to unfillet the corners

Link to comment
Share on other sites

image.png.feb522d921c4eacd67c92a61521432dd.pngimage.png.770196c4c06e844f5ba7b81a8aa05a31.png

Lisp creates circular arcs with different optional radii at the pline vertices that I pick. My goal is to create a continuous pline and two blue vertex lines as shown.

 

Link to comment
Share on other sites

"two blue green vertex lines as shown". Yes / No ?

 

This is road alignment stuff IP required. 

 

Just thinking get vertices before add radius. Pline = 4 points.

Add radius's Pline vertices now 6 points. 

Should be able to do some form of join correct points, only problem I see is where two straights do not have a radius between.

image.thumb.png.2b9b8296bba93dbb896acc5c37e67afa.png

; https://www.cadtutor.net/forum/topic/78649-get-42-x-at-param-in-list-data-lwpolyline/

(defun c:step1 ( / plent)
(setq plent (entsel "\nPick pline step 1"))
(if plent (setq co-ord1 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
(princ co-ord1)
(prompt "\nAdd your radius then run step2 ")
(princ)
)

(defun c:step2 ( / plent)
(setq plent (entsel "\nPick pline after radius step 2 "))
(if plent (setq co-ord2 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
(princ co-ord2)
; (setvar 'clayer "yourlayer")
(setq x 1 y 1)
(repeat (- (length co-ord1) 2)
(command "line" (nth x co-ord2) (nth y co-ord1)(nth  (1+ x) co-ord2) "")
(setq x (+ x 2) y (1+ y))
)

 

Edited by BIGAL
  • Like 1
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...