XY and Z to File

Discussion in 'AutoCAD' started by Walid Khalid, Nov 29, 2004.

  1. Walid Khalid

    Walid Khalid Guest

    Hi,

    There is a good freeware in www.gisplus.co.nz

    Regards

    I'm wondering if you can help me with these LISP's that I have.
    They both work, but I'd like them to work with a few less keystrokes. One
    makes you enter a "z" coordinate in case the "z" coordinate of the object
    is "0". I'm not fluent in LISP so I don't know the reasoning behind that.
    They were written by someone else and were not intended to be used as
    shareware, so I hope you don't have a problem helping me alter the
    LISP's. I am not going to use these LISP's for any reason other than
    personal use to write coords to files to put into a surfacing program.
    It's alot faster than writing the files from scratch.
    If you happen to be the author of either of these LISP's, please
    respond any way you see fit.
    *************************************************************************

    This one I'd like to get it to automatically assign a file name and NOT
    have to enter a "z" coordinate "in case" the objects are at "0"
    elevation. Also, it put an "X" on the object I pick with a number I have
    to begin with. it seems to be too much for a 'simple' LISP.

    **** points.lsp ****

    ; INSTRUCTIONS/USE:
    ; -----------------
    ;
    ; Unmodified copies of this program and the accompanying documentation
    may be
    ; made and distributed freely without charge. Under no circumstances
    shall
    ; this program or the accompanying documentation be distributed as part
    of any
    ; for-profit venture, without expressed written permission from the
    author.
    ;
    ; POINTS is a simple program which allows you generate a coordinate
    points
    ; file by picking points within an AutoCAD drawing file. To run POINTS,
    ; load POINTS.LSP (see AutoCAD Reference Manual), type "POINTS" and press
    ; [Enter]. POINTS will first prompt you for an output coordinate
    filename.
    ; You must enter a valid DOS filename at this point. The coordinate file
    ; produced will be in the following format:
    ;
    ; POINT NO. NORTHING(y) EASTING(x) ELEVATION(z)
    ;
    ; POINTS will then prompt you for a starting point number, and a default
    ; elevation. POINTS reads the "x" & "y" coordinates from the picked
    point,
    ; and will also read the "z" coordinate if it is not equal to "0". If
    the "z"
    ; coordinate of a particular point is equal to "0", POINTS will assign
    the
    ; default elevation entered by the user to that point. Note that the
    picked
    ; point will only have a "z" coordinate if the point is a specific point
    on an
    ; existing drawing entity (ie: ENDPT, INT, etc.). The default elevation
    may
    ; be changed by pressing [Enter] at the "Next Point:" prompt. You will
    then
    ; be prompted for a new default elevation. If [Enter] is pressed again
    without
    ; entering a new elevation, the POINTS program will terminate.
    ;
    ; POINTS uses the default (current) text style and layer.
    ;
    ; If you have any questions or comments concerning POINTS, I may be
    reached
    ; via THE SPECTRUM BBS þ (501) 521-5639
    ;
    ;------------------------------------------------------------------------
    ------
    ; * ERROR trapping *
    ;
    (defun *ERROR* ()
    (eop)
    )
    ;------------------------------------------------------------------------
    ------
    ; * End of program *
    ;
    (defun EOP ()
    (setvar "CMDECHO" POINTS_CE)
    (setvar "PDMODE" POINTS_PDM)
    (setvar "PDSIZE" POINTS_PDS)
    (princ)
    )
    ;------------------------------------------------------------------------
    ------
    ; * Get points *
    ;
    (defun GETPOINTS()
    (while (/= (setq NP (getpoint "\nNext Point: ")) nil)
    (command "POINT" NP)
    (command "TEXT" NP 0.0 (strcat " " (itoa BPN)))
    (setq pt (cdr np))

    (if (= (car (cdr PT)) 0)
    (setq ZPT (getvar "ELEVATION"))
    (progn (setq Z (cdr PT))
    (setq ZPT (car Z))
    (command "ELEV" ZPT "")
    )
    ) ;end if

    (setq outline (strcat (itoa BPN) " " ;POINT NUMBER
    (rtos (car PT) 2 4) " " ;Y
    (rtos (car NP) 2 4) " " ;X
    (rtos ZPT 2 4) "\n") ;Z
    )

    (princ OUTLINE OF)
    (princ OUTLINE)
    (setq BPN (1+ BPN))
    ) ;end while
    )
    ;------------------------------------------------------------------------
    ------
    ; * Main program *
    ;
    (defun C:pOINTS ()
    (setq S (getvar "LTSCALE"))
    (setq POINTS_CE (getvar "CMDECHO"))
    (setq POINTS_PDM (getvar "PDMODE"))
    (setq POINTS_PDS (getvar "PDSIZE"))
    (setvar "CMDECHO" 0)
    (setvar "PDMODE" 3)
    (setvar "PDSIZE" (* s 0.05))

    (prompt "\n ")
    (prompt "\nP O I N T S v1.1 -- Copyright (c) 1992 by Kurtis J. Jones
    / -Mate Software")
    (prompt "\n ")

    (setq OF (open (getstring "\nFilename: ") "a"))
    (setq BPN (getint "\nStarting Point No.: "))
    (setq NELEV (getreal "\nEnter Elevation: "))

    (while (/= NELEV nil)
    (command "ELEV" NELEV "")
    (getpoints)
    (setq NELEV (getreal "\nEnter Elevation: "))
    )

    (close OF)
    (eop)
    )


    *************************************************************************

    This LISP seemed so simple to modify to include a "z" coordinate, but I
    couldn't get it to work by adding what I thought would make it "Z"
    friendly. It just does "x" and "y" coords.

    **** p2file.lsp****

    (defun c:p2file( / pickpt pointlist ctr xpt ypt outfilename outfile)

    (setq ctr 0
    pickpt T
    pointlist nil) ;;defaults

    (while pickpt
    (setq pickpt (getpoint "\nSelect point, [Enter] when complete "))
    (if pickpt (setq PointList (append PointList (list PickPt))))
    ) ;while

    ;;get the filename from the user
    (setq OutFilename (getfiled "Select Output File" "" "txt" 1))

    ;;open the file for writing
    (setq OutFile (open OutFilename "w"))

    ;;process the point list
    (if (and PointList OutFile)
    (progn
    (repeat (length PointList)
    (setq xpt (car (nth ctr PointList))
    ypt (cadr (nth ctr Pointlist)))
    (write-line (strcat (rtos xpt) "," (rtos ypt)) OutFile)
    (setq ctr (1+ ctr))
    ) ;repeat
    (close OutFile)
    (alert "File Complete!")
    ) ;progn
    ;else
    (alert "No Points, or Bad Data File!")
    ) ;if

    (princ)
    ) ;end defun
    *************************************************************************

    This one won't even start up.

    **** pointplt.lsp ****

    ; INSTRUCTIONS/USE:
    ; -----------------
    ;
    ; Unmodified copies of this program and the accompanying documentation
    may be
    ; made and distributed freely without charge. Under no circumstances
    shall
    ; this program or the accompanying documentation be distributed as part
    of any
    ; for-profit venture, without expressed written permission from the
    author.
    ;
    ; POINTPLT is a simple AutoLSIP program that will plot a coordinate
    points file
    ; in AutoCAD. To run POINTPLT, load POINTPLT.LSP as you would any normal
    ; AutoLISP file (see AutoCAD Reference Manual), type "POINTPLT" and press
    ; [Enter]. POINTPLT will first prompt you for an input coordinate
    filename.
    ; You must enter a vaild DOS filename at this point. The input
    coordinate file
    ; must be in the following format:
    ;
    ; POINT NO. NORTHING(y) EASTING(x) ELEVATION(z)
    ;
    ; A sample input coordinate file (SAMPLE.DAT) is included with POINTPLT.
    ;
    ; POINTPLT uses the default (current) text style and layer. However, the
    ; current text style must have a defined height (height must not be "0").
    ;
    ; If you have any questions or comments concerning POINTS, I may be
    reached
    ; via THE SPECTRUM BBS þ (501) 521-5639
    ;
    ;------------------------------------------------------------------------
    -------
    ; * ERROR Trapping *
    ;
    (defun *ERROR* ()
    (eop)
    )
    ;------------------------------------------------------------------------
    -------
    ; * End of program *
    ;
    (defun EOP ()
    (setvar "CMDECHO" POINTSPLT_CE)
    (princ)
    )
    ;------------------------------------------------------------------------
    -------
    ; * Main Program *
    ;
    (defun C:pOINTPLT ()
    (setq POINTSPLT_CE (getvar "CMDECHO"))
    (setvar "CMDECHO" 0) ;Turn "Command Echo" off

    (prompt "\n ")
    (prompt "\nP O I N T P L T v1.0 -- Copyright (c) 1992 by Kurtis J.
    Jones / -Mate Software")
    (prompt "\n ")

    (setq IN_FILE (open (getstring "\nEnter points filename: ") "r"))
    (prompt "\n ")
    (setq POINT_LINE 0) ;Force at least one pass thru the "while" loop
    (while (/= POINT_LINE nil)
    (setq POINT_LINE (read-line IN_FILE)) ;Read POINT_LINE from input
    file
    (if (/= POINT_LINE nil)
    (progn
    (setq POINT_LINE (strcat "(" POINT_LINE ")")) ;Correct format
    (setq POINT_LINE (read POINT_LINE)) ;Convert to
    list
    (setq POINT_NO (nth 0 POINT_LINE)) ;Get the point
    number
    (prompt (strcat "\nPlotting point no. " (itoa POINT_NO)))
    (setq POINT
    (list
    (nth 2 POINT_LINE) ;Get easting
    (nth 1 POINT_LINE) ;Get northing
    (nth 3 POINT_LINE) ;Get elevation
    )
    )
    (command "POINT" POINT)
    (command "TEXT" POINT 0.0 (strcat " " (itoa POINT_NO)))
    )
    )
    )
    (close IN_FILE)
    (prompt "\nPOINTPLT finished")
    (prompt "\n ")
    (eop)
    )

    *************************************************************************

    This one wouldn't let me pick any object I had created, such as a block.
    What was funny about this one is that it picked the "x's" (points shaped
    like x's) left over from another LISP I had run previously. Wierd. I had
    to put points where I had my blocks.

    **** points2.lsp ****

    ;;;exports point data to file.
    (DEFUN C:p2 (/ ECHO
    F_N ;filename
    SS ;selection set
    N ;selection set length
    PNT ;point number
    INDEX ;loop counter
    F_O ;open file
    SS1 ;isolate selection set entity
    XYZ ;xyz coordinates
    X
    Y
    Z
    PNT1 ;string value of point integer
    LN ;line of text
    )
    (GRAPHSCR)
    (SETQ ECHO (GETVAR "CMDECHO"))
    (SETVAR "CMDECHO" 0)
    (SETQ F_N (GETFILED "Point Files" "" "asc" 5));choose filename
    (SETQ SS (SSGET
    (LIST (CONS 0 "POINT"))));select objects
    (SETQ N (SSLENGTH SS))
    (SETQ PNT (GETINT "\nEnter starting point Number:<1> "))
    (IF (NULL PNT) (SETQ PNT 1))
    (SETQ INDEX 0)
    (SETQ F_O (OPEN F_N "w"));open chosen file to overwrite
    (REPEAT N
    (SETQ SS1 (ENTGET (SSNAME SS INDEX)))
    (SETQ INDEX (+ INDEX 1))
    (SETQ XYZ (ASSOC 10 SS1));store coordinate list
    (SETQ X (NTH 1 XYZ));separate coordinate list
    (SETQ Y (NTH 2 XYZ))
    (SETQ Z (NTH 3 XYZ))
    (SETQ PNT1 (RTOS PNT 2 0));convert point number to string
    (SETQ X (RTOS X 2 2));convert coordinates to string
    (SETQ Y (RTOS Y 2 2))
    (SETQ Z (RTOS Z 2 2))
    (SETQ LN (STRCAT PNT1 "," Y "," X "," Z));store text string
    (WRITE-LINE LN F_O);write string to file
    (SETQ PNT (+ PNT 1));set next point number
    );ends repeat
    (CLOSE F_O);closes open file
    (SETVAR "CMDECHO" ECHO)
    (PRINC)
    );ends defun

    *************************************************************************

    If anyone can help with any of these LISP's, especially an author, I'd
    be most appreciative. What I need: Have a LISp write coordinates to a
    file that is named automatically (*.txt, *.asc, *.dat), it doesn't
    matter, by picking blocks using OSNAP setting "insert". It doesn't get
    any more simpler than that, unless I just don't get it. That very well
    could be a possibility. Thanks again.
     
    Walid Khalid, Nov 29, 2004
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.