; ASCPOINT.LSP Copyright 1990-97 Tony Tanzillo All Rights Reserved. ; ;; Author: Tony Tanzillo, ;; Design Automation Consulting ;; http://ourworld.compuserve.com/homepages/tonyt ;; tony.tanzillo@worldnet.att.net ;; ;; Permission to use, copy, modify, and distribute this software ;; for any purpose and without fee is hereby granted, provided ;; that the above copyright notice appears in all copies and ;; that both that copyright notice and the limited warranty and ;; restricted rights notice below appear in all copies and all ;; supporting documentation, and that there is no charge or fee ;; charged in return for distribution or duplication. ;; ;; This SOFTWARE and documentation are provided with RESTRICTED ;; RIGHTS. ;; ;; Use, duplication, or disclosure by the Government is subject ;; to restrictions as set forth in subparagraph (c)(1)(ii) of ;; the Rights in Technical Data and Computer Software clause at ;; DFARS 252.227-7013 or subparagraphs (c)(1) and (2) of the ;; Commercial Computer Software Restricted Rights at 48 CFR ;; 52.227-19, as applicable. The manufacturer of this SOFTWARE ;; is Tony Tanzillo, Design Automation Consulting. ;; ;; NO WARRANTY ;; ;; ANY USE OF THIS SOFTWARE IS AT YOUR OWN RISK. THE SOFTWARE ;; IS PROVIDED FOR USE "AS IS" AND WITHOUT WARRANTY OF ANY KIND. ;; TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE AUTHOR ;; DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT ;; NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND ;; FITNESS FOR A PARTICULAR PURPOSE, WITH REGARD TO THE SOFTWARE. ;; ;; NO LIABILITY FOR CONSEQUENTIAL DAMAGES. TO THE MAXIMUM ;; EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL ;; THE AUTHOR OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, ;; INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER ;; (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF ;; BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS ;; INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF ;; THE USE OF OR INABILITY TO USE THE SOFTWARE PRODUCT, EVEN ;; IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH ;; DAMAGES. BECAUSE SOME JURISDICTIONS DO NOT ALLOW EXCLUSION ;; OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL ;; DAMAGES, THE ABOVE LIMITATION MAY NOT APPLY TO YOU. ;; ; ; ASCPOINT.LSP is a utility for use with AutoCAD Release 10 or later, ; which reads coordinate data from ASCII files in CDF or SDF format, ; and generates AutoCAD geometry from the imported coordinates. ; ; The ASCPOINT command will read coordinate data from an ASCII file, ; and generate either a continuous string of LINES, a POLYLINE, a ; 3DPOLYline, multiple copies of a selected group of objects, or ; AutoCAD POINT entities. ; ; Format: ; ; Command: ASCPOINT ; File to read: MYFILE.TXT <- ASCII input file ; Comma/Space delimited : Comma <- data format ; Generate Copies/Lines/Nodes/3Dpoly/: Nodes <- entity to create ; Reading coordinate data... ; ; If you selected "Copies", then ASCPOINT will prompt you to select the ; objects that are to be copied. The basepoint for all copies is the ; current UCS origin (0,0,0). One copy of the selected objects will be ; created for each incoming coordinate, using each coordinate as the ; displacement relative to the origin. ; ; A comma-delimited (CDF) ascii file contains one coordinate per line, ; with each component seperated by a comma, like this: ; ; 2.333,4.23,8.0 ; -4.33,0.0,6.3 ; 0.322,5.32,0.0 ; etc.... ; ; There should be no spaces or blank lines in a CDF coordinate data file. ; ; A space-delimited (SDF) ascii file contains one coordinate per line, ; with each component seperated by one or more spaces, like this: ; ; 2.333 4.23 8.0 ; -4.33 0.0 6.3 ; 0.322 5.32 0.0 ; ... ; ; Coordinate data can be 2D or 3D. ; ; Note that all numeric values must have at least one digit to the left ; and the right of the decimal point (values less than one must have a ; leading 0), and a leading minus sign indicates negative values. This ; applys to both CDF and SDF formats. ; ; ASCPOINT can generate a continuous chain of LINE entities from your ; coordinate data, where each pair of adjacent lines share a coordinate ; from the file. ; ; ASCPOINT can also generate a polyline or 3DPOLYline from the coordinate ; data, where each point in the file becomes a vertice of the polyline. ; If the input file contains 3D coordinates, and you specify a polyline, ; then the Z component is ignored and the default of 0.0 is used. ; ; ASCPOINT will also COPY a selected group of objects, creating one copy ; for each incoming coordinate, and using the coordinate as the absolute ; copy displacement from the CURRENT UCS origin (0,0,0). ; ; Finally, ASCPOINT will generate AutoCAD POINT entities from the data in ; the file. Specify the point size and type prior to invoking ASCPOINT. ; ; Writing POINT coordinates to file: ; ; The WPOINT command also included in this file, will export the ; coordinates of selected POINT entities to a comma-delimited CSV ; file that can be read into Excel, and imported using ASCPOINT. ; ; Good luck, ; ; Tony Tanzillo (defun C:ASCPOINT ( / f bm hi format input line plist ss makepoint) (cond ( (not (setq f (getfiled "Import ASCII Coordinate Data" "" "" 0)))) ( (not (setq f (open f "r"))) (princ "\nCan't open file for input.")) (t (initget "Space Comma") (setq format (cond ((getkword "\nComma/Space delimited : ")) (t "Comma"))) (initget "Copies Lines Nodes 3Dpoly Pline") (setq input (cdr (assoc (cond ( (getkword "\nGenerate Copies/Lines/Nodes/3Dpoly/: ")) (t "Pline")) '(("Lines" . "._LINE") ("Copies" . "._COPY") ("Nodes" . "._POINT") ("3Dpoly" . "._3DPOLY") ("Pline" . "._PLINE")))) ) (setq read-point (if (eq format "Comma") cdf sdf) ) (setq makepoint (if (eq input "._PLINE") 2dpoint 3Dpoint) ) (setvar "cmdecho" 0) (command "._UNDO" "_Begin") (setq bm (getvar "blipmode")) (setq hi (getvar "highlight")) (setvar "blipmode" 0) (princ "\nReading coordinate data...") (while (setq line (read-line f)) (cond ( (and (setq line (strtrim line)) (/= line "") (setq line (makepoint (read-point line)))) (setq plist (cons line plist))))) (close f) (setq plist (reverse plist)) (cond ( (eq input "._POINT") (setvar "highlight" 0) (command "._POINT" "0,0,0" "._COPY" (setq ss (entlast)) "" "_m" "0,0,0") (apply 'command plist) (command) (entdel ss)) ( (eq input "._COPY") (princ "\nSelect objects to copy,") (while (not (setq ss (ssget))) (princ "\nNo objects selected,") (princ " select objects to copy,")) (setvar "HIGHLIGHT" 0) (command "._COPY" ss "" "_m" "0,0,0") (apply 'command plist) (command)) (t (command input) (apply 'command plist) (command))) (command "._UNDO" "_en") (setvar "highlight" hi) (setvar "blipmode" bm))) (princ) ) (defun cdf (l) (command "._LASTPOINT" l) (getvar "lastpoint") ) (defun sdf (l) (read (strcat "(" l ")")) ) (defun 3dpoint (p) (list (car p) (cadr p) (cond ((caddr p)) (t 0.0))) ) (defun 2dpoint (p) (list (car p) (cadr p)) ) (defun noz (p) (list (car p) (cadr p)) ) ;; ================================================================ ;; (Strtrim ) ;; ;; Trims leading and trailing spaces from (defun strtrim (s) (Strltrim (Strrtrim s)) ) ;; ================================================================ ;; (StrLtrim ) ;; ;; Trims leading spaces from (defun Strltrim (s / l) (if (wcmatch s " *") (progn (setq l (1+ (strlen s)) i 1) (while (and (eq (substr s i 1) " ") (/= l i)) (setq i (1+ i)) ) (substr s i) ) s ) ) ;; ================================================================ ;; (StrRtrim ) ;; ;; Trims trailing spaces from (defun Strrtrim (s / i) (if (wcmatch s "* ") (progn (setq i (strlen s)) (while (and (> i 0) (eq (substr s i 1) " ")) (setq i (1- i)) ) (substr s 1 i) ) s ) ) (defun C:WPOINT ( / ss fd file) (cond ( (not (setq ss (ssget '((0 . "POINT")))))) ( (not (setq file (getfiled "Export Points" "" "csv" 1)))) ( (not (setq fd (open file "w"))) (alert "Unable to open file for output")) (t (repeat (setq i (sslength ss)) (write-point (ssname ss (setq i (1- i))) fd 6 ) ) (close fd) ) ) (princ) ) (defun write-point (e fd prec / p) (setq p (cdr (assoc 10 (entget e)))) (write-line (strcat (rtos (car p) 2 prec) "," (rtos (cadr p) 2 prec) "," (rtos (caddr p) 2 prec) ) fd ) ) (princ "\nASCPOINT.LSP Copyright 1990-1997 Tony Tanzillo.") (princ "\nUse ASCPOINT to import coordinates.") (princ "\nUse WPOINT to export POINT coordinates.") (princ)