how to import data from csv file

how to import data from csv file

Yamishon_Noah
Enthusiast Enthusiast
9,208 Views
32 Replies
Message 1 of 33

how to import data from csv file

Yamishon_Noah
Enthusiast
Enthusiast

Hi,

 

Please find below lisp I'm using manually adding commands to run the lisp. 

 

I would like to make it as lisp should call csv file (data) and execute the lisp.

 

Below is the lisp (never mind other functions of lisp)

 

 

 

(defun c:mk ( / *error* osm tag)
    (defun *error* (msg)
        (if osm
            (setvar 'OSMODE osm)
        )
        (cond ((not msg))
              ((member msg '("Function cancelled" "quit / exit abort")))
              ((princ (strcat "\n** Error: " msg " ** ")))
        )
        (princ)
    )
    (setq osm (getvar 'OSMODE))
    (setvar 'OSMODE 0)
    (if (not (tblsearch "APPID" "Ishwinder_LineTag"))
            (regapp "Ishwinder_LineTag")
        )
    (defun tag (name)
        (entmod (append (entget (entlast)) (list (list -3 (list "Ishwinder_LineTag" '(1002 . "{") (cons 1000  name) '(1002 . "}"))))))
    )

(command "_layer" "n" "_3D_poly" "")
(command "_layer" "c" "82" "_3D_poly" "")
(command "_layer" "s" "_3D_poly" "")
(command "_3DPOLY" "3835007,3178626,21298" "3835007,3178626,20200" "3835007,3185013,20200" "3817101,3185013,20200" "")
(tag "cable-1")

    (*error* nil)
    (princ)
)

 

in above codes, I want to keep following data in csv file 

 

(command "_layer" "n" "_3D_poly" "")
(command "_layer" "c" "82" "_3D_poly" "")
(command "_layer" "s" "_3D_poly" "")
(command "_3DPOLY" "3835007,3178626,21298" "3835007,3178626,20200" "3835007,3185013,20200" "3817101,3185013,20200" "")
(tag "cable-1")

 

these 5 lines I kept for example, like this there are more than 1000 lines (basically commands).

 

So I want to edit that lisp, it shall call csv file to get these data to execute it.

 

I hope it can be done..

 

kindly help me out.

 

Thanks

 

mk

 

0 Likes
Accepted solutions (2)
9,209 Views
32 Replies
Replies (32)
Message 21 of 33

Yamishon_Noah
Enthusiast
Enthusiast

Hi @pbejse, Thanks very much for your esteemed effort.. Smiley Happy

 

I will check the same and let you know by tomorrow..

 

Thanks again

 

mk

0 Likes
Message 22 of 33

pbejse
Mentor
Mentor

Amendment on the code. 

 

Replace this 

 

 

 (entmakex
        (list (cons 0 "TEXT")
              (cons 10 (list (Car pt1)(+ 67.5 (cadr pt1)) (caddr pt1)))
              (cons 40 54.0)
              (cons 8 "_End2_Text")
              (cons 1 (strcat (cadr data) "_" (nth 4 data)))))

 

With this..at "_End2_Text" section of the code

 

 

(entmakex
        (list (cons 0 "TEXT")
              (cons 10 (list (Car pt1)(+ 100.00 (cadr pt1)) (caddr pt1)))
              (cons 40 54.0)
              (cons 8 "_End2_Text")
              (cons 1 (strcat (nth 5 data) "_" (nth 21 data)))))

 

Sorry about that.. done in haste.

 

Message 23 of 33

Yamishon_Noah
Enthusiast
Enthusiast

hi @pbejse First of all.. it surprised me totally.. it worked very well.. Smiley Very Happy  Thanks a ton actually

 

I have few questions to discuss with,

 

1. Both codes (lisp) does the same function?

        i.e. i3DPL program refers final CSV file (which I had to extract from "3D_poly_working" tab separately for one by one rows)

             FirsttabCSV program refers to directly ""3D_poly_working" which is First tab in your file.

                  My understanding here is correct?

                  If it is correct then I prefer to use FirsttabCSV program only because I will not make third tab it will save more n more time for me. 

 

2. FirsttabCSV program refers Column "AA", "AH" & "AL" in first tab.csv file correct?  why Im asking this because I will keep the format as it is for future files also. And tell me how many rows program can refer? any limit is there?

 

 

 

Kind request, I would like bring a dialog box once lisp loaded, messages like "First message line" , "Second message line"  and "Third message line" I have tried this but could not do properly.. 

 

Thanks very much Smiley Happy

 

mk

 

 

0 Likes
Message 24 of 33

Yamishon_Noah
Enthusiast
Enthusiast

@pbejse Continuation to earlier post,

 

I want to add two more points for 3d polyline (now 5 points and it will be 7 points) so while I insert column (6nos) will lisp affect? any change required in program?.. pls let me know...

 

thanks again,,

 

mk

0 Likes
Message 25 of 33

pbejse
Mentor
Mentor

@thegreatkarthik67 wrote:

hi @pbejse First of all.. it surprised me totally.. it worked very well.. Smiley Very Happy  Thanks a ton actually...


You are welcome mk, glad it works for you.

 


I have few questions to discuss with,

 

1. Both codes (lisp) does the same function?

        i.e. i3DPL program refers final CSV file (which I had to extract from "3D_poly_working" tab separately for one by one rows)

             FirsttabCSV program refers to directly ""3D_poly_working" which is First tab in your file.

                  My understanding here is correct?

                  If it is correct then I prefer to use FirsttabCSV program only because I will not make third tab it will save more n more time for me.  


Does the same thing but only up to the point of reading the csv file, FirsttabCSV refers to the saved CSV version of "3D_poly_working" tab. and yes you don't have to create the third tab "Final for CSV - to run LISP" for FirsttabCSV to work.

 


2. FirsttabCSV program refers Column "AA", "AH" & "AL" in first tab.csv file correct?  why Im asking this because I will keep the format as it is for future files also. And tell me how many rows program can refer? any limit is there? 


No mk, not really, FirsttabCSV will still work without those columns, Better to keep those so may copy and paste the values from those cells and paste it directly in Autocad command prompt for sanity check. It wouldn't affect  FirsttabCSV program in any way.  Not that i'm aware of.

 

The FirsttabCSV  rely on the data from "3D_poly_working" tab columns B to V and "End_2 DETAIL_working" tab,  just because "3D_poly_working" columns T, U & V  use the VLOOKUP function to determine the value from tab "End_2 DETAIL_working".

 

The user need to save a csv copy of only the "3D_poly_working"  tab.

 

As for my query regarding "_JB_Text" values and location, I know this came from "End_2 DETAIL_working" tab, but i think i can code it so program that can generate the text without saving a CSV version of the second tab.

 

But first explain to me the logic behind "_JB_Text" values. 


Kind request, I would like bring a dialog box once lisp loaded, messages like "First message line" , "Second message line"  and "Third message line" I have tried this but could not do properly.. 

 

Thanks very much Smiley Happy

 

mk


At loading? or at beginning at run-time? at the end?

 

pBe

 

EDIT:


....I want to add two more points for 3d polyline (now 5 points and it will be 7 points) so while I insert column (6nos) will lisp affect? any change required in program?.. pls let me know... 

 


 I'm sure we can do that.

 

0 Likes
Message 26 of 33

Yamishon_Noah
Enthusiast
Enthusiast

pbejse wrote:


Does the same thing but only up to the point of reading the csv file, FirsttabCSV refers to the saved CSV version of "3D_poly_working" tab. and yes you don't have to create the third tab "Final for CSV - to run LISP" for FirsttabCSV to work.


--> Its great... I will use only first tab program.. 🙂

 


No mk, not really, FirsttabCSV will still work without those columns, Better to keep those so may copy and paste the values from those cells and paste it directly in Autocad command prompt for sanity check. It wouldn't affect  FirsttabCSV program in any way.  Not that i'm aware of.

The FirsttabCSV  rely on the data from "3D_poly_working" tab columns B to V and "End_2 DETAIL_working" tab,  just because "3D_poly_working" columns T, U & V  use the VLOOKUP function to determine the value from tab "End_2 DETAIL_working".

The user need to save a csv copy of only the "3D_poly_working"  tab.

--> Okay I got you..

 

As for my query regarding "_JB_Text" values and location, I know this came from "End_2 DETAIL_working" tab, but i think i can code it so program that can generate the text without saving a CSV version of the second tab.

But first explain to me the logic behind "_JB_Text" values.

 

--> regarding texts placement, 

 

     1. Inst text which in first tab "3D_poly_working" column B shall be placed in coordinate mentioned in columns C,D,E.

     2. JB text which in second tab "End_2 DETAIL_working" column B shall be placed in coordinate mentioned in columns C,D,E.

     3. Earlier Destination text which in first tab "3D_poly_working" Column F shall be placed in below of inst. text (consider 100mm below in Y direction) but now I feel its not required.. we no need to consider

 

There will be only two texts sufficient now..

 

here can we ask user to mention text height required? once user selected csv file, dialog box shall pop to enter Text height...

instead of standard height mentioned in program


Kind request, I would like bring a dialog box once lisp loaded, messages like "First message line" , "Second message line"  and "Third message line" I have tried this but could not do properly.. 

Thanks very much Smiley Happy

mk


At loading? or at beginning at run-time? at the end?

pBe

EDIT:

 

---> once program loaded in autocad "3 lines of message" to be appeared on screen (dialog box)

      At the end (program completed)  "3 lines of message" to be appeared on screen (dialog box)


....I want to add two more points for 3d polyline (now 5 points and it will be 7 points) so while I insert column (6nos) will lisp affect? any change required in program?.. pls let me know... 


 I'm sure we can do that.


---> I will insert 6 columns for 2 points between T & V in first tab.... kindly tell me in program which line consider this thing i.e. where you have defined no of columns (start & end columns)

 

Thank you very much for your time and tremendous efforts..

 

mk

 

 

 

0 Likes
Message 27 of 33

pbejse
Mentor
Mentor

@thegreatkarthik67 wrote:

 

---> I will insert 6 columns for 2 points between T & V in first tab.... kindly tell me in program which line consider this thing i.e. where you have defined no of columns (start & end columns)

We will write the code in such a way that it doesn't matter how many additional columns as long as it meets the criteria for a point list. So no need to update the code whenever you add or remove columns. 

 

Starting form column H of course. +2 : 3 columns 

 

0 Likes
Message 28 of 33

pbejse
Mentor
Mentor
Accepted solution

@thegreatkarthik67 wrote:

 


.....

here can we ask user to mention text height required? once user selected csv file, dialog box shall pop to enter Text height...

instead of standard height mentioned in program

.....

---> once program loaded in autocad "3 lines of message" to be appeared on screen (dialog box)

      At the end (program completed)  "3 lines of message" to be appeared on screen (dialog box)

---> I will insert 6 columns for 2 points between T & V in first tab.... kindly tell me in program which line consider this thing i.e. where you have defined no of columns (start & end columns)

 

Thank you very much for your time and tremendous efforts..

mk


Here you go.

 

The attached lisp file  should take care of all the above

 

Have fun

 

Cheers

 

Message 29 of 33

Yamishon_Noah
Enthusiast
Enthusiast

Hi @pbejse I'm very excited to check your program.. I will tell my feedback tomorrow... Thank you so much Smiley Very HappySmiley Very HappySmiley Very Happy 

0 Likes
Message 30 of 33

pbejse
Mentor
Mentor

@thegreatkarthik67 wrote:

Hi @pbejse I'm very excited to check your program.. I will tell my feedback tomorrow... Thank you so much Smiley Very HappySmiley Very HappySmiley Very Happy 


Yes, please do tell us how it goes. 

 

pBe

 

0 Likes
Message 31 of 33

Yamishon_Noah
Enthusiast
Enthusiast

Hi... @pbejse.. really its rocks.. excellent work done by you, totally impressed..... I want to learn program things.. Thank you a lot pBe

0 Likes
Message 32 of 33

pbejse
Mentor
Mentor

@thegreatkarthik67 wrote:

Hi... @pbejse.. really its rocks.. excellent work done by you, totally impressed..... I want to learn program things.. Thank you a lot pBe


Glad everything worked out for you.

 

You are welcome, till next time.

 

Cheers

 

0 Likes
Message 33 of 33

pbejse
Mentor
Mentor
Accepted solution
And then...

.....We have used 3D polyline to draw on as per coordinates, Can we have optional one? that is 2D polyline which will take only X,Y from excel (csv) and it will draw on autocad

 

Remains everything same..  


See attached lisp file [ FirstTabCSV_2d3d.lsp ]

 

command: <dialog box "Select CSV file">

 

Enter Text Height <50.00>:  

 

Choose option [3D/2D] <3D>:

 

HTH

 

0 Likes