Lisp for automatically mark a triangle for distance between IP points of polyline curves

Lisp for automatically mark a triangle for distance between IP points of polyline curves

nilesh.bhosale
Advocate Advocate
1,672 Views
21 Replies
Message 1 of 22

Lisp for automatically mark a triangle for distance between IP points of polyline curves

nilesh.bhosale
Advocate
Advocate

I have this lisp i want modify it for marking triangle with dimensions refer attached autocad file ......

 

(defun c:IPMark (/ bulge ptcp pct delta/2 ang chord radius tangent enpi pilst)

(setq en (car (entsel "Select Alignment: "))
lst (listpolb en)
pilst nil
)
(while (> (length lst) 1)
(if (not (zerop (setq bulge (cadar lst))))
(setq ptc (caar lst)
pct (caadr lst)
delta/2 (* (atan bulge) 2.0)
ang (- (angle ptc pct) delta/2)
chord (distance ptc pct)
radius (/ chord (* 2 (sin delta/2)))
tangent (* radius (tan delta/2))
pilst (cons (polar ptc ang tangent) pilst)
enpi (entmakex (list (cons 0 "POINT") (cons 10 (car pilst))))
)
)
(setq lst (cdr lst))
)
(print pilst)
(princ)
)

;; tan From std-lib ;
(defun tan (z / cosz)
(cond ((zerop (rem z pi)) 0.0)
((zerop (rem z (/ pi 2))) 1.7e308)
((zerop (setq cosz (cos z))) 1.7e308)
(t (/ (sin z) cosz))))


;; ;
;; listpolb by ymg ;
;; ;
;; Parameter: en, Entity Name or Object Name ;
;; ;
;; Returns: List of Points and Bulge in WCS ;
;; ;
;; Notes: On Closed Polyline the Last Vertex is Same as First) ;
;; ;

(defun listpolb (en / obj i p l)
(if (= (type en) 'ENAME)
(setq obj (vlax-ename->vla-object en))
(setq obj en en (vlax-vla-object->ename en))
)
(repeat (setq i (fix (vlax-curve-getEndParam en)))
(setq l (cons (list (vlax-curve-getPointAtParam en (setq i (1- i)))
(vla-getbulge obj i)
)
l
)
)
)
(if (= (vla-get-closed obj) :vlax-true)
(append l (list (car l)))
l
)
)

0 Likes
Accepted solutions (2)
1,673 Views
21 Replies
Replies (21)
Message 2 of 22

Kent1Cooper
Consultant
Consultant

An interesting concept....  But there's something wrong at IP-8.  All the other IPs are APParent intersections between two line segments on either side of an arc segment [whose midpoint is near the IP].  But IP-8 is at a vertex between line segments, with no arc segment in the neighborhood.  If both situations are possible, it's a hugely more complex problem than if every IP is like the others, off the Polyline near the midpoint of an arc segment that is flanked by two line segments.

Kent Cooper, AIA
0 Likes
Message 3 of 22

nilesh.bhosale
Advocate
Advocate

The dimension of 1st IP & the Last IP point on polyline need to be taken from the start of the polyline and the end of the polyline respectively 

 

 

0 Likes
Message 4 of 22

nilesh.bhosale
Advocate
Advocate

The drawing is updated, it was a mistake there will be always a curve on polyline

0 Likes
Message 5 of 22

Sea-Haven
Mentor
Mentor

Having done road design for to many years it is a common thing to not put a curve between changes of grade, where the change is less than a certain value, you would not do it on a freeway but a low speed road can push up to about 2% with no curve, so Kent your right would be a problem as no curve. Talking about curves in road design they are normally not curves but rather "Vertical Curve" which is a parabola. The road surface is normally a pline with short segments to reflect the parabola. So again finding the IP is a problem.

 

The poster refers to Vertical so its not a horizontal alignment.

0 Likes
Message 6 of 22

nilesh.bhosale
Advocate
Advocate

This is not road layout this is for mining bulk materials handling technological layouts so it is a different concept I need to mark triangle of IP for curves marked on polyline as shown in attached drawing

0 Likes
Message 7 of 22

Sea-Haven
Mentor
Mentor

Ok

0 Likes
Message 8 of 22

CADaSchtroumpf
Advisor
Advisor

A try with this...

The list returned by code is inclined, horizontal ans vertical dimension.

For continued you can use a block with attributes filled in by the list of values

(vl-load-com)
(defun c:IPMark ( / js AcDoc n ename obj pr dist_start dist_end pt_start pt_end seg_len seg_bulge rad alpha pt_vtx lst_pt)
  (princ "\nSelect Alignment: ")
  (while (null (setq js (ssget "_+.:E:S" '((0 . "LWPOLYLINE")))))
    (princ "\nIsn't a polyline!")
  )
  (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-StartUndoMark AcDoc)
  (setq
    ename (ssname js 0)
    obj (vlax-ename->vla-object ename)
    pr -1
  )
  (repeat (fix (vlax-curve-getEndParam obj))
    (setq
      dist_start (vlax-curve-GetDistAtParam obj (setq pr (1+ pr)))
      dist_end (vlax-curve-GetDistAtParam obj (1+ pr))
      pt_start (vlax-curve-GetPointAtParam obj pr)
      pt_end (vlax-curve-GetPointAtParam obj (1+ pr))
      seg_len (- dist_end dist_start)
      seg_bulge (vla-GetBulge obj pr)
    )
    (if (not (zerop seg_bulge))
      (setq
        rad (/ seg_len (* 4.0 (atan seg_bulge)))
        alpha (+ (angle pt_start pt_end) (- (* pi 0.5) (* 2.0 (atan seg_bulge))))
        pt_vtx (polar pt_start (- alpha (* pi 0.5)) (* rad (/ (sin (* 2.0 (atan seg_bulge))) (cos (* 2.0 (atan seg_bulge))))))
        lst_pt (cons pt_vtx lst_pt)
      )
    )
  )
  (cond
    (lst_pt
      (mapcar '(lambda (x) (entmakex (list (cons 0 "POINT") (cons 10 x)))) lst_pt)
      (print (mapcar '(lambda (x y) (list (distance x y) (- (car x) (car y)) (- (cadr y) (cadr x)))) lst_pt (cdr lst_pt)))
    )
  )
  (vla-EndUndoMark AcDoc)
  (prin1)
)
0 Likes
Message 9 of 22

john.uhden
Mentor
Mentor

Finding the IP, or PI, or PVI is all the same to me.

It's just the intersection of the straight tangents.

It doesn't matter whether they are connected by a circular curve or a parabola.

In fact, relying on the bulge value can be erroneous if the curve is not tangent.

John F. Uhden

0 Likes
Message 10 of 22

nilesh.bhosale
Advocate
Advocate

yes it is working and showing results in List (by pressing F2 command)

but i am unable to make attribute blocks with filled to put these values in triangle form in the drawing.

i have attached here the drawing where i have tested this code  

 

 

0 Likes
Message 11 of 22

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Try this

If the block doesn't exist it's created

You can move the block if the insertion isn't not at good place (middle point bettwen of the IP by defaut)

0 Likes
Message 12 of 22

nilesh.bhosale
Advocate
Advocate

Amazing...!!!

 

Dear Sir,

Thank you very much this is fabulous working perfectly fine

 

thanks again

 

0 Likes
Message 13 of 22

nilesh.bhosale
Advocate
Advocate

i cant resist myself to ask further more...,

 

can i get the angle also, along with the this triangle?? (sin@) of right angle triangle formed from IP points?

 

sample file attached 

0 Likes
Message 14 of 22

john.uhden
Mentor
Mentor

@nilesh.bhosale and @CADaSchtroumpf 

I'm not sure what was supposed to happen, but I must caution you again that the bulge does not necessarily tell you where the PI is, as the curve may not be tangent at both ends.  That's what we call a "broken back curve."  You should intersect the previous and subsequent straight tangents.

John F. Uhden

0 Likes
Message 15 of 22

CADaSchtroumpf
Advisor
Advisor

@john.uhden 

You're right, but when we do road design (which seems to be the case), we avoid making non-tangent connections or you given it a good steering wheel !)🤕

0 Likes
Message 16 of 22

john.uhden
Mentor
Mentor
@CADaSchtroumpf

I am a civil as well, and would nver create a broken back curve, but ,hey,
you never know what someone else may have done before you got the drawing.
Like today I studied the site photos and found that the sanitary manhole is
actually a DOT manhole and that the nearby sanitary manhole was never
located. Now the field crew has to go back out and locate it. 😕

John F. Uhden

0 Likes
Message 17 of 22

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Before test in your drawing, you must erase all INSERT with name "BLK_MEASURE_CURVE"

Purge this block and after test the lisp.

0 Likes
Message 18 of 22

CADaSchtroumpf
Advisor
Advisor

@john.uhden 

You just have to have common sense! ...
Applying your method will complicate the code a lot and in the event of a counter curve without a straight element between, how do we do it (especially if they are broken)?
For me both methods have their flaws.

0 Likes
Message 19 of 22

john.uhden
Mentor
Mentor
@CADaSchtroumpf
Complicated code is the name of my game. I could show you some of my
larger works, but it would create nausea. 😱
But you are correct... the user must eliminate the flaws before using code
that expects flawless conditions.

John F. Uhden

0 Likes
Message 20 of 22

CADaSchtroumpf
Advisor
Advisor

@john.uhden  a écrit :
@CADaSchtroumpf
Complicated code is the name of my game. I could show you some of my
larger works, but it would create nausea. 😱


@john.uhden 

This is also my case, I made routines for AutocadMap which automatically calculate and fill OjectData.

It took me a lot time to develop them, but they enabled me to establish a functional GIS (from A to Z) in record time.

They are so specific that I will certainly never publish them because to make them generic there would still be a lot of work.

0 Likes