Author Topic: Help with cross section lisp  (Read 5009 times)

0 Members and 2 Guests are viewing this topic.

PM

  • Guest
Help with cross section lisp
« on: September 14, 2021, 07:29:17 AM »
Hi,I am using this code to create cross section drom contours. I want to update this code to ask me to pick a point on the aligment and move the 0 in the center line  and when draw the section insert a vertical line in 0 (in the possition of the aligment). My english is bad but look the image and you will understand

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:xsect ()
  3.   (setq os (getvar "osmode"))(setvar "osmode" 0);store users osnap settings
  4.   (setq sectline (car (entsel "\nChoose section line, "))
  5.         bp (dxfeg 10 sectline) ep (dxfeg 11 sectline);get section line endpoints, assuming an ordinary line entity for section line
  6.         ;better project these to xy plane, so....
  7.         bp (list (car bp)(cadr bp) 0.0) ep (list (car ep)(cadr ep) 0.0);section line is projected down onto xy plane
  8.         sectionintpoints nil;make a place to store all intersections between contours and this particular section line
  9.         )
  10.   (princ "\nChoose contours to sample (contours that the section line passes thru),")
  11.   (setq sscontours (ssget) i 0)
  12.   (while (< i (sslength sscontours));loop thru contours
  13.     (setq pldata (getcontourdata (ssname sscontours i));get elevation and 2d points
  14.           elev (car pldata);retrieve elevation
  15.           plis (cdr pldata);retrieve 2d point information (x and y coordinates of contour)
  16.           thiscountourintpoints nil;make a place to store intersection points for this particular contour
  17.           backcountourpoint    (car plis);store first vertex of polyline for intersection test purposes
  18.           j 0;initialize contour vertex counter
  19.     )                          
  20.     (while (< j (length plis));loop thru countour vertices
  21.       (setq frontcontourpoint (nth j plis))
  22.       (cond ((null (setq ip (inters backcountourpoint frontcontourpoint bp ep))) nil);no intersection
  23.             (t;intersection found
  24.                 (setq thiscountourintpoints;add to the list
  25.                     (cons (list (car ip)(cadr ip) elev) thiscountourintpoints )
  26.                    );setq
  27.              );t
  28.            );cond
  29.       (setq backcountourpoint frontcontourpoint);move up the contour.......
  30.       (setq j (1+ j));....and increment counter
  31.         );while j
  32.     ;sort by horizontal distance from bp
  33.     (setq i (1+ i))
  34.     (setq sectionintpoints (append thiscountourintpoints sectionintpoints))
  35.    );while i
  36.   ;now the list must be sorted by horizontal distance from bp
  37.   (setq sortedsectionintpoints
  38.          (vl-sort sectionintpoints '(lambda (p1 p2)(< (distance bp (list (car p1)(cadr p1)))(distance bp (list (car p2)(cadr p2))))))
  39.         )
  40.   ;draw section
  41.   (setq total_distance 0.0
  42.         lastpoint (car sortedsectionintpoints)
  43.         cdrlis (cdr sortedsectionintpoints)
  44.         )
  45.   (command "pline" (list 0.0 (caddr lastpoint)))
  46.   (foreach p cdrlis
  47.           (setq total_distance
  48.                (+ total_distance
  49.                   (distance (list (car lastpoint)(cadr lastpoint))(list (car p)(cadr p))))
  50.               )
  51.         (command (list total_distance (caddr p)))
  52.         (setq lastpoint p)
  53.     )
  54.   (command "")
  55.   ;restore user's snap settings
  56.   (setvar "osmode" os)
  57.  );defun
  58.  
  59. ;..............utility....................................................
  60. (defun dxf (c eg)(cdr (assoc c eg)))(defun dxfeg (c e)(cdr (assoc c (entget e))))
  61.  
  62. ;..................................................................
  63.  
  64. (defun getcontourdata (e / mlis);return a list whose first element is elevation; rest is 2d points follow
  65.  (cond
  66.   ((= "LWPOLYLINE" (dxfeg 0 e))(setq mlis (lwpolyhan e)))
  67.   ((= "POLYLINE" (dxfeg 0 e))(setq mlis (polyhan e)))
  68.   (t (setq mlis nil))
  69.   )
  70. mlis
  71. )
  72. (defun polyhan (e / plis pl p);this is for handing 3dpolylines, and it assumes the 3dpoly's vertices all have the same elevation
  73.  (setq pl e plis nil elev (caddr (dxfeg 10 (entnext e))));
  74.  (while (and (setq e (entnext e))
  75.              (setq eg (entget e))
  76.              (/= "SEQEND" (dxf 0 eg))
  77.            )
  78.     (setq p (dxf 10 eg) plis (cons (list (car p)(cadr p)) plis))
  79.    )
  80.   (setq plis (if (= 1 (logand 1 (dxfeg 70 pl)));if pline is closed, tack a copy of the last vertext onto the front; reverse order either way
  81.                ;then
  82.               (cons (car plis)(reverse plis))
  83.                ;else
  84.               (reverse plis)
  85.                )
  86.         )
  87.  (cons elev plis)
  88. )
  89. (defun lwpolyhan (e / eg elev datalis plis)
  90.   (setq eg (entget e) datalis eg plis nil elev (dxfeg 38 e))
  91.   (while (setq datalis (member (assoc 10 datalis) datalis))
  92.     (setq
  93.           plis (cons (cdar datalis) plis)
  94.           datalis (cdr datalis)
  95.           )
  96.     )
  97.      (setq plis (if (= 1 (logand 1 (dxfeg 70 e)));if pline is closed, tack a copy of the last vertext onto the front; reverse order either way
  98.                ;then
  99.               (cons (car plis)(reverse plis))
  100.                ;else
  101.               (reverse plis)
  102.                )
  103.         )
  104.  (cons elev plis)
  105.   )
  106.  
  107.  
  108.  
  109.  

Thanks

PM

  • Guest
Re: Help with cross section lisp
« Reply #1 on: September 14, 2021, 12:33:32 PM »
Any options ?

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Help with cross section lisp
« Reply #2 on: September 14, 2021, 10:52:29 PM »
Any of the CIVIL packages will do what you want and so much more. Sometimes have to spend money to make money.
A man who never made a mistake never made anything

PM

  • Guest
Re: Help with cross section lisp
« Reply #3 on: September 15, 2021, 02:59:44 AM »
I am not using civil3d.So i need a lisp to cut the cross section from contours. To select the section line, 1 point in the the intersection of aligment and cross section line and third select contours or gine the 2 layers of the contours in the code and select then automaticaly, and draw the section with the aligment center line. Then i add a grid all elevetions


Thanks

PM

  • Guest
Re: Help with cross section lisp
« Reply #4 on: September 15, 2021, 11:26:29 AM »
any other ideas?

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Help with cross section lisp
« Reply #5 on: September 15, 2021, 01:28:13 PM »
Any of the CIVIL packages will do what you want and so much more. Sometimes have to spend money to make money.
Exactly.  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

PM

  • Guest
Re: Help with cross section lisp
« Reply #6 on: September 15, 2021, 03:04:11 PM »
Ok i read that. just i ask for a little modification.To pick a point on the aligmet and insrt 0 in this place and draw a vertical line in the cross section .

Thanks

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Help with cross section lisp
« Reply #7 on: September 15, 2021, 04:20:36 PM »
Ok i read that. just i ask for a little modification.To pick a point on the aligmet and insrt 0 in this place and draw a vertical line in the cross section .
oh, this is simple - use (getpoint) to pick a point and use (command "line" ....) to draw a line

PM

  • Guest
Re: Help with cross section lisp
« Reply #8 on: September 15, 2021, 05:39:33 PM »
ok  VovKa ,is not so simple ..................

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Help with cross section lisp
« Reply #9 on: September 15, 2021, 09:00:51 PM »
You dont have to buy CIV3D there are other packages out there less expensive and will do so much more will save the next 10 request from you.

Hint google YMG Cadtutor TriangV0.5.9.LSP
A man who never made a mistake never made anything

PM

  • Guest
Re: Help with cross section lisp
« Reply #10 on: September 16, 2021, 01:55:35 AM »
Hi Bigal. I know this code TriangV0.5.9.LSP. Is powerfull but don't cut cross sectrions, only long sections.The important thing is to draw CL line on the section.

Thanks

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Help with cross section lisp
« Reply #11 on: September 16, 2021, 08:47:13 PM »
A cross section is a long section at 90 what more do you want for free. There are some other freebies out there just have to find them not my job.
A man who never made a mistake never made anything

PM

  • Guest
Re: Help with cross section lisp
« Reply #12 on: September 17, 2021, 03:26:23 AM »
Hi  BIGAL.The only thing i ask is to pick a point in the aligment possition and pur the 0 there with a vertical line through this point (the length of the vetical line must be equal maxH - min H). Not start from zero.If i use the cross section with the zero in start (like long section) i can not find accure  the aligment possition. The Big different longsection from cross section is that the cross section have the same scale horizontal and vertical , and the zero is on the aligment.

Thanks

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Help with cross section lisp
« Reply #13 on: September 17, 2021, 08:19:40 PM »
Add to text value.lsp so if you draw a line 20 long and get a long section add2text, -10 zero is now in middle.
A man who never made a mistake never made anything

PM

  • Guest
Re: Help with cross section lisp
« Reply #14 on: September 18, 2021, 02:36:59 AM »
Hi BIGAL. I am sure that you know very well that the aligment od the cross section is not all the times in the midle. Some timew we havw 10m in the left and 20m in the right.This code draw a section only on contours.if my ctoss section line  stop between two cross sections will not draw it or will put 0 elevetion there.So is not safe to measure a length and find the emidle and move the section to 0,H (H= datum elelevetion). Thats why i ask to pick a point on intersection (aligment and section line) and start the 0 there. Then i draw a vertical line manualy and do the rest.

Thanks