Author Topic: Whats wrong with this Lisp?  (Read 10590 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1406
Whats wrong with this Lisp?
« on: July 12, 2009, 05:24:27 AM »
Whats wrong with this lisp?

This lisp for insert points (in sequence) then create a table contains the points and position of each one

Code: [Select]
(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)
)

Jeff_M

  • King Gator
  • Posts: 4078
  • C3D user & customizer
Re: Whats wrong with this Lisp?
« Reply #1 on: July 12, 2009, 10:00:42 AM »
1. The error handler should be inside the routine.
2. Only close the file if it's open
3. If the current text style has a height = 0 the Text command fails. Check for this and either prompt for a text height or use the Textsize sysvar.
4. If running Object Snaps are set, the Line & Text commands may be affected by them. Save them, set them to 0, the reset them when done.
5. The hs-factor is being set to 0 because dividing 2 INTs returns an INT. Change the the 100 to 100.0 to get the desired value.
6. A number of items need to be corrected in the table creation. Hard-coding the column widths and heights of the columns & rows will make for a funky looking table. You will likely need to play with this until you get something usable.
7. Next time, please tell us HOW it doesn't work...i.e. what error messages do you get, what output do you get that differs from what you expect, etc.
« Last Edit: July 12, 2009, 10:07:35 AM by Jeff_M »

HasanCAD

  • Swamp Rat
  • Posts: 1406
Re: Whats wrong with this Lisp?
« Reply #2 on: July 12, 2009, 10:41:18 AM »
First, Thanx for your great analysing

Second, the problem is when create the table some times comes good and some times no.

I am using AutoCAD 2007

what i want is a lisp to insert a point with number (in sequance) and create a table with the number and the posision of each point (X & Y)

Regards
« Last Edit: July 12, 2009, 10:46:41 AM by asos2000 »

Lee Mac

  • Seagull
  • Posts: 12857
  • London, England
Re: Whats wrong with this Lisp?
« Reply #3 on: July 12, 2009, 10:59:55 AM »
what i want is a lisp to insert a point with number (in sequance) and create a table with the number and the posision of each point (X & Y)

How much is it worth...  ^-^ ?

HasanCAD

  • Swamp Rat
  • Posts: 1406
Re: Whats wrong with this Lisp?
« Reply #4 on: July 12, 2009, 12:16:18 PM »
what i want is a lisp to insert a point with number (in sequance) and create a table with the number and the posision of each point (X & Y)

How much is it worth...  ^-^ ?

We are a GeoTech Consultant
most of our work depends on the coordenate

suppose we have a power station.
one item of our work is PILES, each pile should be submented with the coordenate (Not dimensions).
the same for the piles of a bridges

This lisp will be very usefull for CIVIL draftmen. and im one of them

LEE your lisp in CADTutor is very good but Txt Position table is needed(See attached).


Lee Mac

  • Seagull
  • Posts: 12857
  • London, England
Re: Whats wrong with this Lisp?
« Reply #5 on: July 12, 2009, 02:00:45 PM »
what i want is a lisp to insert a point with number (in sequance) and create a table with the number and the posision of each point (X & Y)

How much is it worth...  ^-^ ?

LEE your lisp in CADTutor is very good but Txt Position table is needed...

Hmmm... I still can't see whats in it for me...  :|

Spike Wilbury

  • Guest
Re: Whats wrong with this Lisp?
« Reply #6 on: July 12, 2009, 03:00:34 PM »
Hmmm... I still can't see whats in it for me...  :|

You need to get use to... and wait for more requests (and more if you end up coming with great routines)... and where to stop :-P

Lee Mac

  • Seagull
  • Posts: 12857
  • London, England
Re: Whats wrong with this Lisp?
« Reply #7 on: July 12, 2009, 03:23:31 PM »
Hmmm... I still can't see whats in it for me...  :|

You need to get use to... and wait for more requests (and more if you end up coming with great routines)... and where to stop :-P

Well, being as I've got nothing else to do... here ya go  :-P


stevesfr

  • Newt
  • Posts: 54
Re: Whats wrong with this Lisp?
« Reply #8 on: July 12, 2009, 04:48:57 PM »
Lee,  mighty fine program, latest NumInc.   I always think and use coordinates as N & E as opposed to x, y.
I'd like to revise the program to do this.  Do I have to do any revision to the dcl file? or will making proper revsions to NumInc_V7_tab.lsp make the table read North, East, Elev, comment  and the x will fall in East etc.
thanks for clues,
Steve
Can't remember what I'm supposed to forget.

Lee Mac

  • Seagull
  • Posts: 12857
  • London, England
Re: Whats wrong with this Lisp?
« Reply #9 on: July 12, 2009, 07:30:04 PM »
Only the LISP file needs to be altered, just change this list to whatever you like:

         
Code: [Select]
(setq valLst '("X-Value" "Y-Value" "Z-Value" "Comments")) ;;<<-- Change this list to change Table Headers, must be in correct order.

stevesfr

  • Newt
  • Posts: 54
Re: Whats wrong with this Lisp?
« Reply #10 on: July 12, 2009, 08:20:24 PM »
Fine, that will allow editing/revision of the table.  I revised the table to read North, East, Elev.  but I now need a clue on how to enter the Y in the first column instead of X,  X in the second column instead of Y
I assume its in the code below the above line of revisions as you stated in previous response.
thanks for your patience and help.
Steve
Can't remember what I'm supposed to forget.

HasanCAD

  • Swamp Rat
  • Posts: 1406
Re: Whats wrong with this Lisp?
« Reply #11 on: July 13, 2009, 02:32:16 AM »
Quote
Well, being as I've got nothing else to do... here ya go  :-P

Version 7 is more than enough for me,
But there are some comments
- OSnap not working
- The increment number doest reset but continue from the last time.
- Text height dost read the textstyle format.
- See Attached

Thanks

Lee Mac

  • Seagull
  • Posts: 12857
  • London, England
Re: Whats wrong with this Lisp?
« Reply #12 on: July 13, 2009, 04:31:17 AM »
Fine, that will allow editing/revision of the table.  I revised the table to read North, East, Elev.  but I now need a clue on how to enter the Y in the first column instead of X,  X in the second column instead of Y
I assume its in the code below the above line of revisions as you stated in previous response.
thanks for your patience and help.
Steve


You will need to change the order of the titles in the list, and also change the order that the data is being compiled in the value list.

The point is compiled in the list at this point:

Code: [Select]
               (setq tbl_lst
                 (cons
                   (cons tStr
                     (vlax-safearray->list
                       (vlax-variant-value
                         (vla-get-TextAlignmentPoint tObj)))) tbl_lst))

Let me know if you get stuck.
« Last Edit: July 13, 2009, 04:36:24 AM by Lee Mac »

Lee Mac

  • Seagull
  • Posts: 12857
  • London, England
Re: Whats wrong with this Lisp?
« Reply #13 on: July 13, 2009, 04:39:55 AM »
- OSnap not working

Seems to work for me. F3 turns it on.

- The increment number doest reset but continue from the last time.

Yes, that is how I engineered it  ^-^

- Text height dost read the textstyle format.

You can enter the Text Height you want.


As for the rest of your requests, I think you are being unreasonable.

This is a help and advice site, I am in no way working for you - and I have already provided you with plentiful code without renumeration.


HasanCAD

  • Swamp Rat
  • Posts: 1406
Re: Whats wrong with this Lisp?
« Reply #14 on: July 13, 2009, 05:13:17 AM »
Mr. LEE

At fist sorry for disturbance you. and you have to be sure that I appraisate too much because of your help for all and specially for me in drafting.
Second as i told you Version 7 is more than enough for me,
Third we helping each other no one work for any one.
Forth you who make me being unreasonable because of your unlimited help.
finally, Sorry again