Help in editing a LISP

Help in editing a LISP

Anonymous
Not applicable
1,765 Views
12 Replies
Message 1 of 13

Help in editing a LISP

Anonymous
Not applicable

I found a Lisp here in the forum and I can not edit it, lisp works as follows, it exports the X, Y, Z coordinates of a Polyline and transforms it into a .txt file, except I do not want it to export the polyline , but rather a clickable place of instead of selecting the polyne to be the coordinate of the point that I clicked, Ex: I clicked at any point it generates the XYZ coordinates of the point that I clicked.

 

;..........................

 

(defun ERR (S)
(if (= S "Function cancelled")
(princ "\nVERTEXT - cancelled: ")
(progn (princ "\nVERTEXT - Error: ") (princ S) (terpri)) ;_ progn
) ;_ if
(RESETTING)
(princ "SYSTEM VARIABLES have been reset\n")
(princ)
) ;_ err
(defun SETV (SYSTVAR NEWVAL)
(setq X (read (strcat SYSTVAR "1")))
(set X (getvar SYSTVAR))
(setvar SYSTVAR NEWVAL)
) ;_ setv
(defun SETTING ()
(setq OERR *ERROR*)
(setq *ERROR* ERR)
(SETV "CMDECHO" 0)
(SETV "BLIPMODE" 0)
) ;_ end of setting
(defun RSETV (SYSTVAR)
(setq X (read (strcat SYSTVAR "1")))
(setvar SYSTVAR (eval X))
) ;_ restv
(defun RESETTING ()
(RSETV "CMDECHO")
(RSETV "BLIPMODE")
(setq *ERROR* OERR)
) ;_ end of resetting

(defun DXF (CODE ENAME) (cdr (assoc CODE (entget ENAME)))) ;_ dxf

(defun VERTEXT (/ EN VLIST)
(setq EN (GET-EN))
(if (= (DXF 0 EN) "LWPOLYLINE")
(setq VLIST (GET-LWVLIST EN))
(setq VLIST (GET-PLVLIST EN))
) ;_ if
(WRITE-IT VLIST EN)
) ;_ vertext

(defun GET-EN (/ NO-ENT EN MSG1 MSG2)
(setq NO-ENT 1
EN NIL
MSG1 "\nSelect a polyline: "
MSG2 "\nNo polyline selected, try again."
) ;_ setq
(while NO-ENT
(setq EN (car (entsel MSG1)))
(if (and EN
(or (= (DXF 0 EN) "LWPOLYLINE") (= (DXF 0 EN) "POLYLINE")) ;_ or
) ;_ and
(progn (setq NO-ENT NIL)) ; progn
(prompt MSG2)
) ;_ if
) ;_ while
EN
) ;_ get-en

(defun GET-LWVLIST (EN / ELIST NUM-VERT VLIST)
(setq ELIST (entget EN)
NUM-VERT (cdr (assoc 90 ELIST))
ELIST (member (assoc 10 ELIST) ELIST)
VLIST NIL
) ;_ setq
(repeat NUM-VERT
(setq VLIST (append VLIST (list (cdr (assoc 10 ELIST)))) ; append
) ;_ setq
(setq ELIST (cdr ELIST)
ELIST (member (assoc 10 ELIST) ELIST)
) ;_ setq
) ;_ repeat
VLIST
) ;_ get-lwvlist

(defun GET-PLVLIST (EN / VLIST)
(setq VLIST NIL
EN (entnext EN)
) ;_ setq
(while (/= "SEQEND" (DXF 0 EN))
(setq VLIST (append VLIST (list (DXF 10 EN))))
(setq EN (entnext EN))
) ;_ while
VLIST
) ;_ get-plvlist

(defun WRITE-IT (VLST EN / NEWVLIST MSG3 FNAME)
(setq NEWVLIST (mapcar '(lambda (X) (trans X EN 0)) ;_ lambda
VLST
) ;_ mapcar
MSG3 "Polyline vertex file"
FNAME (getfiled MSG3 "" "txt" 1)
F1 (open FNAME "w")
) ;_ setq
(WRITE-HEADER)
(WRITE-VERTICES NEWVLIST)
(setq F1 (close F1))
) ;_ write-it

(defun WRITE-HEADER (/ STR)
(setq STR " POLYLINE VERTEX POINTS")
(write-line STR F1)
(setq STR (strcat " X " " Y " " Z") ;_ strcat
) ;_ setq
(write-line STR F1)
) ;_ write-header

(defun WRITE-VERTICES (NEWVLIST / XSTR YSTR ZSTR STR)
(foreach ITEM NEWVLIST
(setq XSTR (rtos (nth 0 ITEM) 2 4)
YSTR (rtos (nth 1 ITEM) 2 4)
ZSTR (rtos (nth 2 ITEM) 2 4)
STR (strcat XSTR (SPACES XSTR) YSTR (SPACES YSTR) ZSTR) ;_ strcat
) ;_ setq
(write-line STR F1)
) ;_ foreach
) ;_ write-vertices

(defun SPACES (STR / FIELD NUM CHAR SPACE)
(setq FIELD 15
NUM (- FIELD (strlen STR))
CHAR " "
SPACE ""
) ;_ setq
(repeat NUM (setq SPACE (strcat SPACE CHAR))) ;_ repeat
) ;_ spaces

(defun C:VTX ()
(SETTING)
(VERTEXT)
(RESETTING)
(princ)
) ;_ c:vtx

(prompt "\nEnter VTX to start")

 

 

0 Likes
Accepted solutions (3)
1,766 Views
12 Replies
Replies (12)
Message 2 of 13

hanslammerts
Collaborator
Collaborator

What do you mean 'can't edit it'?

save it as a .lsp file.

use the vlisp command to start vlide

0 Likes
Message 3 of 13

Anonymous
Not applicable

@hanslammertsThe problem is not the way to load, it is to edit the code to do what is described in the question.

0 Likes
Message 4 of 13

hanslammerts
Collaborator
Collaborator

Didn't read carefully, sorry

there are a whole bunch of progs that can work with xyz

like this one. No need to invent wheels over 😉

 

https://translate.google.com/translate?sl=auto&tl=en&js=y&prev=_t&hl=nl&ie=UTF-8&u=http%3A%2F%2Fwww....

0 Likes
Message 5 of 13

Anonymous
Not applicable

@hanslammerts 

Excuses, but I do not think you understood the point. This software made available for download, does exactly what LISP described in the question, takes as coordinates of an existing object and exports the XYZ coordinates, BUT I do not want as coordinates of an object, but the coordinates of a click, EXAMPLE: A every Click that I give in autocad, be exported to the exact coordinate of that click.

 

 

0 Likes
Message 6 of 13

Anonymous
Not applicable

I'm from Brazil, and google does not translate correctly.

0 Likes
Message 7 of 13

john.uhden
Mentor
Mentor

I understand your english.

I presume you are going to pick a number of points in the same command function, si?

I presume you want each line to be comma-delimited, like a CSV file, ai?

To what precision do you want the values (places after the decimal)?

If you use the command later, do you want to maybe append to the previous file, or do you want a new file each time?

Do you want the file to be a CSV, or TXT, or you decide each time?

John F. Uhden

0 Likes
Message 8 of 13

john.uhden
Mentor
Mentor
Accepted solution

Also...

Do you want to number the points as you pick them, like starting at 1 (or any number)?

Do you want to add a description?

 

For example:

#,X,Y,Z,Description

 

This is a typical format for survey points like you might send to a surveyor (usually via e-mail) for staking out points in the field.

John F. Uhden

0 Likes
Message 9 of 13

Anonymous
Not applicable

@john.uhden

 

###I presume you are going to pick a number of points in the same command function, si?

R: Exactly.

### I presume you want each line to be comma-delimited, like a CSV file, ai?

R: Can be 

### To what precision do you want the values (places after the decimal)?

R: 4 places after the decimal

###If you use the command later, do you want to maybe append to the previous file, or do you want a new file each time?

R: I want to attach to the previous file

###Do you want the file to be a CSV, or TXT, or you decide each time?

R:  decide each time

 

###Also...

Do you want to number the points as you pick them, like starting at 1 (or any number)?

Do you want to add a description? 

R:Yes, it's essential.

 

For example:

#,X,Y,Z

;.......................................................................

follows jpg dp example of how I would like it.

 

 

0 Likes
Message 10 of 13

john.uhden
Mentor
Mentor

Pardon me, but I haven't provided any solution as yet.

John F. Uhden

0 Likes
Message 11 of 13

joselggalan
Advocate
Advocate
Accepted solution

try this:

 

Image_13.gif

 

;;============================= c:Test0007 ====================================;;
;; Jose L. García G. -  29/10/17                                               ;;
;;=============================================================================;;
(defun c:Test0008 (/ p1 oFile sFile tmp Separator i
		     ;|Functions|; GetFormatFile aux:SelectFile grdx
                  )

	;;_________________________________________________
	(defun GetFormatFile (/ lsts)
	 (or *Format* (setq *Format* "csv"))
	 (setq lsts '(("csv" ";" "[<Csv>/Txt/Xls]")
		      ("txt" " " "[Csv/<Txt>/Xls]")
		      ("xls" "\t" "[Csv/Txt/<Xls>]")))
	 (setq mens (last (assoc *Format* lsts)))
	 (initget "Csv Txt Xls _csv txt xls")
	 (if (setq tmp (getkword (strcat "\nFormat file;" mens ": ")))
	  (setq *Format* tmp)
	 )
	 (setq Separator (cadr (assoc *Format* lsts)))
	)
	;;_________________________________________________
	(defun aux:SelectFile ( Extension / ff)
	 (if (setq ff (getfiled "Select File" (if *TmpRutaFile* *TmpRutaFile* "") Extension 1))
	  (setq *TmpRutaFile* (strcat (vl-filename-directory ff) "\\"))
	 );c.if
	 ff
	);c.defun
 
 	;;_________________________________________________
	; grdx - graphic cross utility
	(defun grdx (p col size / h)
	  (setq h (/ (getvar "viewsize") size))
	  (grdraw (list (- (car p) h) (- (cadr p) h))
	          (list (+ (car p) h) (+ (cadr p) h)) col 0)
	  (grdraw (list (- (car p) h) (+ (cadr p) h))
	          (list (+ (car p) h) (- (cadr p) h)) col 0)
	  p
	);c.defun
 ;;--------------------- MAIN -----------------
 (or *Prec* (setq *Prec* 4))
 (setq p1 (getpoint "\nPick first point: "))
 (while p1
  (grdX p1 213 125)
  (setq lstFile (cons p1 lstFile))
  (setq p1 (getpoint " >> Pick Next point: "))
 )
 (cond
  (lstFile
   (initget (+ 4))
   (if (setq tmp (getint (strcat "\nPrecisión;<" (itoa *Prec*) ">: ")))
    (setq *Prec* tmp)
   )
   (GetFormatFile)
   (setq sFile (aux:SelectFile *Format*))
   (cond
    (sFile
     (setq i 1)
     (setq oFile (open sFile "w"))
     (write-line "COORDINATES OF POINTS" oFile)
     (write-line (strcat "#" Separator "X" Separator "Y" Separator "Z") oFile)
     (mapcar
      (function
       (lambda (pt)
	(write-line (strcat (itoa i) Separator
			    (rtos (car  pt) 2 *Prec*) Separator
			    (rtos (cadr pt) 2 *Prec*) Separator
			    (rtos (last pt) 2 *Prec*)
		    )
	 oFile)
	(setq i (1+ i))
       )
      )
      lstFile
     );c.mapcar
     (close oFile)
     (alert (strcat "File: \n\n[" sFile "]\n\nhas been created."))
     ;;(startAPP (strcat "notepad.exe " sFile))
     (command "shell" (strcat "start " sFile))
    )
   )
  )
 );c.cond
 (princ)
)
(princ)

regards...

 

Message 12 of 13

Anonymous
Not applicable

@joselggalan

 

Thank you very much, that's exactly what I was looking for.

0 Likes
Message 13 of 13

john.uhden
Mentor
Mentor
Accepted solution

I think this will serves your purpose.

 

If you are creating a new file, it will start numbering the points at #1.

If you are appending to an existing file, it will read the file and start appending at the next higher number.

It saves the last file written or appended in the registry, which becomes the default file, but you can select/create a different file if you wish.

It writes the coordinates to 4 decimal places in the order of X, Y, Z, comma-delimited.

John F. Uhden