Author Topic: Help - Lisp drawing polyline by degree between two parallel  (Read 2797 times)

0 Members and 1 Guest are viewing this topic.

mihaibantas

  • Mosquito
  • Posts: 5
Help - Lisp drawing polyline by degree between two parallel
« on: April 19, 2018, 03:17:03 AM »
Hello everyone, I am new to the lisp world and this forum. I have huge request if someone can help me with a code.
I want to join two parallel polylines/lines by a polyline/line drawn automatically to a certain degree.

I've attached a dwg / jpg file for example.

Thanks in advance for your time...have a good day

Dlanor

  • Bull Frog
  • Posts: 263
Re: Help - Lisp drawing polyline by degree between two parallel
« Reply #1 on: April 19, 2018, 07:43:13 AM »
Quick mashup. Minimal checking. If required you can change the angle of the lines, but these must be in degrees or decimal degrees.

There is also scope to add the new lines to the red polyline.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun rh:select_ent ( pmt / rtn )
  3.   (setq rtn (car (entsel pmt)))
  4. );end_defun
  5.  
  6. (defun rh:D2R (d) (* pi (/ d 180.0)))
  7.  
  8. (defun rh:draw_line (spc s_pnt e_pnt ang dist / line t_pnt)
  9.   (if (and (not ang) (not dist) e_pnt)
  10.     (setq line (vla-AddLine spc (vlax-3D-point s_pnt) (vlax-3D-point e_pnt)))
  11.     (setq t_pnt (polar s_pnt (rh:D2R ang) dist)
  12.           line (vla-AddLine spc (vlax-3D-point s_pnt) (vlax-3D-point t_pnt))
  13.     );end_setq
  14.   );end_if
  15. );end_defun      
  16.  
  17. (defun rh:intersect_pt (ent1 ent2 / int_pt rtn)
  18.   (setq int_pt (vlax-invoke-method ent1 'IntersectWith ent2 acExtendNone))
  19.   (if (/= -1 (vlax-safearray-get-u-bound (vlax-variant-value int_pt) 1))
  20.     (setq rtn (vlax-safearray->list (vlax-variant-value int_pt)))
  21.     (setq rtn nil)
  22.   );end_if
  23. );end_defun
  24.  
  25. (defun c:test ( / *error* c_doc ms r_ent g_ent rs_pnt re_pnt left right ans t_line i_pt l_line r_line)
  26.  
  27.   (defun *error* ( msg )
  28.     (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
  29.     (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
  30.     (princ)
  31.   );_end_*error*_defun
  32.        
  33.         ms (vla-get-modelspace c_doc)
  34.         l_ang 214                       ;<<======= Real angle of left line in degrees (180 + required angle)
  35.         r_ang 326                       ;<<======= Real angle of right line in degrees (0 - required angle)
  36.         r_ent (rh:select_ent "\nSelect Red Polyline : ")
  37.         g_ent (rh:select_ent "\nSelect Green Polyline : ")
  38.         rs_pnt (vlax-curve-getstartpoint r_ent)
  39.         re_pnt (vlax-curve-getendpoint r_ent)
  40.   );end_setq
  41.  
  42.   (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-endundomark c_doc))
  43.         (vla-startundomark c_doc)
  44.  
  45.   (if (> (car rs_pnt) (car re_pnt))
  46.     (setq left re_pnt
  47.           right rs_pnt
  48.     );end_setq
  49.     (setq left rs_pnt
  50.           right re_pnt
  51.     );end_setq
  52.   );end_if
  53.   (initget "Left Right Both")
  54.   (setq ans (getkword "\nDraw Connecting Line to End [Left Right Both] : "))  ;<<== Pressing L,P or B upper or lower case will select correctly
  55.   (cond ( (= ans "Left")
  56.           (setq t_line (rh:draw_line ms left nil l_ang 50))
  57.           (setq i_pt (rh:intersect_pt t_line (vlax-ename->vla-object g_ent)))
  58.           (vla-delete t_line)
  59.           (setq l_line (rh:draw_line ms left i_pt nil nil))
  60.         );end_=Left
  61.        ( (= ans "Right")
  62.           (setq t_line (rh:draw_line ms right nil r_ang 50))
  63.           (setq i_pt (rh:intersect_pt t_line (vlax-ename->vla-object g_ent)))
  64.           (vla-delete t_line)
  65.           (setq r_line (rh:draw_line ms right i_pt nil nil))      
  66.         );end_=Right
  67.        ( (= ans "Both")
  68.           (setq t_line (rh:draw_line ms left nil l_ang 50))
  69.           (setq i_pt (rh:intersect_pt t_line (vlax-ename->vla-object g_ent)))
  70.           (vla-delete t_line)
  71.           (setq l_line (rh:draw_line ms left i_pt nil nil))
  72.           (setq t_line (rh:draw_line ms right nil r_ang 50))
  73.           (setq i_pt (rh:intersect_pt t_line (vlax-ename->vla-object g_ent)))
  74.           (vla-delete t_line)
  75.           (setq r_line (rh:draw_line ms right i_pt nil nil))          
  76.         );end_=Both
  77.   );end_cond
  78.   (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-endundomark c_doc))
  79. );end_defun
  80.  
  81.  

mihaibantas

  • Mosquito
  • Posts: 5
Re: Help - Lisp drawing polyline by degree between two parallel
« Reply #2 on: April 19, 2018, 07:59:47 AM »
Hello Dlanor
First of all I want to thank you for your help ... the code works perfectly

It seems like I'm facing another problem .... Can I adjust the code to make the same line type just as the green line is above the red ??? I attached the example in the picture ... Thank you in advance for your time.

Dlanor

  • Bull Frog
  • Posts: 263
Re: Help - Lisp drawing polyline by degree between two parallel
« Reply #3 on: April 19, 2018, 08:36:54 AM »
Yes, you can adjust the hard coded angles in the main defun (defun c:test). The first setq function contains two variables l_ang (left angle) and r_ang (right angle). They have comments

;<<===== alongside them

The angles are in degrees. If you require the same slope angle (34 degrees) change l_ang to 146 and r_ang to 34 for red below green

I'll attempt to alter my routine to account for red below green, but i can't do anything before this evening.

mihaibantas

  • Mosquito
  • Posts: 5
Re: Help - Lisp drawing polyline by degree between two parallel
« Reply #4 on: April 19, 2018, 08:54:48 AM »
Hello Dlanor....I made the changes in the code ... and they were successful :smitten: .... but I happen to have both situations in same drawing. What do you suggest me to do ....... to use two different codes with the respective modified variables

Command TEST ======> l_ang to 146 and r_ang to 34
Command TEST1 ======> l_ang to 214 and r_ang to 326.

However wait and modified version of you ... maybe you version much better solution than mine...Thanks again for the interest shown to my problem

Dlanor

  • Bull Frog
  • Posts: 263
Re: Help - Lisp drawing polyline by degree between two parallel
« Reply #5 on: April 19, 2018, 12:28:39 PM »


Edited as attached file superceded
« Last Edit: April 19, 2018, 08:43:08 PM by Dlanor »

Dlanor

  • Bull Frog
  • Posts: 263
Re: Help - Lisp drawing polyline by degree between two parallel
« Reply #6 on: April 19, 2018, 03:00:06 PM »
Improved Lisp. Type "test" on commandline to run

While loop: Repeats until null selection made for either polyline or enter pressed at same prompt.

Lisp now handles either end of design polyline being on the ground line or intersection point being outside extents of ground line 

Test drawing included to test cases.

 
« Last Edit: April 19, 2018, 08:44:53 PM by Dlanor »

mihaibantas

  • Mosquito
  • Posts: 5
Re: Help - Lisp drawing polyline by degree between two parallel
« Reply #7 on: April 20, 2018, 03:16:33 AM »
Thanks again for the last code ... it covers all my related problems :smitten: :smitten: :smitten:
I wish you a good day

Dlanor

  • Bull Frog
  • Posts: 263
Re: Help - Lisp drawing polyline by degree between two parallel
« Reply #8 on: April 20, 2018, 05:08:47 AM »
Thanks again for the last code ... it covers all my related problems

Not a problem, i'm glad it helps

BIGAL

  • Swamp Rat
  • Posts: 1407
  • 40 + years of using Autocad
Re: Help - Lisp drawing polyline by degree between two parallel
« Reply #9 on: April 21, 2018, 05:04:58 AM »
If these are road cross sections why are you not producing the batter slope any way ???

To make the code much simpler pick pline left side compare start and end pts swap if required, Pick connecting pline, the line angle is not an angle rather a slope 1:ratio so draw a ray line and look for intersect pt if not reverse angle this is cut v's fill. You know which is left and right so there is only 2 solutions per end to try. Even old lisp (inters p1 p2 p3 p4) if true then it intersects at the new point, false reverse angle.

30+ years civil design.
A man who never made a mistake never made anything