Jump to content

Modify Existing Lisp to include Z Values?


JQUAILE

Recommended Posts

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 by JQUAILE
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...