aaryan Posted June 11, 2012 Posted June 11, 2012 Hi all, I am getting an error (bad argument value: does not fit in byte) after running this code cant find solution yet. Please help. (defun c:Bathy (/ tpath fd info Soundings Bs Bsc BSL data ipt ba tpt x y xs ys) (defun *error* (msg) (if msg (princ (strcat "\nError! " msg))) (princ) ) ;//pBe (defun _roundTruncated (a) (setq b (fix a) c (* (abs (- a b)) 10)) (if (= c 0) (setq d 0) (setq d (fix (+ c (/ c (abs c) 2.0)))))) ;// (setq tpath (getfiled "Select XYZ File" "*.*" "" 4)) (setvar "cmdecho" 0) (setvar "osmode" 0) (graphscr) (setq fd (open tpath "r") info (read-line fd) ) (if (/= info nil) (progn (if (setq Soundings (getfiled "Select Sounding Block" "*.*" "dwg" 4)) (progn (setq Bs (Getreal "\nScale factor for Bathymetry Block <1>:")) (if (= Bs Nil) (setq Bsc 1) (setq Bsc Bs) ))(exit)) ) (progn (alert "Bathy file is empty") (exit)) ) (setq Bsl (rtos Bsc 2 3)) (while (/= info nil) (setq data (read (strcat "(" (vl-string-translate "," " " info) ")")) ipt (list (car data)(cadr data)) bat (atof (rtos (caddr data) 2 4)) tpt data) (setq xfin 0 yfin 0 zfin 0) (Setq xfin (car data) yfin (cadr data) zfin (caddr data)) (setq xfin (1+ xfin) yfin (1+ yfin) zfin (1+ zfin)) (setq xlst (cons xfin xlst) ylst (cons yfin ylst) zlst (cons zfin zlst)) (setq xmax (apply 'max xlst) xmax (eval (cons 'max xlst)) ymax (apply 'max ylst) ymax (eval (cons 'max ylst)) zmax (apply 'max zlst) zmax (eval (cons 'max zlst))) (setq xmin (apply 'min xlst) xmin (eval (cons 'min xlst)) ymin (apply 'min ylst) ymin (eval (cons 'min ylst)) zmin (apply 'min zlst) zmin (eval (cons 'min zlst))) (command "_.zoom" "W" (list xmin ymin) (list xmax ymax)) (if (< bat 0) (progn (setq ba (* -1 bat) x (fix ba) y (_roundTruncated bat)) (if (= y 10) (progn (setq x (+ x 1) y 0)) (progn (setq x x y y))) (setq xs (strcat "%%U" (itoa x)) ys (itoa y)) (command "insert" Soundings ipt Bsl Bsl 0 xs ys) (setq info (read-line fd))) (progn (setq x (fix bat) y (_roundTruncated bat)) (if (= y 10) (progn (setq x (+ x 1) y 0)) (progn (setq x x y y))) (setq xs (itoa x) ys (itoa y)) (command "insert" Soundings ipt Bsl Bsl 0 xs ys) (setq info (read-line fd)) ))) (close fd) (command "regen") (setvar "osmode" 31743) (*error* nil) (princ) ) Quote
aaryan Posted June 11, 2012 Author Posted June 11, 2012 Thanks pBe I was waiting for and glad to see your reply. Actually i am trying find out the minimum and maximum x, y and z value from the xyz file. and after getting min x min y and max x and max y, i will use the (command _.zoom "W" (list minx miny) (list maxx maxy)). simply saying i want to zoom extent the area of interest and then my command insert should start. Quote
pBe Posted June 11, 2012 Posted June 11, 2012 Actually i am trying find out the minimum and maximum x, y and z value from the xyz file.and after getting min x min y and max x and max y, i will use the (command _.zoom "W" (list minx miny) (list maxx maxy)). simply saying i want to zoom extent the area of interest and then my command insert should start. I see, From the looks of how the code is written now. You want to "zoom" before every insert. is that the way you wanted it? For one thing xlist,ylst,zlst on the first run will pass the same point value for zoom window... result *invalid* Suggestion: Collect all data from external file then run insert & Zoom (if thats what you want) from the collected list. you can however tweak you code to include a condtion that only when there are two or more data on the xlst/ylst/zlst the it wil start the zoom thingy. And you know what even with that. you wont really "see" the zoom part of your code until the last insert. So, collelct data. retrieve max / min, invoke zoom, then start inserting. Got it? Quote
aaryan Posted June 11, 2012 Author Posted June 11, 2012 thanks, Not on every insert i want to zoom but to zoom to the extents of the whole area before importing blocks. for eg. my file contains 200,300,13.5 300,500,14.6 500,100,17.1 800,1000,19.9 then i want to zoom window ( list (xmin)200 (ymin)100 ) ( list (xmax)800 (ymax)1000) the whole area and starts importing. Hope i could do it. Regards Quote
pBe Posted June 11, 2012 Posted June 11, 2012 thanks,then i want to zoom window ( list (xmin)200 (ymin)100 ) ( list (xmax)800 (ymax)1000) the whole area and starts importing. Hope i could do it. Regards (defun _HiLow (lev lev2 lst) (list (apply lev (mapcar 'car lst)) (apply lev2 (mapcar 'cadr lst)) )) (progn (setq fd (open tpath "r")) (while (setq info (read-line fd)) (setq Pdata (cons (read (strcat "(" (vl-string-translate "," " " info) ")")) Pdata)) ) (close fd) (command "_.zoom" "w" (_HiLow 'min 'min [b]Pdata[/b])(_HiLow 'max 'max [b]Pdata[/b])) ....... <the rest of your code> ......... Where Pdata is a list of points derived from the external file ((200 300 13.5) (300 500 14.6) (500 100 17.1) (800 1000 19.9)) You can do you manipulation off the list (foreach item Pdata (do this..)) Try it first, if you hit a snag, do not hesitate to ask EDIT: You can however Zoom out AFTER, Collecting point list while inserting blocks,, that will cut down the processing time, but just a tad i guess Quote
aaryan Posted June 11, 2012 Author Posted June 11, 2012 Thanks a LOT.. I will give it a try and let you know how it works Tomorrow as my office time is over... Thanks again and have a good day.. Quote
aaryan Posted June 11, 2012 Author Posted June 11, 2012 (edited) I am confused pBe.. Please look into it. this is my actual code i am using and failing to insert your code on suitable place. Please do this favor for me. (defun c:Bathy (/ tpath fd info Soundings Bs Bsc BSL data ipt ba tpt x y xs ys) (defun *error* (msg) (if msg (princ (strcat "\nError! " msg))) (princ) ) ;//pBe (defun _roundTruncated (a) (setq b (fix a) c (* (abs (- a b)) 10)) (if (= c 0) (setq d 0) (setq d (fix (+ c (/ c (abs c) 2.0)))))) ;// ;//pBe (defun _HiLow (lev lev2 lst) (list (apply lev (mapcar 'car lst)) (apply lev2 (mapcar 'cadr lst)) )) ;// (setq tpath (getfiled "Select XYZ File" "*.*" "" 4)) (setvar "cmdecho" 0) (setvar "osmode" 0) (graphscr) (setq fd (open tpath "r") info (read-line fd) ) (if (/= info nil) (progn (if (setq Soundings (getfiled "Select Sounding Block" "*.*" "dwg" 4)) (progn (setq Bs (Getreal "\nScale factor for Bathymetry Block <1>:")) (if (= Bs Nil) (setq Bsc 1) (setq Bsc Bs) ))(exit)) ) (progn (alert "Bathy file is empty") (exit)) ) (setq Bsl (rtos Bsc 2 3)) (while (/= info nil) (setq data (read (strcat "(" (vl-string-translate "," " " info) ")")) ipt (list (car data)(cadr data)) bat (atof (rtos (caddr data) 2 4)) tpt data) (if (< bat 0) (progn (setq ba (* -1 bat) x (fix ba) y (_roundTruncated bat)) (if (= y 10) (progn (setq x (+ x 1) y 0)) (progn (setq x x y y))) (setq xs (strcat "%%U" (itoa x)) ys (itoa y)) (command "insert" Soundings ipt Bsl Bsl 0 xs ys) (setq info (read-line fd))) (progn (setq x (fix bat) y (_roundTruncated bat)) (if (= y 10) (progn (setq x (+ x 1) y 0)) (progn (setq x x y y))) (setq xs (itoa x) ys (itoa y)) (command "insert" Soundings ipt Bsl Bsl 0 xs ys) (setq info (read-line fd)) ))) (close fd) (command "zoom" "e") (command "regen") (setvar "osmode" 31743) (*error* nil) (princ) ) At which line i should insert your given code for zoom window I am trying but failing. Edited June 11, 2012 by aaryan Quote
pBe Posted June 11, 2012 Posted June 11, 2012 (edited) I am confused pBe.. Please look into it.this is my actual code i am using and failing to insert your code on suitable place. Please do this favor for me. At which line i should insert your given code for zoom window I am trying but failing. Forgive the crudeness of the code, i maintain most of your coding otherwise it would be a complete re-write, and you dont want that really. the more the orignal code, the better for you to understand. (defun c:Bathy (/ tpath fd info Soundings Bs Bsc BSL Pdata data ipt ba tpt x y xs ys) [color=blue](vl-load-com)[/color] (defun *error* (msg) (if msg (princ (strcat "\nError! " msg))) (princ) ) ;//pBe (defun _roundTruncated (a) (setq b (fix a) c (* (abs (- a b)) 10)) (if (= c 0) (setq d 0) (setq d (fix (+ c (/ c (abs c) 2.0)))))) (defun _HiLow (lev lev2 lst) (list (apply lev (mapcar 'car lst)) (apply lev2 (mapcar 'cadr lst)) )) ;// [color=blue](defun _errormsg ( lst / x )[/color] [color=blue](if (setq x (vl-some '(lambda ( x ) (if (null (eval (car x))) (cadr x))) lst))[/color] [color=blue](alert x)[/color] [color=blue])[/color] [color=blue])[/color] (setvar "cmdecho" 0) (graphscr) [color=blue](if (and[/color] (setq Pdata nil tpath (getfiled "Select XYZ File" "*.*" "txt" 4)) [color=blue](setq fsz (> (vl-file-size tpath) 0))[/color] (setq Soundings (getfiled "Select Sounding Block" "*.*" "dwg" 4)) [color=blue](progn[/color] (setq Bs (Getreal "\nScale factor for Bathymetry Block <1>:")) (if (= Bs Nil) (setq Bsc 1) (setq Bsc Bs))[color=blue])[/color] [color=blue])[/color] (progn (setq fd (open tpath "r")) (setq Bsl (rtos Bsc 2 3)) (while (setq info (read-line fd)) (setq Pdata (cons (read (strcat "(" (vl-string-translate "," " " info) ")")) Pdata)) ) (close fd) (command "_.zoom" "w" (_HiLow 'min 'min Pdata)(_HiLow 'max 'max Pdata)) (foreach data Pdata (setq ipt (list (car data) (cadr data)) bat (atof (rtos (caddr data) 2 4)) tpt data) (if (< bat 0) (progn (setq ba (* -1 bat) x (fix ba) y (_roundTruncated bat)) (if (= y 10) (progn (setq x (+ x 1) y 0)) (progn (setq x x y y))) (setq xs (strcat "%%U" (itoa x)) ys (itoa y)) ) (progn (setq x (fix bat) y (_roundTruncated bat)) (if (= y 10) (progn (setq x (+ x 1) y 0)) (progn (setq x x y y))) (setq xs (itoa x) ys (itoa y)) )) (command "insert" Soundings [color=blue]"_scale" Bsl "_non" ipt[/color] 0 xs ys) (runtime ".... Creating Soundings") ) ;(command "zoom" "e") (command "regen") ) [color=blue](_errormsg[/color] [color=blue] '([/color] [color=blue] (tpath "Failed to select Data File")[/color] [color=blue] (fsz "Bathy file is empty")[/color] [color=blue] (Soundings "Failed to select Block")[/color] [color=blue] )[/color] [color=blue])[/color] ) (*error* nil) (princ) ) What is (runtime..) function? System variables to consider: Attreq Dimzin I would suggest you look into error handling Error Handling by Lee Mac HTH Edited June 11, 2012 by pBe Quote
aaryan Posted June 11, 2012 Author Posted June 11, 2012 Thanks You, Thanks for maintaining my codes and for correcting it to the end. Being a newbie I will not understand your codes if you rewrite it. My last request for this thread is Please suggest me some good VISUAL LISP tutorial books Whatever I learned is from Jeffery P Sanders site a good tutorial for beginners of autolisp but for Visual Lisp?.. BTW runtme function my colleague used to use its like a continous dots will appear when importing blocks or so I removed it so that if any newbie want to use this routine he shouldn't get confused. Thanks and Regards Aaryan Quote
BlackBox Posted June 11, 2012 Posted June 11, 2012 Thanks You,Whatever I learned is from Jeffery P Sanders site a good tutorial for beginners of autolisp but for Visual Lisp?.. Visual LISP Developer's Bible, 2011 Edition - David M. Stein, only $6.99 at Amazon This is a great book, and David's a really nice guy personally as well (had an opportunity to speak with him). Quote
pBe Posted June 11, 2012 Posted June 11, 2012 Lee Mac Programming Afralisp Autodesk University on-line courses Also look out for Visual Lisp Developers Bible by David Stein Now i remember, this is where i really started >>>> CADTutor HTH EDIT: [i'm toooo sloooww] ...... Quote
aaryan Posted June 12, 2012 Author Posted June 12, 2012 Thank You, Where there is a will, there is a way. I will go through it and let you know. Regards Quote
Recommended Posts
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.