Author Topic: SOLVED_lookup between CSV files  (Read 2587 times)

0 Members and 1 Guest are viewing this topic.

nekonihonjin

  • Newt
  • Posts: 103
SOLVED_lookup between CSV files
« on: November 08, 2022, 11:53:45 AM »
Hi guys!

I am trying to relate the columns of two CSV files to get information from one to the other using a pivot column that has values in common.

One file has information with coordinates, azimuth, inclination of an exploration drill hole, while the other has information of segments of each drill hole, so there are several entries of the same element in the pivot column.



I want to draw each drill by segments, but I need the coordinates, azimuth and inclination to be able to draw it, I am trying to search it in the other file with a comparison within a cycle, but it seems that it makes the search only once, and I can't find what's wrong.

Code: [Select]
(setq IDp "")
(setq fo2 (open fo2n "R"))
(setq lst2 '())
(setq fo (open fon "R"))
(setq lst '())
(while (setq nline (read-line fo))
    (setq lst (cons (_csv->lst nline) lst))
         (setq lst (nth 0 lst))
         (setq ID (nth 0 lst) from (nth 1 lst) to (nth 2 lst) AU (nth 3 lst) AG (nth 4 lst) PB (nth 5 lst) ZN (nth 6 lst) CU (nth 7 lst))

         (if (/= IDp ID)
           (progn
             (while (setq nline (read-line fo2))
               (setq lst2 (cons (_csv->lst nline) lst2))
               (setq lst2 (nth 0 lst2))
               (if (= ID (nth 0 lst2))
               (progn
               (setq X (nth 1 lst2) Y (nth 2 lst2) Z (nth 3 lst2) depth (nth 4 lst2) azim (nth 5 lst2) inclin (nth 6 lst2))
               (setq romp (list (atof X) (atof Y) (atof Z)))
               (setq az (dtr (aztocad (atof azim))))
               (setq incl (atof inclin))
               (Text romp 1 (nth 0 lst2))
               );progn
               );if
             ); while
          );progn
         );if

         (setq prof (- (atof to) (atof from)))
         (setq ptend (pol3d romp az (DTR incl) prof))
         (if (= disco "1")
              (progn
                (setq 3dline (Line romp ptend))
                (setq profile (Circle pto_c rad2))
                (command "_sweep" "_MO" "_SO" profile "" 3dline)
              );progn 
              (setq 3dline (Linew romp ptend))
         );if
         (setq romp ptend)
         (setq IDp ID)
);while



« Last Edit: November 09, 2022, 05:34:18 PM by nekonihonjin »

DEVITG

  • Bull Frog
  • Posts: 479
Re: lookup between CSV files
« Reply #1 on: November 08, 2022, 05:15:12 PM »
Please upload both CSV , and DWG where you apply the lisp
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

nekonihonjin

  • Newt
  • Posts: 103
Re: lookup between CSV files
« Reply #2 on: November 08, 2022, 05:25:52 PM »
Please upload both CSV , and DWG where you apply the lisp


I attach the CSV files, I run the lisp in a new file.

VovKa

  • Water Moccasin
  • Posts: 1628
  • Ukraine
Re: lookup between CSV files
« Reply #3 on: November 08, 2022, 05:49:50 PM »
read-line function reads a line and moves the pointer to the next line
so you cannot read-line one and the same line twice

i advise you read both files into separate lists and then do your stuff

nekonihonjin

  • Newt
  • Posts: 103
Re: lookup between CSV files
« Reply #4 on: November 08, 2022, 06:05:06 PM »
read-line function reads a line and moves the pointer to the next line
so you cannot read-line one and the same line twice

i advise you read both files into separate lists and then do your stuff

I make two different lists, the first one called lst and the other one lst2,
I really have no idea how to get all the information of each file and save it in a list.
and to search for information between lists I would also need some help to know where to start.

BIGAL

  • Swamp Rat
  • Posts: 1408
  • 40 + years of using Autocad
Re: lookup between CSV files
« Reply #5 on: November 08, 2022, 06:59:27 PM »
Step1

Code: [Select]
(while (setq nline (read-line fo))
    (setq lst (cons (_csv->lst nline) lst))
)
(while (setq nline (read-line fo2))
    (setq lst2 (cons (_csv->lst nline) lst2))
)

ok now you can take say the 1s row of say lst get which variable you want to look for in lst2, then loop through lst2 and check for a match.

It will be a double foreach. A simple example.

Code: [Select]
(foreach val lst
(setq valtolookfor (nth x lst))
(foreach val2 lst2
(if (= valtolookfor (nth y val2))
do something here
)
)
)
A man who never made a mistake never made anything

nekonihonjin

  • Newt
  • Posts: 103
Re: lookup between CSV files
« Reply #6 on: November 08, 2022, 08:08:05 PM »
Step1

Code: [Select]
(while (setq nline (read-line fo))
    (setq lst (cons (_csv->lst nline) lst))
)
(while (setq nline (read-line fo2))
    (setq lst2 (cons (_csv->lst nline) lst2))
)





ok now you can take say the 1s row of say lst get which variable you want to look for in lst2, then loop through lst2 and check for a match.

It will be a double foreach. A simple example.

Code: [Select]
(foreach val lst
(setq valtolookfor (nth x lst))
(foreach val2 lst2
(if (= valtolookfor (nth y val2))
do something here
)
)
)


Thanks BIGAL, going that way.




*************** update*************

Code: [Select]
(setq fo (open fon "R"))
(setq lst '())
(while (setq nline (read-line fo))
    (setq lst (cons (_csv->lst nline) lst))
)

(setq fo2 (open fo2n "R"))
(setq lst2 '())
(while (setq nline (read-line fo2))
    (setq lst2 (cons (_csv->lst nline) lst2))
)

(foreach val lst
         (setq ID (nth 0 val) from (nth 1 val) to (nth 2 val) AU (nth 3 val) AG (nth 4 val) PB (nth 5 val) ZN (nth 6 val) CU (nth 7 val))
         (if (/= ID IDp)
           (progn
             (foreach val2 lst2
                (setq ID2 (nth 0 val2) X (nth 1 val2) Y (nth 2 val2) Z (nth 3 val2) depth (nth 4 val2) azim (nth 5 val2) inclin (nth 6 val2))
                (if (= ID ID2)
                 (progn
                   (setq romp (list (atof X) (atof Y) (atof Z)))
                   (setq az (dtr (aztocad (atof azim))))
                   (setq incl (atof inclin))
                   (setvar "clayer" "0")
                   (Text romp 1 ID2)
                 );prog
               );if
             );foreach
           );progn
         );if
do stuff...


it's done, thanks for the tips.

« Last Edit: November 09, 2022, 05:33:13 PM by nekonihonjin »

BIGAL

  • Swamp Rat
  • Posts: 1408
  • 40 + years of using Autocad
Re: SOLVED_lookup between CSV files
« Reply #7 on: November 09, 2022, 06:32:58 PM »
No worries a pretty common problem.
A man who never made a mistake never made anything