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

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help me to convert a file
« Reply #45 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:
« Last Edit: December 19, 2015, 03:15:19 AM by Kerry »
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 #46 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 to insert the points in to the drawing. The only thing i need for the doit.lsp is to export a txt  file

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help me to convert a file
« Reply #47 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)
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help me to convert a file
« Reply #48 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.
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 #49 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  :-)

pedroantonio

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help me to convert a file
« Reply #51 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.  
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 #52 on: December 19, 2015, 04:27:01 AM »
Thank you Kerry

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help me to convert a file
« Reply #53 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 !

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.