robwalker24 Posted May 23, 2011 Share Posted May 23, 2011 Hi guys, I currently have a .txt file which has x and y coordinates as well as an IDname for around 200 items. I would like to create a lisp routine that reads this text file and inserts a block (point.dwg) to the coordinates and enters the IDname into the Name attribute. The text file is in the following format: 60000.000 6000000.000 Structure1 I have found this helpful so far but cannot figure out how to modify it to suit my needs: (defun c:insertBlocks (/ txtFile xyData expertVar attreqVar) (setq expertVar (getvar "expert")) (setq attreqVar (getvar "attreq")) (setvar "expert" 2) (setvar "attreq" 0) (setq txtFile (open "c:\\cad\\textfile.txt" "r")) ; give the path & file name of x,y data (while (setq xyData (read-line txtFile)) (command "-insert" "point" xyData "1" "1" "0") ) (close txtFile) (setvar "expert" expertVar) (setvar "attreq" attreqVar) (princ) ) Any help would be very much appreciated. Thanks very much! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 23, 2011 Share Posted May 23, 2011 (edited) Not my best code, but should do your bidding (defun c:test ( / *error* _str->lst bl fn fo ln ov vl x y ) (setq fn "C:\\cad\\textfile.txt" ;; Filename of Text file (nil for prompt) bl "point" ;; Block Name (must be in Drawing or Support Path) ) (defun *error* ( msg ) (if ov (mapcar 'setvar vl ov)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (defun _str->lst ( str del / pos ) (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (_str->lst (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) (cond ( (not (or (setq fn (findfile fn)) (setq fn (getfiled "" "" "txt" 16)) ) ) (princ "\n*Cancel*") ) ( (not (or (tblsearch "BLOCK" bl) (setq bl (findfile (strcat bl ".dwg"))) ) ) (princ "\n--> Block not Found.") ) ( (not (setq fo (open fn "r"))) (princ "\n--> Error Opening File.") ) (t (setq vl '("CMDECHO" "OSMODE" "ATTREQ") ov (mapcar 'getvar vl)) (mapcar 'setvar vl '(0 0 1)) (while (setq ln (read-line fo)) (if (and (< 2 (length (setq ln (_str->lst ln " ")))) (setq x (distof (car ln))) (setq y (distof (cadr ln))) ) (command "_.-insert" bl "_S" "1" "_R" "0" (list x y 0.0) (caddr ln)) ) ) (setq fo (close fo)) (mapcar 'setvar vl ov) ) ) (princ) ) (vl-load-com) (princ) Maybe also try my Point Manager program. Edited May 23, 2011 by Lee Mac Quote Link to comment Share on other sites More sharing options...
robwalker24 Posted May 23, 2011 Author Share Posted May 23, 2011 Lee, Thanks very much for your quick reply. I am unable to get that particular code working. When I run it I get the following message in the command line: Value must be nonzero. Enter Y scale factor : I apologise if I am missing something here, pretty new to this stuff! Thanks again, Cheers Quote Link to comment Share on other sites More sharing options...
stevesfr Posted May 23, 2011 Share Posted May 23, 2011 Lee, Thanks very much for your quick reply. I am unable to get that particular code working. When I run it I get the following message in the command line: Value must be nonzero. Enter Y scale factor : I apologise if I am missing something here, pretty new to this stuff! Thanks again, Cheers Rob, I think the program is perhaps using the wrong Point block that has too many attributes. Make a new block and call it something like point1 having only one attribute named "structure". Modify Lees code to now look for your new block called point1 or whatever. save it to where acad can find it and I think all will be cool. Steve Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 23, 2011 Share Posted May 23, 2011 Sorry Rob, I don't use the "-Insert" command in LISP too often, but it appears the prompts vary from version to version - I have now updated the code above to explicitely state the scale and rotation and bypass the prompts. Lee Quote Link to comment Share on other sites More sharing options...
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.