Jump to content

Has anyone a lisp for extacting y values


coombsie11
 Share

Recommended Posts

Certainly,

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:ellev [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] *error* Line Text P1 P2 PT TSZE X Y[b][color=RED])[/color][/b]
 [i][color=#990099];; Lee Mac  ~  01.03.10[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] *error* [b][color=RED]([/color][/b]msg[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]wcmatch[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcase[/color][/b] msg[b][color=RED])[/color][/b] [b][color=#a52a2a]"*BREAK,*CANCEL*,*EXIT*"[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#a52a2a]"\n** Error: "[/color][/b] msg [b][color=#a52a2a]" **"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] Line [b][color=RED]([/color][/b]p1 p2[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]entmakex[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#a52a2a]"LINE"[/color][/b][b][color=RED])[/color][/b]
                   [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]10[/color][/b] p1[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]11[/color][/b] p2[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] Text [b][color=RED]([/color][/b]pt hgt str[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]entmakex[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#a52a2a]"TEXT"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]10[/color][/b]  pt[b][color=RED])[/color][/b]
                   [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]40[/color][/b] hgt[b][color=RED])[/color][/b]   [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]1[/color][/b]  str[b][color=RED])[/color][/b]
                   [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]50[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]angle[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=DARKRED]'[/color][/b]UCSXDIR[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                   [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]7[/color][/b]  [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=DARKRED]'[/color][/b]TEXTSTYLE[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]  
 
 [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] *scl [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *scl [b][color=#009900]100[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]initget[/color][/b] [b][color=#009900]6[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *scl [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]getint[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#a52a2a]"\nEnter Drawing Scale <"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]itoa[/color][/b] *scl[b][color=RED])[/color][/b] [b][color=#a52a2a]"> : "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]*scl[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] tsze [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] [b][color=#009999]0.002[/color][/b] *scl[b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] pt [b][color=RED]([/color][/b][b][color=BLUE]getpoint[/color][/b] [b][color=#a52a2a]"\nPick Elevation Line Point: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] x [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] pt[b][color=RED])[/color][/b] y [b][color=RED]([/color][/b][b][color=BLUE]cadr[/color][/b] pt[b][color=RED])[/color][/b][b][color=RED])[/color][/b]

   [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] p1 [b][color=RED]([/color][/b][b][color=BLUE]trans[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]-[/color][/b] x [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] tsze [b][color=#009900]2[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]+[/color][/b] y tsze[b][color=RED])[/color][/b] [b][color=#009999]0.[/color][/b][b][color=RED])[/color][/b] [b][color=#009900]1[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b]
         p2 [b][color=RED]([/color][/b][b][color=BLUE]trans[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]+[/color][/b] x [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] tsze [b][color=#009900]2[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]+[/color][/b] y tsze[b][color=RED])[/color][/b] [b][color=#009999]0.[/color][/b][b][color=RED])[/color][/b] [b][color=#009900]1[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

   [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]function[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b]x[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]line [b][color=RED]([/color][/b][b][color=BLUE]trans[/color][/b] pt [b][color=#009900]1[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b] x[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] p1 p2[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b]line p1 p2[b][color=RED])[/color][/b]

   [b][color=RED]([/color][/b]Text [b][color=RED]([/color][/b][b][color=BLUE]trans[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] x [b][color=RED]([/color][/b][b][color=BLUE]+[/color][/b] y tsze[b][color=RED])[/color][/b] [b][color=#009999]0.[/color][/b][b][color=RED])[/color][/b] [b][color=#009900]1[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b] tsze [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]<=[/color][/b] [b][color=#009900]0[/color][/b] y[b][color=RED])[/color][/b] [b][color=#a52a2a]"+"[/color][/b] [b][color=#a52a2a]""[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]rtos[/color][/b] y [b][color=#009900]2[/color][/b] [b][color=#009900]2[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 

 

See, that's the only real advantage of using command calls, all the coordinate transformations are implicit.

Link to comment
Share on other sites

  • Replies 39
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    16

  • alanjt

    10

  • pontifex

    6

  • uddfl

    3

Top Posters In This Topic

Posted Images

the trailing zeros are affected by your Sys Var settings, not my code.

 

Sorry to be a party pooper, but DIMZIN also affects real-to-string conversions performed by the AutoLISP rtos and angtos functions.

 

Would it not be kinder to temporarily set DIMZIN to zero whilst you were doing the rtos conversion to be sure of getting the required output, then retrieve the DIMZIN value from before and re-instate it. Some folk might like it the way that it is set, rather than setting it specially for a Lisp routine.

Link to comment
Share on other sites

Sorry to be a party pooper, but DIMZIN also affects real-to-string conversions performed by the AutoLISP rtos and angtos functions.

 

Would it not be kinder to temporarily set DIMZIN to zero whilst you were doing the rtos conversion to be sure of getting the required output, then retrieve the DIMZIN value from before and re-instate it. Some folk might like it the way that it is set, rather than setting it specially for a Lisp routine.

 

That would the be easiest thing to do. :)

 

(defun c:ellev (/ *error* #Dimzin Line Text P1 P2 PT TSZE X Y)
 ;; Lee Mac  ~  01.03.10

 (defun *error* (msg)
   (and #Dimzin (setvar 'dimzin #Dimzin))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))

 (defun Line (p1 p2)
   (entmakex (list (cons 0 "LINE")
                   (cons 10 p1) (cons 11 p2))))

 (defun Text (pt hgt str)
   (entmakex (list (cons 0 "TEXT") (cons 10  pt)
                   (cons 40 hgt)   (cons 1  str)
                   (cons 50 (angle '(0 0 0) (getvar 'UCSXDIR)))
                   (cons 7  (getvar 'TEXTSTYLE)))))

 (setq #Dimzin (getvar 'dimzin))
 (setvar 'dimzin 0)
 
 (or *scl (setq *scl 100)) (initget 6)
 (setq *scl (cond ((getint (strcat "\nEnter Drawing Scale <" (itoa *scl) "> : "))) (*scl)))

 (setq tsze (* 0.002 *scl))

 (while (setq pt (getpoint "\nPick Elevation Line Point: "))
   (setq x (car pt) y (cadr pt))

   (setq p1 (trans (list (- x (/ tsze 2)) (+ y tsze) 0.) 1 0)
         p2 (trans (list (+ x (/ tsze 2)) (+ y tsze) 0.) 1 0))

   (mapcar (function (lambda (x) (line (trans pt 1 0) x))) (list p1 p2))
   (line p1 p2)

   (Text (trans (list x (+ y tsze) 0.) 1 0) tsze (strcat (if (<= 0 y) "+" "") (rtos y 2 2))))

 (and #Dimzin (setvar 'dimzin #Dimzin))

 (princ))

Link to comment
Share on other sites

Thanks Alan - now my code is 'contaminated' with your #var's :P :P

 

 

I thought it needed a little sprucing up. ;)

Force of habit.

 

I suppose I should have called it DZn or something.

Link to comment
Share on other sites

Say that again?

 

Well, for example, special characters (#, *, etc) are not valid in variable symbols in C, (and probably derivatives of such). The asterisk indicates a pointer in C, and the # is used for such statements as #include and #define... (can't remember the exact classification of these statements)

Link to comment
Share on other sites

Well, for example, special characters (#, *, etc) are not valid in variable symbols in C, (and probably derivatives of such). The asterisk indicates a pointer in C, and the # is used for such statements as #include and #define... (can't remember the exact classification of these statements)

 

Then modifications will be en route. I'll be working with C and .net very soon. Thanks for the heads up.

Link to comment
Share on other sites

Are you still working on learning C, or have you given that up [entirely or for the time being]?

 

I did a module of it for my degree - and got pretty familiar with the basic concepts of a console program - reading/writing files, arrays, pointers, and all the basic constructs. Was enjoyable.

 

I learnt the basics of C++ too, (just enough to make a few console programs), but I haven't steered either towards AutoCAD as yet. I keep meaning to focus on it, but it is all to easy to slip back into the nice and easy LISP :)

Link to comment
Share on other sites

I did a module of it for my degree - and got pretty familiar with the basic concepts of a console program - reading/writing files, arrays, pointers, and all the basic constructs. Was enjoyable.

 

I learnt the basics of C++ too, (just enough to make a few console programs), but I haven't steered either towards AutoCAD as yet. I keep meaning to focus on it, but it is all to easy to slip back into the nice and easy LISP :)

 

Right on....

Link to comment
Share on other sites

Have you started venturing out of LISP?

I've programed in other languages, but that was in high school. I bought a book on VB.Net close to a year ago, but haven't had time to do more than thumb through it.

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

 Share


×
×
  • Create New...