TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: pedroantonio on December 12, 2015, 10:58:18 AM

Title: Help me to convert a file
Post by: pedroantonio on December 12, 2015, 10:58:18 AM
I have a drawing with 125 cross section (i upload one of them).
I have a drawing of a road .I want to steak out this road so i want to export the position and elevetion from the cross sections.I have export for the cross section the distansce and the elevetion to a *.txt file.I need a lisp to convert me this files to (point number,x,y,elevetion) files

Read the test.dwg and  will understand

Thanks
Title: Re: Help me to convert a file
Post by: pedroantonio on December 12, 2015, 02:14:52 PM
Any ideas ?

Thanks
Title: Re: Help me to convert a file
Post by: ymg on December 12, 2015, 02:58:34 PM
topographer,

Do you have the alignment of the center line and the chainage
of each section ?

Right now your data file does not give the chainage.

(vlax-curve-getpointatdist alignment chainage) will give you a point
(vlax-curve-getfirstderivative ....  will give you the direction of the alignment

Then simply calculate each point at 90 degree from this angle.

ymg

Title: Re: Help me to convert a file
Post by: pedroantonio on December 12, 2015, 03:15:11 PM
Hi ymg.Look If you know for example the coordinates ,the distanse and the angle you can calculate the coordinates of a new point.I have in a file the distanse and the elevetion of the new point but i dont have the angle so. I need a lisp to select the aligment of the cross section ,grab the cordinate of the midle point of the cross section ,and convert the length , elevetion txt file to (point,x,y,elev) (with point name 1,2,3 .... i don't  care  what).

I dont need the chainge i can do it this manualy for eatch section. For the time is very big help to convert the file

Thanks
Title: Re: Help me to convert a file
Post by: pedroantonio on December 12, 2015, 03:18:47 PM
Code: [Select]
Then simply calculate each point at 90 degree from this angle.
I use grads ,and direction north for the most of my drawings.
Title: Re: Help me to convert a file
Post by: ymg on December 12, 2015, 05:29:49 PM
topographer,

First select your alignment and assign it's ename to variable en:
Code - Auto/Visual Lisp: [Select]
  1. (setq en (car (entsel "\nSelect Alignment: ")))
  2.  


You kow how to get the point knowing the chainage as a real number:

Code - Auto/Visual Lisp: [Select]

The reference angle you can get with this function:
Code - Auto/Visual Lisp: [Select]
  1. ;;                                                                            ;
  2. ;; Return angle along curve, at specified point (on curve)                    ;
  3. ;; e - valid curve (ENAME or VLA-OBJECT)                                      ;
  4. ;; p - point on curve                                                         ;
  5. ;; Alan J. Thompson, 11.04.10                                                 ;
  6. ;;                                                                            ;
  7.  
  8. (defun AngleAtPoint (e p)
  9. )
  10.  


Then your section point will all be at:
Code - Auto/Visual Lisp: [Select]
  1. (polar point (+ refangle (/ pi 2)) sdist)
  2.  

Replace the z of the point calculated above by the one in your cross section.

Now stop asking question and get coding!

ymg
Title: Re: Help me to convert a file
Post by: pedroantonio on December 13, 2015, 02:30:21 AM
Thanks you ymg for the help but the problem is that I am not good in lisp. To coding this lisp if very difficult for my level  :oops:
Title: Re: Help me to convert a file
Post by: pedroantonio on December 14, 2015, 02:28:39 AM
Hi ymg.Can you help me more  :embarrassed:

Thanks
Title: Re: Help me to convert a file
Post by: pedroantonio on December 15, 2015, 11:48:35 AM
with the help of ymg this is the idea. I dont know how to continue. Can any one finish this code.I am not good in lisp . I have a lot of work to do and this code will help me a lot.

Code - Auto/Visual Lisp: [Select]
  1. (setq en (car (entsel "\nSelect Alignment: ")))
  2.  
  3.  
  4. ;; Read the file with the distanse and elevetion
  5.  
  6. (SETQ F1 (OPEN FNAME "r"))
  7.  
  8.  
  9. ;;                                                                            ;
  10. ;; Return angle along curve, at specified point (on curve)                    ;
  11. ;; e - valid curve (ENAME or VLA-OBJECT)                                      ;
  12. ;; p - point on curve                                                         ;
  13. ;; Alan J. Thompson, 11.04.10                                                 ;
  14. ;;                                                                            ;
  15.  
  16. (defun AngleAtPoint (e p)
  17. )
  18.  
  19.  
  20. (polar point (+ refangle (/ pi 2)) sdist)
  21.  
  22. ;; Save the new file p,x,y,z
  23.  
  24. (setq fn (getfiled "save file as  P,x,y,z" "" "txt" 1))
  25.  

Thanks
Title: Re: Help me to convert a file
Post by: ronjonp on December 15, 2015, 11:58:17 AM
with the help of ymg this is the idea. I dont know how to continue. Can any one finish this code.I am not good in lisp . I have a lot of work to do and this code will help me a lot.

Code - Auto/Visual Lisp: [Select]
  1. (setq en (car (entsel "\nSelect Alignment: ")))
  2.  
  3.  
  4. ;; Read the file with the distanse and elevetion
  5.  
  6. (SETQ F1 (OPEN FNAME "r"))
  7.  
  8.  
  9. ;;                                                                            ;
  10. ;; Return angle along curve, at specified point (on curve)                    ;
  11. ;; e - valid curve (ENAME or VLA-OBJECT)                                      ;
  12. ;; p - point on curve                                                         ;
  13. ;; Alan J. Thompson, 11.04.10                                                 ;
  14. ;;                                                                            ;
  15.  
  16. (defun AngleAtPoint (e p)
  17. )
  18.  
  19.  
  20. (polar point (+ refangle (/ pi 2)) sdist)
  21.  
  22. ;; Save the new file p,x,y,z
  23.  
  24. (setq fn (getfiled "save file as  P,x,y,z" "" "txt" 1))
  25.  

Thanks
You really have to start trying to write your own code.  ;)
Title: Re: Help me to convert a file
Post by: pedroantonio on December 15, 2015, 12:09:45 PM
Always ronjonp your comments are negative. Can you  help me one time  without doing me an observation? We're not  all good in programming as you !!!!  :-)
Title: Re: Help me to convert a file
Post by: ronjonp on December 15, 2015, 12:16:23 PM
Always ronjonp your comments are negative. Can you  help me one time  without doing me an observation? We're not  all good in programming as you !!!!  :)
Negative (https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=chainage%20site%3Atheswamp.org).
Title: Re: Help me to convert a file
Post by: pedroantonio on December 15, 2015, 03:08:48 PM
I need help to finish the code.
I have in a file the distanse and the elevetion of the new point but i dont have the angle so.
I need a lisp to select the aligment of the cross section ,grab the coordinate of the midle point of the cross section ,and convert the length , elevetion txt file to (point,x,y,elev) (with point name 1,2,3 .... i don't  care  what).

Thanks
Title: Re: Help me to convert a file
Post by: ymg on December 15, 2015, 09:14:45 PM
topographer,

You should not see Ronjomp's commentaries as negative, actually every links
he gave you is helpful in achieving your goal.

We are trying to shock you into jumping in and actually doing the effort
required to code your own.

This is not out of contempt, but actually trying to help you achieve something
that would/will be a tremendous plus in your career.

Although, you did a little effort in the previous post you need to do a little more
if you want us to help you.

For example, there is nothing telling us how your data is organized.  Are all the files
for a given alignment in a single folder.  If so we need to iterate all xsection files of
the folder and create a single point file out of it.

You posted an image about the angle being an unknown.  I explained to you
in previous post that all you need is the first derivative of the center line point
at the chainage of the section. This is the tangent to the curve.

Function "angleatpoint" gives you the direction of that tangent.  So to make
a long story short your angle is always 90 degrees, which correspond to an
angle of pi/2 radian.

So (polar p (+ (angleatpoint p en)  (/ pi 2)) dist) always gives you the points
on your section. (Notes that your distance are kept negative on left side of alignment)

Other question how are your file named ?

Can we extract the chainage from the file name ?

We understand that you are busy. But a little effort now will repay itself
a thousand times.

ymg
Title: Re: Help me to convert a file
Post by: pedroantonio on December 16, 2015, 01:35:51 AM
Good morning ymg.I will try to explain from the beginning what i want.
I have 125 cross section to steak out and a road design.
I export the data from eatch cross section to a txt file .This data is (lengths and elevetion) .The lengths with (-) are from the left and the other lengths  are from the right. (look the txt file)
In the road drawing for eatch section you can see a green line vertical to the road center line.
I want this lisp to work for one cross section per time (I dont want to add the  chainage ) .

The lisp i want to work like this:

1) pick the middle of green cross section line from the road drawing anf grab the coordinates
2)Select the green cross section line from the road drawing (and canlulate the angle G look the test.dwg)
3)open window and select the cross section file with the lengths and elevetions
4)Tranform this this file to a new file p,x,y,elev

So i can have the the cross section data over the road design.


Thanks
Title: Re: Help me to convert a file
Post by: ChrisCarlson on December 16, 2015, 07:19:52 AM
Lets work on this one and break down your routine step by step. Instead of attempting to mash out a routine, lets write function by function to achieve your goal.

(http://whitbeckweb.com/wp-content/uploads/2015/01/steps-to-business-your-success_quote.jpg)

In your routine what is the first thing you need to do? I'd suggest filtering your selection set as using

Code - Auto/Visual Lisp: [Select]
  1. (setq en (car (entsel "\nSelect Alignment: ")))

Will allow the user to select any entity.
Title: Re: Help me to convert a file
Post by: pedroantonio on December 16, 2015, 02:02:11 PM
Hi. I don't know how to continue this code.Can any one finish it ?  :embarrassed:

Thanks
Title: Re: Help me to convert a file
Post by: ChrisCarlson on December 16, 2015, 03:49:27 PM
We are trying to assist, if you purely want someone else to write it you will have a better chance of purchasing a routine from a company which specializes in add-ons.
Title: Re: Help me to convert a file
Post by: ymg on December 16, 2015, 05:20:41 PM
topographer,

You did not answer my questions, that is : Can we derive the chainage of the section from the file name ?

On your test drawing they seems to be always at 20 meters distance.

What is the name of each of your files ?

The unit that you use for your angle is irrelevant. The polar function works in radians.

If you want help at least answers this simple question.

ymg
Title: Re: Help me to convert a file
Post by: ymg on December 16, 2015, 09:28:31 PM
Try this, No Error checking or filtering.

You do not need to pick each point, the programs
find them at every 20 meters.

You do have to enter a filename in the getfiled dialog box,
because you did not organize your data properly.  The section
should be in a single folder and at least have a name that could
be translated to a chainage.  Alternatively the first line in every
cross section file could be a real corresponding to the chainage.

You still have not answered my question!!!!!




Code: [Select]
(defun c:section2points (/ ** an en f fname lg p path pnum ps rst sect title

                              angleatpoint readcsv in_range rtosta)

   ;;                                                                         ;
   ;; Return angle along curve, at specified point (on curve)                 ;
   ;; e - valid curve (ENAME or VLA-OBJECT)                                   ;
   ;; p - point on curve                                                      ;
   ;; Alan J. Thompson, 11.04.10                                              ;
   ;;                                                                         ;

   (defun AngleAtPoint (e p)
      (angle '(0. 0. 0.) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e p)))
   )


   ;; ReadCSV  -  Lee Mac                                                     ;
   ;; Parses a CSV file into a list of lists, each sublist is a row           ;
   ;; of CSV cell values.                                                     ;
 
   (defun ReadCSV ( filename / _csv->lst file line lst )
 
      (defun _csv->lst ( str / pos )
         (if (setq pos (vl-string-position 44 str))
            (cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
            (list str)
         )
      )
 
      (if (setq file (open filename "r"))
         (progn
            (while (setq line (read-line file))
               (setq lst (cons (_csv->lst line) lst))
            )
            (close file)
         )
      )
      (reverse lst)
   )

   
   ;;                                                                         ;
   ;; in_range      by ElpanovEvgeniy       (recursive)                       ;
   ;;                                                                         ;
   ;; Similar to the Python Function                                          ;
   ;;                                                                         ;

   (defun in_range (s e i)
      (if (or (and (> i 0) (< s e)) (and (< i 0) (> s e)))
(cons s (in_range (+ i s) e i))
      )
   )

   ;;                                                                         ;
   ;; rtosta                     by ymg            September 2013             ;
   ;; Arguments:   sta, Real number to format as a Station                    ;
   ;;             unit, 1 for Imperials,                                      ;
   ;;                   2 for Metrics.                                        ;
   ;;             prec, Integer for number of decimals                        ;
   ;; DIMZIN must be set to 0 or 1 outside this routine.                      ;
   ;;                                                                         ;
   ;; Examples: (rtosta 0 1 0) -> "0+00"   (rtosta 1328.325 1 2) -> "13+28.33";
   ;;           (rtosta 0 2 0) -> "0+000"  (rtosta 1328.325 2 2) -> "1+328.33";
   ;;                                                                         ;
   ;; If sta is negative, format is as follow:                                ;
   ;;                             (rtosta -1328.325 1 2) -> "13-28.33"        ;
   ;;                             (rtosta -1328.325 2 2) -> "1-328.33"        ;
   ;;                                                                         ;

   (defun rtosta (sta unit prec / str a b dz)     
      (setq str (rtos (abs sta) 2 prec))   
      (while (< (strlen str) (if (= prec 0) (+ unit 2) (+ prec (+ unit 3))))
         (setq str (strcat "0" str))
      )
      (setq a (if (= prec 0) (- (strlen str) unit) (- (strlen str) prec (+ unit 1)))
            b (substr str 1 (- a 1))
            a (substr str a)
      )
      (strcat b (if (minusp sta) "-" "+") a)
   )

   ;;-------------------------- Main Program ---------------------------------;
   
   (setq en    (car (entsel "\nSelect the Polyline Representing the Alignment: "))
         lg    (vlax-curve-getdistatpoint en (vlax-curve-getendpoint en))
         pnum  1
         path  ""
   )     
   (foreach d (in_range 0 lg 20)
     
      (setq title (strcat "Select File for Chainage " (rtosta d 2 0))
            **    (princ (strcat "\n" title))
            fname (getfiled title path "txt" 0)
             path (if (setq tmp (vl-filename-directory fname)) (strcat tmp "\\") "")
      )
     
      (if fname
         (progn
            (setq sect (readcsv fname)
                     p (vlax-curve-getpointatdist en d)
                    an (+ (angleatpoint en p) (/ pi 2))
            )
            (foreach i sect
               (setq ps   (polar p an (atof (car i)))
                     rst  (cons (list pnum (car ps) (cadr ps) (atof (cadr i))) rst)
                     pnum (1+ pnum)
               )
            )
         )
      )     
   )

   ;; List rst now contains all points generated from the section             ;

   (setq f   (open (strcat path "Section Points.txt") "w"))
   (foreach i (reverse rst)
      (write-line (strcat (itoa  (car    i)) ","
                          (rtos  (cadr   i)) ","
                          (rtos  (caddr  i)) ","
                          (rtos  (cadddr i))
                  )
                  f
      )
   )
   (close f)   
   (princ)   
)

ymg
Title: Re: Help me to convert a file
Post by: ronjonp on December 16, 2015, 11:49:13 PM
Ymg ..I applaud your patience & generosity but topo guy needs a lesson in tough love if he's ever to really try for himself IMO.  :evil:
Title: Re: Help me to convert a file
Post by: pedroantonio on December 17, 2015, 04:55:57 AM
Hi ymg, I try your code and thank you for your time.The insert poits are not correct (Have wrong angle ,and wrong position).I upload all the drawing of the road and all my cross sections. The  chainage is not all the etime 20m but every cross section write on the left the  chainage.  Your idea is corect. If the cross section file  have all the section data and the chainage,the only thing i have to do is select the road center line only !!! Help me how to manage my data files corect .

I use this lisp to export the data from the cross sections

Code - Auto/Visual Lisp: [Select]
  1. (defun c:dtexport ()
  2.   (setq sset (ssget '((-4 . "<OR")(0 . "POINT")
  3.                       (0 . "LWPOLYLINE")(-4 . "OR>"))))
  4.   (if sset
  5.     (progn
  6.       (setq itm 0 num (sslength sset))
  7.       (setq fn (getfiled "Save file" "" "txt" 1))
  8.       (if (/= fn nil)
  9.         (progn
  10.           (setq fh (open fn "w"))
  11.           (while (< itm num)
  12.             (setq hnd (ssname sset itm))
  13.             (setq ent (entget hnd))
  14.             (setq obj (cdr (assoc 0 ent)))
  15.             (cond
  16.               ((= obj "POINT")
  17.                 (setq pnt (cdr (assoc 10 ent)))
  18.                 (setq pnt (trans pnt 0 1));;**CAB
  19.                 (princ (strcat (rtos (car pnt) 2 8) ","
  20.                                (rtos (cadr pnt) 2 8)) fh)
  21.                 (princ "\n" fh)
  22.               )
  23.               ((= obj "LWPOLYLINE")
  24.                 (if (= (cdr (assoc 38 ent)) nil)
  25.                   (setq elv 0.0)
  26.                   (setq elv (cdr (assoc 38 ent)))
  27.                 )
  28.                 (foreach rec ent
  29.                   (if (= (car rec) 10)
  30.                     (progn
  31.                       (setq pnt (cdr rec))
  32.                       (setq pnt (trans pnt 0 1));;**CAB
  33.                       (princ (strcat (rtos (car pnt) 2 8) ","
  34.                                      (rtos (cadr pnt) 2 8)) fh)
  35.                       (princ "\n" fh)
  36.                     )
  37.                   )
  38.                 )
  39.               )
  40.               (t nil)
  41.             )
  42.             (setq itm (1+ itm))
  43.           )
  44.           (close fh)
  45.         )
  46.       )
  47.     )
  48.   )
  49.   (princ)
  50. )
  51.  

I can join all cross section data to one like this

Code: [Select]
0+000  <---  chainage
-3.91192198,22.42945290
-3.65605593,22.60003090
-3.35605597,22.60003090
-3.05302572,22.80002975
-2.50000000,22.80002403
0.00000000,22.79999924 <---  Here is the section of roadlinea and cross section line
2.50000000,22.80002403
3.05302572,22.80002975
3.35605597,22.60003090
3.65605593,22.60003090
4.25976181,23.80744362
4.55976200,24.23544121
4.85951757,24.49160957
0+020<---  chainage
-4.01208448,21.47536469
-3.65605593,21.71271896
-3.35605597,21.71271896
-3.05302572,21.91271782
-2.50000000,21.91271210
0.00000000,21.91268730
2.50000000,21.91271210
3.05302572,21.91271782
3.35605597,21.71271896
3.65605593,21.71271896
3.73025107,21.86110687
4.03025103,22.28760529
4.33002567,22.54076385

Title: Re: Help me to convert a file
Post by: Kerry on December 17, 2015, 05:23:27 AM

What happens if you change the precision in the file to 16 or 17  ?

Does that improve your accuracy ?
Title: Re: Help me to convert a file
Post by: pedroantonio on December 17, 2015, 09:05:03 AM
Hi Kerry. if you are tolking about this

Code: [Select]
                      (princ (strcat (rtos (car pnt) 2 8) ","
                                     (rtos (cadr pnt) 2 8)) fh)

I did it for the  accuracy,but I will change it to

Code: [Select]
                      (princ (strcat (rtos (car pnt) 2 3) ","
                                     (rtos (cadr pnt) 2 2)) fh)
Title: Re: Help me to convert a file
Post by: ymg on December 17, 2015, 04:28:07 PM
topographer,

Just change this line  to:
Code: [Select]
an (- (angleatpoint en p) (/ pi 2))

Should be minus instead of plus

ymg
Title: Re: Help me to convert a file
Post by: pedroantonio on December 17, 2015, 05:09:16 PM
Ymg still have problem with the angle and the position of the points.I am using grads.I don't know if the the problem is there .I upload 2 photos with the wrong results and the desirable result
Title: Re: Help me to convert a file
Post by: pedroantonio on December 17, 2015, 05:25:05 PM
I change the angle to

Code: [Select]
an (- (angleatpoint en p) (/ pi 200))
Now the angle is almost correct but all the points must move to right, because the number 6 is not in the middle of the road
Title: Re: Help me to convert a file
Post by: Kerry on December 17, 2015, 06:43:39 PM
I change the angle to

Code: [Select]
an (- (angleatpoint en p) (/ pi 200))
Now the angle is almost correct but all the points must move to right, because the number 6 is not in the middle of the road

Why are you Subtracting pi divided by 200 from the calculated angle ??
Title: Re: Help me to convert a file
Post by: pedroantonio on December 17, 2015, 06:46:41 PM
Hi Kerry  i  write (/ pi 200)to convert the angle to grads

All the times the program take as midle insert point the right side of the section line. The problem is if i extent the section line to the left and right the road center line is not all ways in the middle of the cross section line. Thats way i said in the beginning of the topic to

1) select the cross section line
2)pick the middle of green cross section line from the road drawing
3)calculate the  angle G in grads
Title: Re: Help me to convert a file
Post by: ymg on December 17, 2015, 08:02:25 PM
topographer,

I told you many times that the angle argument for function polar is radians. You don't need grad the side of your direction

is also irrelevant.

I plotted your sample section and point 1, 6 and 13 are right, no matter the direction or angle units.

ymg
Title: Re: Help me to convert a file
Post by: Kerry on December 17, 2015, 08:24:52 PM
Hi Kerry  i  write (/ pi 200)to convert the angle to grads

All the times the program take as midle insert point the right side of the section line. The problem is if i extent the section line to the left and right the road center line is not all ways in the middle of the cross section line. Thats way i said in the beginning of the topic to

1) select the cross section line
2)pick the middle of green cross section line from the road drawing
3)calculate the  angle G in grads

Topo,

Further to ymg's post,

PLEASE follow this through :

Code - Auto/Visual Lisp: [Select]
  1.  
  2. ;|
  3. AUNITS
  4. 0 -- Degrees
  5. 1 -- Degrees/minutes/seconds
  6. 2 -- Grads
  7. 3 -- Radians
  8. 4 -- Surveyor's units
  9. |;
  10.  
  11. (setvar 'aunits 0)
  12. (getvar 'Aunits) ;=> 0 DEGREES
  13. (setq en    (car (entsel "\nSelect Line")) )
  14.  
  15.  
  16. (vlax-curve-getStartPoint en) ;=> (0.0 0.0)
  17.  
  18. ;;The distance along the curve from the beginning of the curve to the location of the specified point.
  19. (setq pt (vlax-curve-getPointAtDist en 20)) ;=> (17.5001 -9.6823 0.0)  
  20.  
  21.  
  22. (setq ptd1 (polar pt (- (angle startPoint pt) (/ pi 2)) 5 )) ;=> (15.0795 -14.0573 0.0)
  23.  
  24. (setvar 'aunits 2)
  25. (getvar 'Aunits) ;=> 2 GRADS
  26.  
  27. (setq ptg1 (polar pt (- (angle startPoint pt) (/ pi 2)) 5 )) ;=>  WHAT DO YOU EXPECT FOR THIS RESULT
  28.  
  29.  
Title: Re: Help me to convert a file
Post by: ronjonp on December 17, 2015, 10:19:24 PM
http://m.youtube.com/watch?v=pHte24GGHD4
Title: Re: Help me to convert a file
Post by: Kerry on December 17, 2015, 11:13:36 PM
http://m.youtube.com/watch?v=pHte24GGHD4

The cat has lovely coloured sclera.
Title: Re: Help me to convert a file
Post by: ronjonp on December 17, 2015, 11:54:53 PM
http://m.youtube.com/watch?v=pHte24GGHD4

The cat has lovely coloured sclera.
:-)
Title: Re: Help me to convert a file
Post by: pedroantonio on December 18, 2015, 02:00:46 AM
Quote
I plotted your sample section and point 1, 6 and 13 are right, no matter the direction or angle units.

Hi ymg.After your post i use again your code for A13 cross section and the results are wrong.

I upload the cross section data  file i use and the cross section i use , and tell were is my mistake.

Quote
;;The distance along the curve from the beginning of the curve to the location of the specified point.
(setq pt (vlax-curve-getPointAtDist en 20)) ;=> (17.5001 -9.6823 0.0)

I have one question. This lisp  works only for cross section with length 20m ? If i have 20m for the left of the road center line and 40m for the right how the program will understand were is the center of the road?

Title: Re: Help me to convert a file
Post by: Kerry on December 18, 2015, 02:25:58 AM

Quote
;;The distance along the curve from the beginning of the curve to the location of the specified point.
(setq pt (vlax-curve-getPointAtDist en 20)) ;=> (17.5001 -9.6823 0.0)

I have one question. This lisp  works only for cross section with length 20m ? If i have 20m for the left of the road center line and 40m for the right how the program will understand were is the center of the road?


I'm giving up on this.
The code I wrote was pulled from my head to help you understand.

Personally I don't give a stuff about the width of your road; I was trying to demonstrate that polar uses radians and that your change of someone elses code to (/ pi 200 ) was useless and incorrect.

You didn't even make the effort to answer the question I raised in the code or to acknowledge the lesson.





Title: Re: Help me to convert a file
Post by: pedroantonio on December 18, 2015, 02:36:56 AM
Thank you Kerry for the lesson. It help me to understand many things,but can you explain me why my mistake almost correct the angle of the points? I upload in previous post photos with the results.I am not good in programming and i respect that you, (ronjonp  :evil: ) and ymg try to help me.
Title: Re: Help me to convert a file
Post by: Kerry on December 18, 2015, 03:30:32 AM
By happenstance (/ pi 2)  is 89.1 degrees rotated from (/ pi 200)

... So you assumed the change fixed the issue and ignored the nominal 1 degree misalignment.

Code - Auto/Visual Lisp: [Select]
  1. (defun rtd (ang) (/ (* ang 180.0) pi))
  2. (defun rtg (ang) (/ (* ang 200.0) pi))
  3.  
  4. (rtd  pi ) ;=> 180.0 d
  5. (rtg  pi ) ;=> 200.0 g
  6.  
  7. (rtd (/ pi 200) ) ;=>  0.9 d
  8. (rtd (/ pi 2)   ) ;=> 90.0 d
  9.  

added re polar function:
Title: Re: Help me to convert a file
Post by: pedroantonio on December 18, 2015, 04:54:01 AM
And why ymg say

Quote
I told you many times that the angle argument for function polar is radians. You don't need grad the side of your direction is also irrelevant.
Title: Re: Help me to convert a file
Post by: Kerry on December 18, 2015, 05:11:54 AM
And why ymg say

Quote
I told you many times that the angle argument for function polar is radians. You don't need grad the side of your direction is also irrelevant.

You're joking, right ??
Title: Re: Help me to convert a file
Post by: pedroantonio on December 18, 2015, 05:28:26 AM
ymg i read again your previous post
Code: [Select]
You do not need to pick each point, the programs
find them at every 20 meters.

You do have to enter a filename in the getfiled dialog box,
because you did not organize your data properly.  The section
should be in a single folder and at least have a name that could
be translated to a chainage.  Alternatively the first line in every
cross section file could be a real corresponding to the chainage.

How to manage my data? Is A13.txt  file correct?

I can not understand this

Code: [Select]
You do not need to pick each point, the programs
find them at every 20 meters.

When the program start i select in road drawing  the cross green line not the center line of the road !!!. Please show me how to use correct your program , and what to change to cross section files
Title: Re: Help me to convert a file
Post by: ymg on December 18, 2015, 01:29:08 PM
topographer,

The whole exercise of re-calculating point out of your cross-section
is somewhat pointless.

Normally, the program you used to creates the cross-sections started
from points and calculated the offset distance and elevation.

So the proper way to do it would be to save your points as you creates
the cross-sections.

Now let says that for some reasons you lost your alignment drawing and
the file containing your original points and you want to recreates the alignment
and the point.

To do this, each cross section should have as the first line in each file, the chainage and the
coordinates of the center point and the orientation of the section. All  the offsets and distances
would be kept in the following lines.

This way you would need nothing else to re-calculate your points.  If you go back
to a project two years down the line,  your alignment can be reconstructed from
the cross-section files only.

Another question, although you are not very good at answering,  Why don't you
named your file in a meaningful way, like including the chainage in the name of the file ?

As for the correctness of file A13, I cannot check as the alignment drawing you gave us
does not show that one.  So even If I had the chainage of section A13, I cannot calculate the points.



ymg
Title: Re: Help me to convert a file
Post by: pedroantonio on December 18, 2015, 01:58:35 PM
Hi ymg. i have confused with all this .Can you tell me what to do to run this lisp without problems.Why i have problem with the rotation  aligment. Is my cross section file wrong?If is not nessesery to change anything in the code upload me the files you use to see the diference.

Code: [Select]
Another question, although you are not very good at answering,  Why don't you
named your file in a meaningful way, like including the chainage in the name of the file ?

I can do any change you want in the cross section file ,this is not a problem.just give an example. The only thing  i want is to see this programm work perfect  :-D .

Thanks
Title: Re: Help me to convert a file
Post by: ymg on December 18, 2015, 03:19:00 PM
topographer,

This is the files I use, which is the one you uploaded.

Title: Re: Help me to convert a file
Post by: pedroantonio on December 18, 2015, 03:46:10 PM
I can not see any difference.And you don't have rotation problem with this files ?If you usethis files then the programm mast have serious problem with the calculate ange.lIn your previous post you said me

Code: [Select]
To do this, each cross section should have as the first line in each file, the chainage and the
coordinates of the center point and the orientation of the section. All  the offsets and distances
would be kept in the following lines.

This way you would need nothing else to re-calculate your points.  If you go back
to a project two years down the line,  your alignment can be reconstructed from
the cross-section files only.

Another question, although you are not very good at answering,  Why don't you
named your file in a meaningful way, like including the chainage in the name of the file ?

So i think it is time to change the file and add the  the chainage and the
coordinates of the center point
Title: Re: Help me to convert a file
Post by: Kerry on December 18, 2015, 11:18:08 PM
Trying to resolve the original question

Select chainage marker line
Select Intersection of chainage marker line and road alignment line

Choose data file ( A13.txt )

Translate Section offsets to World locations

Write data file ( Section Points A13.txt )
which contains the point locations and elevations

I stole relevant parts from ymg
Proof of concept code :
Code - Auto/Visual Lisp: [Select]
  1. (defun c:doit (/            _readcsv
  2.                chainage_en  chainage_rotation
  3.                chainage_workpoint
  4.                f            fname
  5.                path         pnum
  6.                ps           rst
  7.                sect         title
  8.                tmp
  9.               )
  10.   ;; ReadCSV  -  Lee Mac                                                     ;
  11.   ;; Parses a CSV file into a list of lists, each sublist is a row           ;
  12.   ;; of CSV cell values.                                                     ;
  13.   (defun _ReadCSV (filename / _csv->lst file line lst)
  14.     (defun _csv->lst (str / pos)
  15.       (if (setq pos (vl-string-position 44 str))
  16.         (cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
  17.         (list str)
  18.       )
  19.     )
  20.     (if (setq file (open filename "r"))
  21.       (progn (while (setq line (read-line file))
  22.                (setq lst (cons (_csv->lst line) lst))
  23.              )
  24.              (close file)
  25.       )
  26.     )
  27.     (reverse lst)
  28.   )
  29.   ;;-----------------------------------------------------
  30.   (setq chainage_en        (car (entsel "\nSelect the Chainage marker line: "))
  31.         chainage_rotation  (angle (vlax-curve-getStartPoint chainage_en)
  32.                                   (vlax-curve-getEndPoint chainage_en)
  33.                            )
  34.         chainage_workpoint (getpoint
  35.                              "\nSelect Intersection Point of Road Alignment and Chainage marker "
  36.                            )
  37.   )
  38.   ;;-------------------------
  39.   (or path (setq path (getvar "DWGPREFIX")))
  40.   (setq title "Select File for Chainage Data"
  41.         fname (getfiled title path "txt" 0)
  42.         path  (if (setq tmp (vl-filename-directory fname))
  43.                 (strcat tmp "\\")
  44.                 ""
  45.               )
  46.   )
  47.   ;;-------------------------
  48.   (if fname
  49.     (progn (setq sect (_readcsv fname)
  50.                  pnum 1
  51.            )
  52.            (foreach i sect
  53.              (setq ps   (polar chainage_workpoint
  54.                                chainage_rotation
  55.                                (atof (car i))
  56.                         )
  57.                    rst  (cons (list pnum (car ps) (cadr ps) (atof (cadr i)))
  58.                               rst
  59.                         )
  60.                    pnum (1+ pnum)
  61.              )
  62.            )
  63.     )
  64.   )
  65.   ;; List rst now contains all points generated from the section             ;
  66.   (setq f (open (strcat path
  67.                         "Section Points "
  68.                         (vl-filename-base fname)
  69.                         ".txt"
  70.                 )
  71.                 "w"
  72.           )
  73.   )
  74.   (foreach i (reverse rst)
  75.     (write-line (strcat (itoa (car i))
  76.                         ","
  77.                         (rtos (cadr i))
  78.                         ","
  79.                         (rtos (caddr i))
  80.                         ","
  81.                         (rtos (cadddr i))
  82.                 )
  83.                 f
  84.     )
  85.   )
  86.   (close f)
  87.   (princ)
  88. )
  89.  

A13.txt

-3.79929280,  13.33168888
-3.65605593,  13.42717934
-3.35605597,  13.42717934
-3.05302572,  13.62718010
-2.50000000,  13.62717438
0.00000000,   13.62714958
2.50000000,   13.62717438
3.05302572,   13.62718010
3.35605597,   13.42717934
3.65605593,   13.42717934
3.97086596,   13.21730709


Section Points A13.txt

1,  428782.778500,  4315790.148924, 13.331689
2,  428782.866375,  4315790.262038, 13.427179
3,  428783.050423,  4315790.498948, 13.427179
4,  428783.236329,  4315790.738251, 13.627180
5,  428783.575606,  4315791.174976, 13.627174
6,  428785.109337,  4315793.149228, 13.627150
7,  428786.643068,  4315795.123479, 13.627174
8,  428786.982345,  4315795.560204, 13.627180
9,  428787.168252,  4315795.799507, 13.427179
10, 428787.352300,  4315796.036418, 13.427179
11, 428787.545433,  4315796.285023, 13.217307


Added:
NOTE: I've added spaces in files to facilitate human reading
May need to be edited to remove spaces

Topo,
I've not noticed any code to draw markers so I assume you will read this file to insert markers at each chainage.
If you have a function that draws the markers that works in Vanilla AutoCAD I'd like to try it with this data.


Snippet added:
Title: Re: Help me to convert a file
Post by: pedroantonio on December 19, 2015, 03:11:30 AM
Hi Kerry.Perhaps i miss something. I test your code many time.I use files with spaces and without spaces but all the time i get this error

I did this change in your code

Code: [Select]
;; List rst now contains all points generated from the section             ;
  (setq f1 (getfiled  "Section Points Pxyz" "/" "txt" 1))
  (setq f (open f1 "w"))
   (foreach i (reverse rst)
      (write-line (strcat (itoa  (car    i)) ","
                          (rtos  (cadr   i)) ","
                          (rtos  (caddr  i)) ","
                          (rtos  (cadddr i))
                  )
                  f
      )
   )
   (close f)   
   (princ)   
)

Code: [Select]
Select the Chainage marker line:
Select Intersection Point of Road Alignment and Chainage marker _int of ; error: no function definition: READCSV
Command:

The coordinates you upload is correct ,but i can not export any file for this lisp.

I use  pointsin.lsp (© Chris Bell) http://cadtips.cadalyst.com/attributed-blocks/import-survey-points (http://cadtips.cadalyst.com/attributed-blocks/import-survey-points) to insert the points in to the drawing. The only thing i need for the doit.lsp is to export a txt  file
Title: Re: Help me to convert a file
Post by: Kerry on December 19, 2015, 03:16:17 AM
In the body of my function change
Code - Auto/Visual Lisp: [Select]
  1.  (progn (setq sect (readcsv fname)
to
Code - Auto/Visual Lisp: [Select]
  1.  (progn (setq sect (_readcsv fname)
Title: Re: Help me to convert a file
Post by: Kerry on December 19, 2015, 03:20:31 AM

I did this change in your code

< .. >

Why change it ?
I explicitly wrote the code so that the points file was suffixed with name of the section data file.
Title: Re: Help me to convert a file
Post by: pedroantonio on December 19, 2015, 03:39:56 AM
Thank you Kerry the program works fine now.I use the code as you make it. I did the change  before i case i need to change file.

Thank again all (ymg, Kerry ,ronjonp :evil:,ChrisCarlson) for the help and the programming lessons.

I wish to all Marry Christmas  :-)
Title: Re: Help me to convert a file
Post by: pedroantonio on December 19, 2015, 04:05:16 AM
Kerry a last question . Can you tell me where in your code i can change the decimals ?

i want to change the expot file to somethig like this for more accuracy

Code: [Select]
Section Points A13.txt

1,428782.778500,4315790.148924,13.33
2,428782.866375,4315790.262038,13.42
3,428783.050423,4315790.498948,13.42
4,428783.236329,4315790.738251,13.62
5,428783.575606,4315791.174976,13.62
6,428785.109337,4315793.149228,13.62
7,428786.643068,4315795.123479,13.62
8,428786.982345,4315795.560204,13.62
9,428787.168252,4315795.799507,13.42
10,428787.352300,4315796.036418,13.42
11,428787.545433,4315796.285023,13.21


Thanks
Title: Re: Help me to convert a file
Post by: Kerry on December 19, 2015, 04:22:49 AM
http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-D03ABBC2-939A-44DB-8C93-FC63B64DE4A2

So :

Code - Auto/Visual Lisp: [Select]
  1. ;; snip
  2.  
  3.   (setq f (open (strcat path
  4.                         "Section Points "
  5.                         (vl-filename-base fname)
  6.                         ".txt"
  7.                 )
  8.                 "w"
  9.           )
  10.   )
  11.   (foreach i (reverse rst)
  12.     (write-line (strcat (itoa (car i))
  13.                         ","
  14.                         (rtos (cadr i) 2 6)     ;;<<<<<<<<<<
  15.                         ","
  16.                         (rtos (caddr i) 2 6)     ;;<<<<<<<<<<
  17.                         ","
  18.                         (rtos (cadddr i) 2 2)     ;;<<<<<<<<<<
  19.                 )
  20.                 f
  21.     )
  22.   )
  23.  
  24.  
Title: Re: Help me to convert a file
Post by: pedroantonio on December 19, 2015, 04:27:01 AM
Thank you Kerry
Title: Re: Help me to convert a file
Post by: Kerry on December 19, 2015, 04:38:49 AM
learn 2 functions a day, you'll know most of them by next New Year.
//--------------------------------
Just a tip for anyone who doesn't know !