Jump to content

Recommended Posts

Posted

Hi All,

 

I am quite new to an autolisp programming and trying to make a lisp routine which reads xyz from external file and import its z value as a block attribute. So far i've reached is as follows.

 

(defun c:bthy (/ tpath fd info Bs Bsc BSL eas nor ipt ba tpt x y xs ys) 
 (setq tpath (getfiled "Select XYZ File" "*.*" "" 4))
   (setvar "cmdecho" 0)
   (graphscr)
   (setq fd   (open tpath "r")
  info (read-line fd)
   )
   (if	(/= info nil)
     (progn
(setq Soundings (getfiled "Select Sounding Block" "*.*" "dwg" 4))
(setq Bs (Getreal "\nScale factor for Bathymetry Block <1>:"))
(if (= Bs Nil)
  (setq Bsc 1)
  (setq Bsc Bs)
)
     )
     (progn (alert "Bathy file is empty") (exit))
   )
   (setq BSL (rtos Bsc 2 3))
   (while (/= info nil)
     (setq eas	(atof (substr info 1 10))
    nor	(atof (substr info 12 11))
    ipt	(list eas nor)
    ba	(atof (substr info 24 5))
    tpt	(list eas nor ba)
    x	(fix ba)
    y	(fix (* (- ba x) 10))
    xs	(itoa x)
    ys	(itoa y)
     )
     (command "insert" Soundings ipt BSL BSL 0 xs ys)
     (setq info (read-line fd))
   )
   (close fd)
   (COMMAND "zoom" "0.8x")
   (COMMAND "regen")
   (princ)
 )

 

Bathymetry.dwg

 

A file for this code should contain a line as (eg. 500000.000,2150000.000,23.5) any delimiter can be used but X and Y decimal must be 3 and for Z it must be 1.

 

My request and question here is:

1, i always get a text file which has easting northing and elevation with different decimals on every line, how can i make my code to read the file as i get without changing its decimals from excel.

2, I also get files which includes elevations as positive and even negative (i.e 500000.23, 2154356.355, -25.1 and 500101.2, 2155389.24, 24.1), how can i filter all negatives (-) and insert as (%%U25.1).

3, Can i give colors for different values as interval in interger given by user..

 

I hope i am not expecting too big but Please i need help.

Thanks and Regards

Posted

(setq data (read (strcat "(" (vl-string-translate "," " " info) ")")))
(setq ipt (list (car data)(cadr data)))  <----  for (list eas nor)
(setq tpt data)    <----  for (list eas nor ba)

 

To make a string lsit

 

(setq StringData (mapcar '(lambda (k) (itoa (fix k))) data))

Posted

Thank you so much.. pBe..

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...