Jump to content

Whats wrong in this Lisp


asos2000

Recommended Posts

This lisp for coordinate

 

click in the points in order then create a table with the points number and X&Y

 

when run the routen

its pick the points and insert the point number

But can not create the table

 

I hope to find a solution or a lisp same like

 

 

(defun derr (s)                       ; If an error (such as CTRL-C) occurs
                                     ; while this command is active...
 (if (/= s "Function cancelled")
   (princ (strcat "\n*Error: " s))
 )
 (setvar "cmdecho" echo)
 (setvar "blipmode" blip)
 (setvar "luprec" decimal)
 (setq *error* olderr)               ; Restore old *error* handler
 (close file)
 (princ)
)
;----------------------------------------------------------------------------
(defun c:pt()

  (setq olderr *error*
               *error* derr)
  (setq echo (getvar "cmdecho"))
  (setq blip (getvar "blipmode"))
  (setq decimal (getvar "luprec"))
  (setvar "cmdecho" 0)
  (setvar "blipmode" 0)

     (setq pt_file (getstring "\nPoints File Name <points.txt>:"))
     (if (= pt_file "")
         (setq file (open "points.txt" "w"))
         (setq file (open pt_file "w"))
     )
     (setq h-scale (getint "\nHorizontal Scale  1:"))
     (setq pre_code (getstring "\nPrefix Code:"))
     (setq start_pn (getint "\nStart Number:"))

     (setq pn  start_pn)
     (setq hs-factor (/ h-scale 100))
     (setq p 0)
     (setq n 1)
     (while p
            (setq p (getpoint "\nSelect Point <Exit>:"))
            (if p
                (progn
                   (setq str_pn (itoa pn))
                   (setq pt_code (strcat pre_code str_pn))
                   (setq ptxt (list
                                 (- (car p) (* 0.5 hs-factor))
                                 (+ (cadr p) (* 0.5 hs-factor))
                              ))

                   (command "point" p)
                   (command "text" "m" ptxt "0" pt_code)

                   ;Writting Selected point to the file
                   ;-----------------------------------
                   (princ (strcat "\n" pt_code " " (rtos (car p)) " " 
                                  (rtos (cadr p)) ) file)
                   (setq pn (+ pn 1))

                   (setq pt_list1 (list (append (list pt_code) p)))
                   (if (= n 1)
                       (setq pt_list pt_list1)
                       (setq pt_list (append pt_list pt_list1))
                   )
                   (setq n (+ n 1))
                )
            )
     )
  (prompt "\n** Points Coordinates Table **")

  (setq p_l_up (getpoint "\nSelect Upper Left Cornner :\n"))
  (setq p_r_up (list (+ (car p_l_up) (* 7.2 hs-factor))
                     (cadr p_l_up) ))
  (setq ph1 (list (car P_l_up)
                  (- (cadr p_l_up) (* 1 hs-factor)) ))
  (setq ph2 (list (car P_r_up)
                  (- (cadr p_r_up) (* 1 hs-factor)) ))
  (setq ph_txt1 (list (+ (car p_l_up) (* 0.6 hs-factor))
                      (- (cadr p_l_up) (* 0.5 hs-factor)) ))
  (setq ph_txt2 (list (+ (car p_l_up) (* 2.7 hs-factor))
                      (- (cadr p_l_up) (* 0.5 hs-factor)) ))
  (setq ph_txt3 (list (+ (car p_l_up) (* 5.7 hs-factor))
                      (- (cadr p_l_up) (* 0.5 hs-factor)) ))
  (command "line" p_l_up p_r_up "")
  (command "line" ph1 ph2 "")
  (command "text" "m" ph_txt1 "0" "Pt.")
  (command "text" "m" ph_txt2 "0" "X")
  (command "text" "m" ph_txt3 "0" "Y")

  (setq len_ptlst (length pt_list))
  (setq n_lst 0)
  (repeat len_ptlst
          (progn
             (setq p1 (list (car ph1)
                            (- (cadr ph1) (* 1 (+ n_lst 1) hs-factor)) ))
             (setq p2 (list (car ph2)
                            (- (cadr ph2) (* 1 (+ n_lst 1) hs-factor)) ))

             (setq ptxt1 (list 
                           (car ph_txt1)
                           (- (cadr ph_txt1)(* 1 (+ n_lst 1) hs-factor)) ))
             (setq ptxt2 (list 
                           (car ph_txt2)
                           (- (cadr ph_txt2)(* 1 (+ n_lst 1) hs-factor)) ))
             (setq ptxt3 (list 
                           (car ph_txt3)
                           (- (cadr ph_txt3)(* 1 (+ n_lst 1) hs-factor)) ))
             (setq x (rtos (nth 1 (nth n_lst pt_list))))
             (setq y (rtos (nth 2 (nth n_lst pt_list))))

             (princ (strcat "\rPoint Number " (nth 0 (nth n_lst pt_list))))
             (command "text" "m" ptxt1 "0" (nth 0 (nth n_lst pt_list)))
             (command "text" "m" ptxt2 "0" x)
             (command "text" "m" ptxt3 "0" y)
             (command "line" p1 p2 "")

          )
          (setq n_lst (+ n_lst 1))
  )

  (setq pv1 (list (+ (car p_l_up) (* 1.2 hs-factor))
                  (cadr p_l_up) ))
  (setq pv2 (list (+ (car p_l_up) (* 4.2 hs-factor))
                  (cadr p_l_up) ))
  (setq pv3 (list (+ (car p1) (* 1.2 hs-factor))
                  (cadr p1) ))
  (setq pv4 (list (+ (car p1) (* 4.2 hs-factor))
                  (cadr p1) ))
  (command "line" p_l_up p1 "")
  (command "line" pv1 pv3 "")
  (command "line" pv2 pv4 "")
  (command "line" p_r_up p2 "")
  (setvar "cmdecho" echo)
  (setvar "blipmode" blip)
  (setvar "luprec" decimal)
  (setq *error* olderr)               ; Restore old *error* handler
  (close file)
  (princ)
)

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...