Jump to content

Recommended Posts

Posted

Everyone who has to draw lots of Survey Plans, CP, DP, RP has their different methods of efficiency. I'm sick of typing @,

 

(defun C:BD  (/ LEN DEGS MINS SECS)
(command "_.line" (getpoint "\nPick a starting point: ")

;And Copy this bit 100 times or so as necessary*******
        (strcat "@" (rtos (getreal "\nType Length: ")) "<"
       (if (= (setq DEGS (getstring "\nType Degrees: ")) "") "0" DEGS) "d"
       (if (= (setq MINS (getstring "\nType Minutes: ")) "") "0" MINS) "'"
       (if (= (setq SECS (getstring "\nType Seconds: ")) "") "0" SECS) "\""
          )
;******************************************

)
(princ))

 

Now this works fine, the code just doesn't look nice.

I've tried putting a while loop around the bit I copy 100 times:

 

(Setq zzz 0)
(command "_.line" (getpoint "\nPick a starting point: ")
    (while (/= zzz 3)
        (strcat "@" (rtos (getreal "\nType Length: ")) "<"
       (if (= (setq DEGS (getstring "\nType Degrees: ")) "") "0" DEGS) "d"
       (if (= (setq MINS (getstring "\nType Minutes: ")) "") "0" MINS) "'"
       (if (= (setq SECS (getstring "\nType Seconds: ")) "") "0" SECS) "\""
          )
      (setq zzz (+ zzz 1)))

 

But then the 'line' command doesn't draw each line as I go, in fact it doesn't seem to do anything. Can while loops be placed inside of a line command?

Any help would be appreciated.

Posted

Try this buddy:

 

(defun c:test (/ pt len deg mIs Sec Ang)
 (if (setq pt (getpoint "\nSelect Starting Point: "))
   (progn
     (command "_.line" "_non" pt)
     (while
       (and
         (not (initget 2))
         (setq len (getdist pt "\nSpecify Length: "))
         (or (setq deg (getreal "\nDegrees: ")) (setq deg 0.))
         (or (setq mIs (getreal "\nMinutes: ")) (setq mIs 0.))
         (or (setq Sec (getreal "\nSeconds: ")) (setq Sec 0.))
         (setq Ang (* pi (/ (+ deg (/ mIs 60.) (/ Sec 3600.)) 180.))
               pt (polar pt Ang len)))
       (command "_non" pt))
     (command "")))
 (princ))
        

Posted

No problem - if you need the any part of the code explained, just shout :)

Posted

Yes I'll have to dwell on the code for a few hours first before I have code questions :-)

An immediate question I have is, I usually have 0 degrees facing up the page but this code outputs it to the right. Where is this set in the code and can I change it?

And what does the _non do?

Ta.

Posted

An immediate question I have is, I usually have 0 degrees facing up the page but this code outputs it to the right. Where is this set in the code and can I change it?

 

I have merely converted the Degree/Min/Sec angle into Radians, and just used the Polar function to plot the point. So, if you want 0 Degrees to be Vertical - just shift all measurements by (pi/2) rads (90 degs).

 

 

(defun c:test (/ pt len deg mIs Sec Ang)
 (if (setq pt (getpoint "\nSelect Starting Point: "))
   (progn
     (command "_.line" "_non" pt)
     (while
       (and
         (not (initget 2))
         (setq len (getdist pt "\nSpecify Length: "))
         (or (setq deg (getreal "\nDegrees: ")) (setq deg 0.))
         (or (setq mIs (getreal "\nMinutes: ")) (setq mIs 0.))
         (or (setq Sec (getreal "\nSeconds: ")) (setq Sec 0.))
         [color=Red][b](setq Ang (* pi (/ (+ deg (/ mIs 60.) (/ Sec 3600.)) 180.))[/b][/color]
               pt (polar pt [color=Blue][b](+ Ang (/ pi 2.))[/b][/color] len)))
       (command "_non" pt))
     (command "")))
 (princ))

 

 

 

And what does the _non do?

 

Disregards OSNAPS, so that the plotted points are accurate.

Posted

Thanks again. That _non is handy as I was getting a few zero length lines before.

I should have asked this along with the 0degrees facing north question; Polar computes anti-clockwise, can it be made to compute clockwise? I thought maybe *-1 but that doesn't work...

 

Edit: I'm glad you didn't stay up :), -1 does work:

 

(setq Ang (* pi (/ (+ deg (/ mIs 60.) (/ Sec 3600.)) 180.))
               pt (polar pt (+ (* Ang -1.) (/ pi 2.)) len)))

 

Thanks for your help Lee

Posted

Would this not work?

 

(defun c:test (/ pt len deg mIs Sec Ang)
 (if (setq pt (getpoint "\nSelect Starting Point: "))
   (progn
     (command "_.line" "_non" pt)
     (while
       (and
         (not (initget 2))
         (setq len (getdist pt "\nSpecify Length: "))
         (or (setq deg (getreal "\nDegrees: ")) (setq deg 0.))
         (or (setq mIs (getreal "\nMinutes: ")) (setq mIs 0.))
         (or (setq Sec (getreal "\nSeconds: ")) (setq Sec 0.))
         (setq Ang (* pi (/ (+ deg (/ mIs 60.) (/ Sec 3600.)) 180.))
               pt (polar pt (+ (* -1. Ang) (/ pi 2.)) len)))
       (command "_non" pt))
     (command "")))
 (princ))

 

Edit, nice one mate.

Posted

As another option look at ACAD system variables AngBase and AngDir

Posted

Those variables do look like a better alternative to "- pi/2" & "*-1". Just not too sure how to implement them.

 

An aside: Lee I've had a good look at your code and I think it all makes sense! As for writing it myself...

Just out of interest, regarding the code I initially posted, it seems to me it's not possible to run a while loop without running another command (eg the polar command). Is this true?

Posted
As another option look at ACAD system variables AngBase and AngDir

 

Nice Idea CAB - hadn't thought of that.

 

Just out of interest, regarding the code I initially posted, it seems to me it's not possible to run a while loop without running another command (eg the polar command). Is this true?

 

You can have a while with just a test statment, for example, observe the following code (best example I could think of):

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:test [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] ans[b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ans
       [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=#ff00ff]"\nType an Even Number <10> : "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=#009900]10[/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]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]zerop[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]rem[/color][/b] ans [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=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]prompt[/color][/b] [b][color=#ff00ff]"\nYou Typed an Odd Number!"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Stay in Loop[/color][/i]
       [b][color=BLUE]nil[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Else Exit Loop[/color][/i]
   [b][color=RED])[/color][/b] [i][color=#990099]; End Progn[/color][/i]
 [b][color=RED])[/color][/b] [i][color=#990099]; End While[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]alert[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]itoa[/color][/b] ans[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]
       

 

Notice that the WHILE statement only includes a test statement, which, if returns nil, will exit the loop.

Posted

A variation on Lee's routine:

(defun c:test (/ pt pt1 len deg mIs Sec Ang)
 (if (setq pt (getpoint "\nSelect Starting Point: "))
   (progn
     (while
       (and
         (not (initget 2))
         (setq len (getdist pt "\nSpecify Length: "))
         (or (setq deg (getreal "\nDegrees: ")) (setq deg 0.))
         (or (setq mIs (getreal "\nMinutes: ")) (setq mIs 0.))
         (or (setq Sec (getreal "\nSeconds: ")) (setq Sec 0.))
         ;;  calc new point based on AngBase 90 & AngDir 1=Clockwise
         (setq Ang (* pi (/ (+ deg (/ mIs 60.) (/ Sec 3600.)) 180.))
               pt1 (polar pt (+ (* -1. Ang) (/ pi 2.)) len))
       )
      (entmake
        (list (cons 0 "LINE")
              (cons 10 pt)
              (cons 11 pt1)
        )
      )
      (setq pt pt1)
     )
   )
 )
 (princ)
)

Posted

Thanks to you both.

Aside: That "Lisp Logic and More" tut is pretty good.

 

Well I got heaps more lisp questions but they're really not to do with drawing survey plans so I'll ask them in another thread; This ones' solved.

Posted
Thanks to you both.

Aside: That "Lisp Logic and More" tut is pretty good.

 

Well I got heaps more lisp questions but they're really not to do with drawing survey plans so I'll ask them in another thread; This ones' solved.

 

Ask away Steve, we'd be happy to explain :)

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