ClareSelley Posted July 3, 2012 Posted July 3, 2012 Those who have seen my last topic probably know where I'm coming from with this! I now have a nice list of handles and centroids and I've got the below code that is meant to take a file of: "Kitchen 2", -10035, 67822 "Kitchen 3", 50, 60 For example, and put the text at the co-ordinates... However it's not putting it at the RIGHT coordinates - they're all off. Can anyone fix it for me? I've tried poking it with a cautious stick & it's not working.... Bonus kudos if it doesn't need the '""" around the label... ;;; Program to read the output data from the Corpson6 coordinate conversion ;;; By Ron Auble, 01/19/07, Auble Consulting. Last update 01/19/07 ;;; ;;; Passed: Nothing, prompted to select a data file ;;; Return: List of lines from data file in the form of '("Label" X-value Y-value) ;;; (defun ReadUTM ( / FName LINE xFN Comma LblStr RemStr Xord Yord DatITM DatLST) (setq FName (getfiled "Select Data File" (getvar "DWGPREFIX") "txt" 0)) (if FName (if (setq FH (open FName "r")) (while (setq LINE (read-line FH)) (if LINE (if (setq Comma (vl-string-position (ascii ",") LINE )) (if (setq LblStr (substr LINE 1 Comma)) (if (setq RemStr (substr LINE (+ Comma 2)) Comma (vl-string-position (ascii ",") RemStr) ) (if (setq Xord (substr RemStr 1 Comma) RemStr (substr RemStr (+ Comma 2)) Comma (vl-string-position (ascii ",") RemStr) Yord (substr RemStr 1 Comma) ) (progn (setq DatITM (list LblStr (atof Xord) (atof Yord)) DatLST (append DatLST (list DatITM)) ) ) (princ (strcat "\n Bad line '" LINE "'")) ) ) ) ) (close FH) ) ) (princ "\n Unable to Open File!") ) (princ "\n No File Picked!") ) (if DatLST (setq DatLST DatLST) (eval nil) ) ) ;;;____________________________________________________________________________ ;;; ;;; Program to Insert Points and Text at each location in list ;;; ;;; (defun C:PlacePTS ( / PosLST ITM Lbls Xord Yord TxtPT) (setq PosLST (ReadUTM)) (if PosLST (progn (setvar "CMDECHO" 0) (command "UNDO" "Begin") (foreach ITM PosLST (setq Lbls (car ITM) Xord (cadr ITM) Yord (caddr ITM) ) (princ (strcat "\n Placing " Lbls)) (command "Point" (list Xord Yord 0.0)) (command) (if (< (atoi Lbls) 0) (setq TxtPT (polar (list Xord Yord 0.0) 0.0 0.0)) (setq TxtPT (polar (list Xord Yord 0.0) 0.0 0.0)) ) (command "Text" TxtPT "150" "0" Lbls) (command) ) (command "UNDO" "End") (setvar "CMDECHO" 1) (princ (strcat "\n Placed " (itoa (length PosLST)) " items.")) ) (princ "\n Nothing to place.") ) (princ) ) There's probably a far more elegant way involving the database & pulling door numbers out of it and so on, but... Quote
MSasu Posted July 3, 2012 Posted July 3, 2012 Maybe try like this: (command "_Text" [color=red]"_non"[/color] TxtPT "150" "0" Lbls) Quote
ClareSelley Posted July 3, 2012 Author Posted July 3, 2012 Oh, I also don't need the point placing. Just the text. Quote
ClareSelley Posted July 3, 2012 Author Posted July 3, 2012 Hmmm. Helped a bit. But, for example, line: "Kitchen Flat 28",11368.36,45276.54 The text "Kitchen Flat 28" is being placed at 9129.45, 58356.76 Some are being placed right & some totally wrong... :/ And I need to get rid of the '""" - there may be '.' in the door number, but never ',' Quote
MSasu Posted July 3, 2012 Posted July 3, 2012 Oh, I also don't need the point placing. Then comment out the line that draw the point: [color=red];[/color](command "Point" (list Xord Yord 0.0)) Quote
ClareSelley Posted July 3, 2012 Author Posted July 3, 2012 Or maybe the 1st script isn't giving the right results... Hmmmm... Quote
MSasu Posted July 3, 2012 Posted July 3, 2012 The file is being read correctly, if that's what you mean. At least with the example from the first post. To validate by yourself just add this to your code: (setq PosLST [color=red](print [/color](ReadUTM)[color=red])[/color]) Quote
MSasu Posted July 3, 2012 Posted July 3, 2012 By the way, are sure that the UCS is the right one? Quote
ClareSelley Posted July 3, 2012 Author Posted July 3, 2012 Thanks all - I've now got it working perfectly and saved myself hours of checking! VERY much appreciated - brilliant forum. Clare. Quote
MSasu Posted July 3, 2012 Posted July 3, 2012 So, you got it fixed. Now, you may post the working code here for other members that may be interested. Quote
ClareSelley Posted July 3, 2012 Author Posted July 3, 2012 Working code: ;;; Program to read the output data from the Corpson6 coordinate conversion ;;; By Ron Auble, 01/19/07, Auble Consulting. Last update 01/19/07 ;;; ;;; Passed: Nothing, prompted to select a data file ;;; Return: List of lines from data file in the form of '("Label" X-value Y-value) ;;; (defun ReadUTM ( / FName LINE xFN Comma LblStr RemStr Xord Yord DatITM DatLST) (setq FName (getfiled "Select Data File" (getvar "DWGPREFIX") "txt" 0)) (if FName (if (setq FH (open FName "r")) (while (setq LINE (read-line FH)) (if LINE (if (setq Comma (vl-string-position (ascii ",") LINE )) (if (setq LblStr (substr LINE 1 Comma)) (if (setq RemStr (substr LINE (+ Comma 2)) Comma (vl-string-position (ascii ",") RemStr) ) (if (setq Xord (substr RemStr 1 Comma) RemStr (substr RemStr (+ Comma 2)) Comma (vl-string-position (ascii ",") RemStr) Yord (substr RemStr 1 Comma) ) (progn (setq DatITM (list LblStr (atof Xord) (atof Yord)) DatLST (append DatLST (list DatITM)) ) ) (princ (strcat "\n Bad line '" LINE "'")) ) ) ) ) (close FH) ) ) (princ "\n Unable to Open File!") ) (princ "\n No File Picked!") ) (if DatLST (setq DatLST DatLST) (eval nil) ) ) ;;;____________________________________________________________________________ ;;; ;;; Program to Insert Points and Text at each location in list ;;; ;;; (defun C:PlacePTS ( / PosLST ITM Lbls Xord Yord TxtPT) (setq PosLST (ReadUTM)) (if PosLST (progn (setvar "CMDECHO" 0) (command "UNDO" "Begin") (foreach ITM PosLST (setq Lbls (car ITM) Xord (cadr ITM) Yord (caddr ITM) ) (princ (strcat "\n Placing " Lbls)) (command) (if (> (atoi Lbls) 5) (setq TxtPT (polar (list Xord Yord 0.0) 0.0 -700.0)) (setq TxtPT (polar (list Xord Yord 0.0) 0.0 0.0)) ) (command "_Text" "_non" TxtPT "150" "0" Lbls) (command) ) (command "UNDO" "End") (setvar "CMDECHO" 1) (princ (strcat "\n Placed " (itoa (length PosLST)) " items.")) ) (princ "\n Nothing to place.") ) (princ) ) Quote
Lee Mac Posted July 3, 2012 Posted July 3, 2012 A quick modification of my code from here, should perform as required: (defun c:txtatpt ( / f p s x y ) (if (and (setq f (getfiled "" "" "csv" 16)) (setq f (open f "r")) ) (progn (while (setq n (read-line f)) (if (and (setq p (vl-string-search "," n)) (setq s (substr n 1 p)) (setq p (vl-string-search "," (setq n (substr n (+ p 2))))) (setq x (distof (substr n 1 p))) (setq y (distof (substr n (+ p 2)))) ) (entmake (list '(0 . "TEXT") (list 10 x y 0.0) (cons 1 s) (cons 40 (getvar 'textsize)) ) ) ) ) (close f) ) ) (princ) ) 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.