alex.rees Posted April 7, 2008 Posted April 7, 2008 Hi everyone, Bear with me as I'm a relative novice to Autolisp, i have been sifting through the internet for over a week now to try and find a Lisp routine that will enable me to pick points on a drawing and automatically label them with their eastings and northings on screen. I have finally achieved this mainly by dissecting other Lisp routines found on the internet and reading a couple of (probably way out of date) books from the local library. I'm not sure of the correct ettiquette when modifying other peoples routines so tell me if I have done something wrong. Anyway, below is the Lsip routine so far, but I cannot for the life of me figure out how to export each set of coordinates to an ASCII file for upload to a Total Station. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; IDXYZ.LSP ; ; This routine is based on: ; ; TIP #940: IDXYZ.LSP (C)1994, JOHN R. RICKER ; ; Taken from a post on the AUGI website ; ; ; ; Example Run : ; ; Enter Desired Text Size ? : ; ; UNIT type to use [s]cientific [D]ec [A]rchitect [E]ng [F]ract : ; ; Enter number of Decimal Places to use ? < 3 > : ; ; Please pick POINT to ID and label with TEXT... <do so> ; ; ************* continues until carriage return is hit *************** ; ; Please pick POINT to ID and label with TEXT... <do so> ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (princ "\Loading IDXY Please Wait..") (setvar "CMDECHO" 0) (setq OS (getvar "OSMODE")) (setq currlay (getvar "clayer")) (setq txtstyl (getvar "textstyle")) (command "style" "UTM" "romans" "0" "1" "0" "N" "N" "N") (command "Layer" "M" "UTM-Text" "S" "UTM-Text" "") ;set trailing zeros to on ; (initget 1 "S H") (setq DMZ (getkword "\nTrailing Zeros [s]how or [H]ide : ")) (cond ((= DMZ "S")(setq DMZ 3)) ((= DMZ "H")(setq DMZ ) ) ; end cond (setvar "DIMZIN" DMZ) ; ; get the text size to use ; (setq TXTSZ (getreal "\n Enter Desired Text Size ? : ")) ; ; get the unit type to display ; (initget 1 "S D E A F") (setq UT (getkword "\n UNIT type to use [s]cientific [D]ec [A]rchitect [E]ng [F]ract : ")) (cond ((= UT "S")(setq UT 1)) ((= UT "D")(setq UT 2)) ((= UT "E")(setq UT 3)) ((= UT "A")(setq UT 4)) ((= UT "F")(setq UT 5)) ) ; end cond ; ; get the number of decimal places to use ; (setq DP (getint "\n Enter number of Decimal Places to use ? < 3 > : ")) (if (or (= DP "")(= DP nil))(setq DP 3)) ; ; get insertion point first time in... ; (setq PT (getpoint "\n Please pick POINT to ID and label with TEXT... (hit Enter when done) ")) (while PT (setq VAL1$ (strcat (rtos (car PT) UT DP) "mE")) (setq VAL2$ (strcat (rtos (cadr PT) UT DP) "mN")) (command "TEXT" (polar PT 0 TXTSZ) TXTSZ "0" VAL1$ "text" "" VAL2$) ; (command "TEXT" PT "" VAL1$ "text" "" VAL2$)) ; ; ; get insertion point while in loop (setq PT (getpoint "\n Please pick POINT to ID and label with TEXT... (hit Enter when done) ")) ) ; end while ; ; reset OSMODE ; (setvar "OSMODE" OS) (setvar "clayer" currlay) (setvar "textstyle" txtstyl) (terpri) ) ; end defun (princ "IDXY Loaded.... Command = IDXY \n") (princ) ; end idxy.lsp Any help would be greatly appreciated. Cheers Quote
CALCAD Posted April 8, 2008 Posted April 8, 2008 I see that no one more capable has responded, so here I go. To save strings in an ascii file you first need to declare a file variable with something like : (setq fvar (open "gpoints.txt" "w")) This could go right after the line : ; get insertion point first time in... Then to write the strings, you need something like : (write-line VAL1$ fvar) (write-line VAL2$ fvar) That pair needs to appear inside the while loop after the strings are defined but before the getpoint statement. So how about just before the line : ; get insertion point while in loop Then after the while loop closes you need to close the file with : (close fvar) A good place for this might be after the line : ; reset OSMODE I hope this works. The code you posted seems incomplete, at least I can't find the opening DEFUN, so I couldn't run and test it myself. Also I don't know where the gpoints.txt file in my example will actually be located on your system. You may want to define a folder for it. About the copyright issue, I am no lawyer but I would guess that the author wouldn't care how you used the code unless you were going to sell a program that contained his code. Then you should contact him and request permission. Best of luck. Quote
BIGAL Posted April 8, 2008 Posted April 8, 2008 (edited) have a look at this looks for 5 points Note!!! cut out of another program not complete (repeat 5 (setq el (entget)) (setq ip (cdr (assoc 10 el))) (setq en1 (entnext en)) (setq el1 (entget en1)) (setq att (cdr (assoc 1 el1))) (setq px (rtos (car ip) 2 3)) (setq py (rtos (cadr ip) 2 3)) (setq pz (rtos (caddr ip) 2 3)) (setq pnt (strcat att "," px ", " py ", " pz)) (write-line pnt filename) ) Edited January 21, 2013 by SLW210 code tags Quote
alex.rees Posted April 8, 2008 Author Posted April 8, 2008 I hope this works. The code you posted seems incomplete, at least I can't find the opening DEFUN, so I couldn't run and test it myself. Also I don't know where the gpoints.txt file in my example will actually be located on your system. You may want to define a folder for it. Cheers CALCAD, that seems to have worked I have added the defun back in and tidied things up a bit. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; IDXYZ.LSP ; ; This routine is based on: ; ; TIP #940: IDXYZ.LSP (C)1994, JOHN R. RICKER ; ; Taken from a post on the AUGI website ; ; ; ; Example Run : ; ; Trailing Zeros [s]how or [H]ide ? ; ; Enter Desired Text Size ? : ; ; UNIT type to use [s]cientific [D]ec [A]rchitect [E]ng [F]ract : ; ; Enter number of Decimal Places to use ? < 3 > : ; ; Please pick POINT to ID and label with TEXT... <do so> ; ; ************* continues until carriage return is hit *************** ; ; Please pick POINT to ID and label with TEXT... <do so> ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (princ "\Loading IDXY Please Wait..") (defun C:IDXY ( / TYP OS ANS XYZ$ DP DMZ UT currlay txtstyl) (setvar "CMDECHO" 0) (setq OS (getvar "OSMODE")) (setq currlay (getvar "clayer")) (setq txtstyl (getvar "textstyle")) (command "style" "UTM" "romans" "0" "1" "0" "N" "N" "N") (command "Layer" "M" "UTM-Text" "S" "UTM-Text" "") ; ; set trailing zeros to on or off ; (initget 1 "S H") (setq DMZ (getkword "\nTrailing Zeros [s]how or [H]ide ? : ")) (cond ((= DMZ "S")(setq DMZ 3)) ((= DMZ "H")(setq DMZ ) ) ; end cond (setvar "DIMZIN" DMZ) ; ; set the text size to use ; (setq TXTSZ (getreal "\n Enter Desired Text Size ? : ")) ; ; set the unit type to display ; (initget 1 "S D E A F") (setq UT (getkword "\n UNIT type to use [s]cientific [D]ec [A]rchitect [E]ng [F]ract : ")) (cond ((= UT "S")(setq UT 1)) ((= UT "D")(setq UT 2)) ((= UT "E")(setq UT 3)) ((= UT "A")(setq UT 4)) ((= UT "F")(setq UT 5)) ) ; end cond ; ; set the number of decimal places to use ; (setq DP (getint "\n Enter number of Decimal Places to use ? < 3 > : ")) (if (or (= DP "")(= DP nil))(setq DP 3)) ; ; ; get insertion point first time in... ; ; open file for writing using drawing location and drawing name ; (setq fname (strcase (strcat (getvar "dwgprefix") (getvar "dwgname") ".xyz"))) (setq fvar (open fname "a")) ; ; pick 1st point ; (setq PT (getpoint "\n Please pick POINT to ID and label with TEXT... (hit Enter when done) ")) (while PT ; ; variable for on screen display (inc mE & mN) ; (setq VAL1$ (strcat (rtos (car PT) UT DP)"mE")) (setq VAL2$ (strcat (rtos (cadr PT) UT DP)"mN")) ; ; variable for output to file ; (setq OUT1$ (strcat (rtos (car PT) UT DP))) (setq OUT2$ (strcat (rtos (cadr PT) UT DP))) ; (command "TEXT" (polar PT 0 TXTSZ) TXTSZ "0" VAL1$ "text" "" VAL2$) ; ; get insertion point while in loop ; (write-line (strcat" " OUT1$ " " OUT2$ " " "0") fvar) ; (setq PT (getpoint "\n Please pick POINT to ID and label with TEXT... (hit Enter when done) ")) ) ; end while ; ; reset OSMODE (close fvar) ; (setvar "OSMODE" OS) (setvar "clayer" currlay) (setvar "textstyle" txtstyl) (terpri) ) ; end defun (princ "IDXY Loaded.... Command = IDXY \n") (princ) ; end idxy.lsp The only thing left to do now is to ask the user to choose a point number and have it increment by one each time a point is picked, any ideas? I have experimented with (setq pno (+ pno 1)) but I'm not sure where it should feature and (to be honest) exactly how to apply it. Cheers Quote
ASMI Posted April 8, 2008 Posted April 8, 2008 Do you really need extra options as 'Trailing Zeros how or [H]ide' and 'UNIT type to use cientific [D]ec [A]rchitect [E]ng [F]ract :'? I have alterate my old routine, now it draws number of points and writes it in file. (defun c:oxy(/ fPt oldEcho oldNum dFlc dDec fVar cX cY cNum *error*) (defun *error*(msg) (setvar "CMDECHO" 1) (if fVar(close fVar)) (princ) ); end of *error* (princ(strcat "DIMSCALE="(rtos(getvar "DIMSCALE"))" " "DIMLFAC="(rtos(setq dFlc(getvar "DIMLFAC")))" " "DIMDEC="(rtos(setq dDec(getvar "DIMDEC")))" " ); end strcat ); end princ (setvar "CMDECHO" 0) (if(= 0(getvar "USERI3"))(setvar "USERI3" 1) ); end if (setq cNum(getint(strcat "\nSpecify first point number <" (itoa(getvar "USERI3")) ">: "))) (if cNum (setvar "USERI3" cNum)) (setq fVar(open(strcase(strcat(getvar "DWGPREFIX") (getvar "DWGNAME") ".xyz")) "a")) (while (setq fPt (getpoint (strcat "\nSpecify point or Right-Click to Quit <"(itoa(getvar "USERI3"))">: "))) (if(vl-cmdf "_.dimordinate" fPt "_t" (strcat "["(itoa(getvar "USERI3"))"]" "\\P" (setq cX(rtos(* dFlc(car fPt))2 dDec)) "mE" "\\X" (setq cY(rtos(* dFlc(cadr fPt))2 dDec)) "mN" ); end strcat pause ); end vl-cmdf (progn (write-line (strcat " " cX " " cY " " "0")fVar) (setvar "USERI3"(1+(getvar "USERI3"))) ); end progn ); end if ); end while (close fVar) (setvar "CMDECHO" 1) (princ) ); end of c:oxy (princ "\nType OXY to tag coordinates ") It use standard DIMORDINATE dimension and controls by standard dimension variables DIMSCALE for dimension scale, DIMLFAC for measurement scale and DIMDEC for number of decimal places. Quote
eldon Posted April 8, 2008 Posted April 8, 2008 A very nice routine ASMI, but to be strict about it, could I point out a slight typo in the following line (write-line (strcat " " cX " " cY " " "0")fVar) Could the counting number variable be assigned to USERR1, so that in later opening of the drawing, the numbers would know what the last one used was, and the next number would carry on from there, instead of starting at 1 again Quote
ASMI Posted April 8, 2008 Posted April 8, 2008 Thank you for catching the bug. Now current number in "USERI3" system variable. Thats is symply but non professional I should to use Dictionaries not "USERXX" variables. But I havn't today more time to make it. Quote
eldon Posted April 8, 2008 Posted April 8, 2008 I know it is heresy to edit the work of masters, but if you change this line (write-line (strcat " " cX " " cY " " "0")fVar) For this one (write-line (strcat (itoa(getvar "USERI3")) "," cX "," cY "," "0")fVar) then the output is csv format with point number, easting, northing, elevation (set to zero) which is very suitable for uploading to a total station All the hard work was done by ASMI - thank you Quote
ASMI Posted April 8, 2008 Posted April 8, 2008 Thank you Eldon. For *.csv i think: (setq fVar(open(strcase(strcat(getvar "DWGPREFIX") (getvar "DWGNAME") "[color="#ff0000"].csv[/color]")) "a")) Glad to help you. Quote
alex.rees Posted April 9, 2008 Author Posted April 9, 2008 Thanks Guys, I have tweaked ASMI's rouitine slightly to suit my purposes and now have a routine to do everything i need. Ihave included my finished code if anyone is interested: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; OXY.LSP ; This routine is designed to display coordinate data on screen with a ; leader within a new layer and output data to a file for upload to a ; Total Station for setout. ; ; Example Run : ; Trailing Zeros [s]how or [H]ide ? ; Specify first point number: <do so> ; Specify point or Right-Click to Quit <do so> ; ****** continues until mouse left click ****** ; Specify point or Right-Click to Quit <do so> ;Lsp routine based on one supplied by ASMI on Cadtutor ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; (defun c:oxy(/ fPt oldEcho oldNum dFlc dDec DMZ fVar cX cY cNum *error*) ; (defun *error*(msg) (setvar "CMDECHO" 1) (if fVar(close fVar)) (princ) ); end of *error* ; ; Routine sets output variables ; (princ(strcat "DIMSCALE="(rtos(getvar "DIMSCALE"))" " "DIMLFAC="(rtos(setq dFlc(getvar "DIMLFAC")))" " "DIMDEC="(rtos(setq dDec 3))" " ); end strcat ); end princ ; ; Routine creates new layer, sets textstyle and inserts data into it ; (setq OS (getvar "OSMODE")) (setq currlay (getvar "clayer")) (setq txtstyl (getvar "textstyle")) (command "style" "UTM" "romans" "0" "1" "0" "N" "N" "N") (command "Layer" "M" "Coords" "S" "Coords" "") ; ; set trailing zeros to on or off ; (initget 1 "S H") (setq DMZ (getkword "\nTrailing Zeros [s]how or [H]ide ? : ")) (cond ((= DMZ "S")(setq DMZ 3)) ((= DMZ "H")(setq DMZ ) ) ; end cond (setvar "DIMZIN" DMZ) ; ; ; (setvar "CMDECHO" 0) (if(= 0(getvar "USERI3"))(setvar "USERI3" 1) ); end if ; ; Specify point number to start ; (setq cNum(getint(strcat "\nSpecify first point number <" (itoa(getvar "USERI3")) ">: "))) (if cNum (setvar "USERI3" cNum)) ; ; Create new file and open for writing ; (setq fVar(open(strcase(strcat(getvar "DWGPREFIX") (getvar "DWGNAME") ".xyz")) "a")) (while (setq fPt ; ; Click point/s on screen ; (getpoint (strcat "\nSpecify point or Right-Click to Quit <"(itoa(getvar "USERI3"))">: "))) (if(vl-cmdf "_.dimordinate" fPt "_t" (strcat "["(itoa(getvar "USERI3"))"]" "\\P" (setq cX(rtos(* dFlc(car fPt))2 dDec)) "mE" "\\X" (setq cY(rtos(* dFlc(cadr fPt))2 dDec)) "mN" ); end strcat pause ); end vl-cmdf (progn ; ; Write to file ; (write-line (strcat (itoa(getvar "USERI3")) "," cX "," cY "," "0")fVar) (setvar "USERI3"(1+(getvar "USERI3"))) ); end progn ); end if ); end while (close fVar) ; ; Reset to original settings ; (setvar "OSMODE" OS) (setvar "clayer" currlay) (setvar "textstyle" txtstyl) (setvar "CMDECHO" 1) (princ) ); end of c:oxy (princ "\nType OXY to tag coordinates ") Once again cheers Quote
surveyman Posted September 2, 2008 Posted September 2, 2008 Hi there, I am a total newcomer to forums so hope I have posted this OK. The code that has been written here is amazing, and does nearly what I want, except that it doesn't export the Z (height, 3D value). Is this possible? There was a 3rd column of data in the text file, but it was "0" even though the data I tried it on was in 3D. See below 1,298768.523,696689.666,0 2,298788.225,696710.462,0 I notice that the exported file, which is really what I am after, is created with the name "filename.dxf.xyz" or "filename.dwg.xyz" It is only a small thing but could this be edited to just be "filename.xyz" Many thanks to all for your work so far. Surveyman Quote
ASMI Posted September 2, 2008 Posted September 2, 2008 + Z coordinate (in file only) and name without .dwg. (defun c:oxy3(/ fPt oldEcho oldNum dFlc dDec fVar cX cY cZ cNum *error*) (defun *error*(msg) (setvar "CMDECHO" 1) (if fVar(close fVar)) (princ) ); end of *error* (princ(strcat "DIMSCALE="(rtos(getvar "DIMSCALE"))" " "DIMLFAC="(rtos(setq dFlc(getvar "DIMLFAC")))" " "DIMDEC="(rtos(setq dDec(getvar "DIMDEC")))" " ); end strcat ); end princ (setvar "CMDECHO" 0) (if(= 0(getvar "USERI3"))(setvar "USERI3" 1) ); end if (setq cNum(getint(strcat "\nSpecify first point number <" (itoa(getvar "USERI3")) ">: "))) (if cNum (setvar "USERI3" cNum)) (setq fVar(open(strcase(strcat(getvar "DWGPREFIX") (vl-filename-base (getvar "DWGNAME")) ".xyz")) "a")) (while (setq fPt (getpoint (strcat "\nSpecify point or Right-Click to Quit <"(itoa(getvar "USERI3"))">: "))) (if(vl-cmdf "_.dimordinate" fPt "_t" (strcat "["(itoa(getvar "USERI3"))"]" "\\P" (setq cX(rtos(* dFlc(car fPt))2 dDec)) "mE" "\\X" (setq cY(rtos(* dFlc(cadr fPt))2 dDec)) "mN" ); end strcat pause ); end vl-cmdf (progn (setq cZ(rtos(* dFlc(last fPt))2 dDec)) (write-line (strcat(itoa(getvar "USERI3")) "," cX "," cY "," cZ)fVar) (setvar "USERI3"(1+(getvar "USERI3"))) ); end progn ); end if ); end while (close fVar) (setvar "CMDECHO" 1) (princ) ); end of c:oxy (princ "\nType OXY3 to tag 3D coordinates ") Quote
surveyman Posted September 2, 2008 Posted September 2, 2008 ASMI Fantastic and many thanks! However having now got the xyz listing I need I have lost the point number. Could this be added? The file name has worked fine. Thanks again Surveyman Quote
ASMI Posted September 2, 2008 Posted September 2, 2008 Ok. I just add point number to the file. Quote
surveyman Posted September 2, 2008 Posted September 2, 2008 ASMI Sorry for the delay but I hadn't realised that you had edited the script in the previous message. This is perfect apart from the file being exported to 2 decimal places. I had a look to see if I could make this simple? edit but as I am new to lisp couldn't see what to do. Is there any chance you could make this final change for me? I'm very grateful. Many thanks Surveyman Quote
eldon Posted September 2, 2008 Posted September 2, 2008 The Lisp does not have to be changed, because it takes the number of decimal places from your dimension set-up (DIMDEC). If you format the dimension style to give three decimal places, so this Lisp will export with three decimal places. Quote
ASMI Posted September 2, 2008 Posted September 2, 2008 This is perfect apart from the file being exported to 2 decimal places. I had a look to see if I could make this simple? You can change DIMDEC system variable to change numbers of decimal places. Or find lines: (setq cX(rtos(* dFlc(car fPt))2 [color="Blue"]dDec[/color])) (setq cY(rtos(* dFlc(cadr fPt))2 [color="Blue"]dDec[/color])) (setq cZ(rtos(* dFlc(last fPt))2 [color="Blue"]dDec[/color])) and change dDec variable to number of decimal places you need, for example 0 for none. Quote
surveyman Posted September 2, 2008 Posted September 2, 2008 ASMI Thanks. Using DIMDEC works Ok but is less convenient than editing the lisp. When I tried making the edits you suggested to the 3 lines i get data like this 1,24905'-6.07",58066'-3.06",7'-5.5" 2,24907'-0.31",58068'-0.01",7'-6.67" 3,24908'-8.41",58069'-8.46",7'-7.21" 4,24910'-4.02",58071'-5.33",7'-8.24" Any ideas as to what is wrong? Thank you. Quote
ASMI Posted September 3, 2008 Posted September 3, 2008 I think you changed mode argument of RTOS function to 3. This is RTOS (real to string) function help: RTOSConverts a number into a string (rtos number [mode [precision]]) The rtos function returns a string that is the representation of number according to the settings of mode, precision, and the system variables UNITMODE, DIMZIN, LUNITS, and LUPREC. Arguments number A number. mode An integer specifying the linear units mode. The mode corresponds to the values allowed for the LUNITS AutoCAD system variable. The mode can be one of the following numbers: 1-Scientific 2-Decimal 3-Engineering (feet and decimal inches) 4-Architectural (feet and fractional inches) 5-Fractional precision An integer specifying the precision. The mode and precision arguments correspond to the system variables LUNITS and LUPREC. If you omit the arguments, rtos uses the current settings of LUNITS and LUPREC. Return Values A string. The UNITMODE system variable affects the returned string when engineering, architectural, or fractional units are selected (mode values 3, 4, or 5). Examples Set variable x: Command: (setq x 17.5) 17.5 Convert the value of x to a string in scientific format, with a precision of 4: Command: (setq fmtval (rtos x 1 4)) "1.7500E+01" Convert the value of x to a string in decimal format, with 2 decimal places: Command: (setq fmtval (rtos x 2 2)) "17.50" Convert the value of x to a string in engineering format, with a precision of 2: Command: (setq fmtval (rtos x 3 2)) "1'-5.50\"" Convert the value of x to a string in architectural format: Command: (setq fmtval (rtos x 4 2)) "1'-5 1/2\"" Convert the value of x to a string in fractional format: Command: (setq fmtval (rtos x 5 2)) "17 1/2" Setting UNITMODE to 1 causes units to be displayed as entered. This affects the values returned by rtos for engineering, architectural, and fractional formats, as shown in the following examples: Command: (setvar "unitmode" 1) 1 Command: (setq fmtval (rtos x 3 2)) "1'5.50\"" Command: (setq fmtval (rtos x 4 2)) "1'5-1/2\"" Command: (setq fmtval (rtos x 5 2)) "17-1/2" Quote
agilia Posted June 22, 2010 Posted June 22, 2010 does anyone know how to change the lisp routine to change the coordinates from millimetes to meters 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.