JQUAILE Posted March 27, 2014 Share Posted March 27, 2014 (edited) Hello All, Modify Existing Lisp to include Z Values? I have an existing Lisp (by Rocket Software) that outputs a blocks Attribute Value and X,Y Values. I would like to modify it to add the Z value as well and change the output file format from *.cdf format to *.CSV format. Existing Code is given below: ; Pilout - write the X and Y coordinates of all inserts of a block to a file. ; Copyright 1997 by Rocket software ; The other kind. ; Subroutine Frat - returns the value of the first filled attribute found, ; otherwise "". Takes one argument, the insertion ename. (DEFUN FRAT (enam / str) (while (and (null str) (/= "SEQEND" (cdr (assoc 0 (setq entt (entget (setq enam (entnext enam)))))))) (setq vall (cdr (assoc 1 entt))) (while (= (substr vall 1 1) " ") (setq vall (substr vall 2))) (if (/= vall "") (setq str vall))) (if str str "")) ; Frat end. (DEFUN C:PILOUT (/ num bl enampt entt ss filnam fn rad len so pa datstr) (setvar "cmdecho" 0) (setq num 0) (setq bl (getstring "Block to use or <Return> to select: ")) (if (and (= bl "") (setq enampt (entsel "Select a block: "))) (progn (setq entt (entget (car enampt))) (setq bl (cdr (assoc 2 entt))) (if bl (prompt bl)))) (if bl (setq ss (ssget "X" (list (cons 2 bl))))) (if ss (progn (setq filnam (getfiled "Data File" "Piles.cdf" "" 1)) (if filnam (setq fn (open filnam "w"))) (setq rad (/ (getvar "viewsize") 25)) (setq len (strcat "/" (itoa (sslength ss)))) (while (setq so (ssname ss num)) (setq entt (entget so)) (setq num (1+ num)) (grtext -2 (strcat (itoa num) len)) (setq pa (cdr (assoc 10 entt))) ; Translate point data to current ucs. (setq pa (trans pa 0 1)) (grdraw (polar pa (/ pi 4) rad) (polar pa (* 1.25 pi) rad) 7) (grdraw (polar pa (* pi 0.75) rad) (polar pa (* pi 1.75) rad) 7) (setq datstr (strcat (frat so) "," (rtos (car pa) 2 6) "," (rtos (cadr pa) 2 6))) (write-line datstr fn)) (if fn (close fn))) (if bl (write-line "\nCan't find any such block. ") (write-line "\nSome type of error..."))) (if ss (write-line (strcat "\nLines written to file: " (itoa num)))) (princ)) Any help with this would be greatly appreciated! Edited March 27, 2014 by JQUAILE Quote Link to comment Share on other sites More sharing options...
JQUAILE Posted March 27, 2014 Author Share Posted March 27, 2014 I see where the X & Y coordinate are being pulled from: (rtos (car pa) 2 6) "," (rtos (cadr pa) 2 6))) I tried adding: (rtos (caddr pa) 2 6))) as the function caddr should pull the Z value from the stored point variable "pa", but then I get nothing at all. pretty sure I am missing something on the front end like maybe pa is set to only store the X,Y values and not the Z value? Again, any help would be greatly appreciated. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Cad64 Posted March 27, 2014 Share Posted March 27, 2014 Please read the code posting guidelines: http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines I have moved your request to the Autolisp forum. Quote Link to comment Share on other sites More sharing options...
ymg3 Posted March 28, 2014 Share Posted March 28, 2014 JQUAILE, Try like this: (setq datstr (strcat (frat so) "," (rtos (car pa) 2 6) "," (rtos (cadr pa) 2 6) "," (rtos (caddr pa) 2 6) ) ) for changing to a csv file modify here: (setq filnam (getfiled "Data File" "Piles.csv" "" 1)) I did not test, so try it ymg Quote Link to comment Share on other sites More sharing options...
JQUAILE Posted March 28, 2014 Author Share Posted March 28, 2014 ymg3, Thank you very much, it worked like a charm! Quote Link to comment Share on other sites More sharing options...
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.