Author Topic: Help me to convert a file  (Read 11193 times)

0 Members and 1 Guest are viewing this topic.

ChrisCarlson

  • Guest
Re: Help me to convert a file
« Reply #15 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.



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.

pedroantonio

  • Guest
Re: Help me to convert a file
« Reply #16 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

ChrisCarlson

  • Guest
Re: Help me to convert a file
« Reply #17 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.

ymg

  • Guest
Re: Help me to convert a file
« Reply #18 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

ymg

  • Guest
Re: Help me to convert a file
« Reply #19 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
« Last Edit: December 16, 2015, 09:32:54 PM by ymg »

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Help me to convert a file
« Reply #20 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:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

pedroantonio

  • Guest
Re: Help me to convert a file
« Reply #21 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

« Last Edit: December 17, 2015, 05:12:23 AM by Topographer »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help me to convert a file
« Reply #22 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 ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

pedroantonio

  • Guest
Re: Help me to convert a file
« Reply #23 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)

ymg

  • Guest
Re: Help me to convert a file
« Reply #24 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

pedroantonio

  • Guest
Re: Help me to convert a file
« Reply #25 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

pedroantonio

  • Guest
Re: Help me to convert a file
« Reply #26 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
« Last Edit: December 17, 2015, 05:55:57 PM by Topographer »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help me to convert a file
« Reply #27 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 ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

pedroantonio

  • Guest
Re: Help me to convert a file
« Reply #28 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

ymg

  • Guest
Re: Help me to convert a file
« Reply #29 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
« Last Edit: December 17, 2015, 09:32:09 PM by ymg »