Jump to content

Recommended Posts

Posted

How to export these points from excel to autocad?

A72EEA53-2E61-458F-864E-FD72BF9591AC.png

Posted

1 need the xl file

 

2 need a explanation as to what the values mean, are the XY twice meaning a LINE ?

 

 

Posted (edited)

You want to draw lines with those coordinates, right?

-To make it easy, save the Excel file as csv (3 line sample in attachment here)

- top of the script, make sure the settings of the file match (this can be handled with open file dialog if needed)

- I just take the coordinates and ignore all other columns.

 

type command IMC (for Import Lines Csv)

  I call it import, from the point of view of Autocad.

 

 (vl-load-com)

 ;; SETTINGS
 ;; you need to set this to the path and filename on your computer
(setq csv_file "C:\\Data\\desktop\\lisp\\CADTUTOR\\import_lines_csv.csv")
;; delimitor.  Check how Excel saves the file to CSV.  Either comma or somicolon
(setq csvdelimiter ",") 
;;(setq csvdelimiter ";") 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://www.lee-mac.com/readcsv.html
;; Read CSV  -  Lee Mac
;; Parses a CSV file into a matrix list of cell values.
;; csv - [str] filename of CSV file to read

(defun LM:readcsv ( csv / des lst sep str )
    (if (setq des (open csv "r"))
        (progn
            (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (csvdelimiter)))
            (while (setq str (read-line des))
                (setq lst (cons (LM:csv->lst str sep 0) lst))
            )
            (close des)
        )
    )
    (reverse lst)
)

;; CSV -> List  -  Lee Mac
;; Parses a line from a CSV file into a list of cell values.
;; str - [str] string read from CSV file
;; sep - [str] CSV separator token
;; pos - [int] initial position index (always zero)
 
(defun LM:csv->lst ( str sep pos / s )
    (cond
        (   (not (setq pos (vl-string-search sep str pos)))
            (if (wcmatch str "\"*\"")
                (list (LM:csv-replacequotes (substr str 2 (- (strlen str) 2))))
                (list str)
            )
        )
        (   (or (wcmatch (setq s (substr str 1 pos)) "\"*[~\"]")
                (and (wcmatch s "~*[~\"]*") (= 1 (logand 1 pos)))
            )
            (LM:csv->lst str sep (+ pos 2))
        )
        (   (wcmatch s "\"*\"")
            (cons
                (LM:csv-replacequotes (substr str 2 (- pos 2)))
                (LM:csv->lst (substr str (+ pos 2)) sep 0)
            )
        )
        (   (cons s (LM:csv->lst (substr str (+ pos 2)) sep 0)))
    )
)

(defun LM:csv-replacequotes ( str / pos )
    (setq pos 0)
    (while (setq pos (vl-string-search  "\"\"" str pos))
        (setq str (vl-string-subst "\"" "\"\"" str pos)
              pos (1+ pos)
        )
    )
    str
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun drawLine (p1 p2)
 (entmakex (list (cons 0 "LINE")
                 (cons 10 p1)
                 (cons 11 p2)))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;; IMC for Import Lines Csv
(defun c:IMC ( / csv_data  i a)
	(setq csv_data (LM:readcsv  csv_file))
	(setq i 0)
	(foreach a csv_data				;; a is 1 line of the csv data
		(if (> i 0) (progn			;; Skip the first line that holds the title of the columns
			(drawLine
				(list (atof (nth 0 a))  (atof (nth 1 a))  (atof (nth 4 a)) )
				(list (atof (nth 2 a))  (atof (nth 3 a))  (atof (nth 5 a)) )
			)
		))
		(setq i (+ i 1))
	)
	
	(princ)
)

 

import_lines_csv.csv

Edited by Emmanuel Delay
  • Like 1
Posted

thanks for the reply but i need to draw a line with angle.

Posted

Please answer my two questions. Then we can help. You have more values than just a pt angle and distance is this in your other post ?

Posted

I have starting point of line x and y, the angle and its span of length. 

Posted

YEAH BUT WHICH VARIABLES ! You have 8 columns in the image.

 

It may be a language problem but your not explaining what to use, the answer is so simple.

Posted

X and y are the coordinates or starting point of line, from there the line has to travel in an angle of 270 degree for a length if 10m

Posted (edited)

Alright.

Same as last code, but now with polar coordinates.

 

command IMCP for Import Lines Csv Polar

Again, change the path settings. I now call it "import_lines_csv_polar.csv", see attachment

 

 (vl-load-com)

 ;; SETTINGS
 ;; you need to set this to the path and filename on your computer
    ;;(setq csv_file "C:\\Data\\desktop\\lisp\\CADTUTOR\\import_lines_csv.csv")
(setq csv_file "C:\\Data\\desktop\\lisp\\CADTUTOR\\import_lines_csv_polar.csv")

;; delimitor.  Check how Excel saves the file to CSV.  Either comma or somicolon
(setq csvdelimiter ",") 
;;(setq csvdelimiter ";") 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://www.lee-mac.com/readcsv.html
;; Read CSV  -  Lee Mac
;; Parses a CSV file into a matrix list of cell values.
;; csv - [str] filename of CSV file to read

(defun LM:readcsv ( csv / des lst sep str )
    (if (setq des (open csv "r"))
        (progn
            (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (csvdelimiter)))
            (while (setq str (read-line des))
                (setq lst (cons (LM:csv->lst str sep 0) lst))
            )
            (close des)
        )
    )
    (reverse lst)
)

;; CSV -> List  -  Lee Mac
;; Parses a line from a CSV file into a list of cell values.
;; str - [str] string read from CSV file
;; sep - [str] CSV separator token
;; pos - [int] initial position index (always zero)
 
(defun LM:csv->lst ( str sep pos / s )
    (cond
        (   (not (setq pos (vl-string-search sep str pos)))
            (if (wcmatch str "\"*\"")
                (list (LM:csv-replacequotes (substr str 2 (- (strlen str) 2))))
                (list str)
            )
        )
        (   (or (wcmatch (setq s (substr str 1 pos)) "\"*[~\"]")
                (and (wcmatch s "~*[~\"]*") (= 1 (logand 1 pos)))
            )
            (LM:csv->lst str sep (+ pos 2))
        )
        (   (wcmatch s "\"*\"")
            (cons
                (LM:csv-replacequotes (substr str 2 (- pos 2)))
                (LM:csv->lst (substr str (+ pos 2)) sep 0)
            )
        )
        (   (cons s (LM:csv->lst (substr str (+ pos 2)) sep 0)))
    )
)

(defun LM:csv-replacequotes ( str / pos )
    (setq pos 0)
    (while (setq pos (vl-string-search  "\"\"" str pos))
        (setq str (vl-string-subst "\"" "\"\"" str pos)
              pos (1+ pos)
        )
    )
    str
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun drawLine (p1 p2)
 (entmakex (list (cons 0 "LINE")
                 (cons 10 p1)
                 (cons 11 p2)))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun deg2rad (deg /)
	(* (/ deg 180) pi)
)

;; IMC for Import Lines Csv Polar
(defun c:IMCP ( / csv_data  i a p1 p2)

	;; reset if needed
	(setq csv_data (list))

	(setq csv_data (LM:readcsv  csv_file))
	;;(princ (nth 0 csv_data))
	
	(setq i 0)
	(foreach a csv_data				;; a is 1 line of the csv data
		(if (> i 0) (progn			;; Skip the first line that holds the title of the rows
			(drawLine
				(setq p1 (list (atof (nth 2 a))  (atof (nth 3 a)) ))
				;;(polar pt ang dist)
				(polar p1 (deg2rad (atof (nth 1 a))) (atof (nth 0 a)))
			)
		))
		(setq i (+ i 1))
	)
	
	(princ)
)

 

import_lines_csv_polar.csv

Edited by Emmanuel Delay
Posted

If you have the start and end points you dont need length and angle.

 

Posted

image.png.b99dfe4e27aae614917d5b0bef991023.png

 

DO YOU HAVE ANY FORMULA FOR COMBINING THESE TWO?

Posted

I agree with devitg is it a case of 2 people from 1 company ? Look at other post.

 

 

Posted

Thank you everyone. We have sorted it out

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...