PDA

View Full Version : For A WHILE, again.


BoKirra
2009-04-02, 07:32 AM
Hi ALL,

I have a thought when reading previous threads in this forum.
But I found this is too hard:


Supposed a user have different pipe sections.
He needs to select a pipe for an existing hole in wall.
The hole size is labeled as "Hole" while "ODp" is for Pipe OD.
He may have used the code for Pipe run 01 selection.
The user is now working for the Pipe run 02 on the same drawing.

(1) If he simply hit the enter key, the code will
(1.a) Ask the user re-enter a suitable pipe size (< ODp Hole), or
(1.b) Ask the user to accept the previous input (for Pipe run 01)
that the code found. And if this is the case, the code will check
if (< ODp_previous Hole) is true.
Process (1) will not stop until input is valid.
This is a loop statement.

(2) If (>= ODp Hole),
the code will repeat the above process.
Again, it is a loop statement.

Your helps are much appreciated.

l3ch
2009-04-02, 11:07 AM
Let's see:
1.- In the main code, introduce something like this:
(setq current_pipe the_current_pipe_that_you_know)
(setq message_chip nil)
(setq pipe_size (determine_pipe_size current_pipe))
(while (< hole_size pipe_size)
(setq current_pipe (select_pipe_type current_pipe message_chip))
(setq pipe_size (determine_pipe_size current_pipe))
(setq message_chip T)
)
When you leave the WHILE loop, current_pipe is the desired pipe type. Be sure there is always a pipe that fits!

2.- Somewhere you need to define the functions, something like this:
(defun determine_pipe_size ( old_pipe chip / new_pipe)
;;; you should know how to select a pipe_type. If, by instance, the pipe type is a name, a way could be:
(if chip (promtp "Pipe selected doesn't fit"))
;;; Note: if you know the list of possible pipes, this is a good place to insert the next line:
(initget 0 "pipe_01 pipe_02 ...")
(setq new_pipe (getkword (strcat "New pipe code <" old_pipe ">: ")))
(if new_pipe new_pipe old_pipe)
)

(defun determine_pipe_size (pipe)
;;; here you code how to know the size of the pipe. Be sure to return the size.
)

BoKirra
2009-04-03, 12:42 AM
Thanks for your help.

The following is what I have so far:

(defun c:PIPE_OD (/ Hole ODp ODp_previous)
;----------------------------------------------------------
;;;Part (1)
;;;Detect the hole size here.
;----------------------------------------------------------
;;;Part (2)
;;;Select pipe size
;;; problem_1: I don't know how to get "ODp_previous" before a pipe OD is inputted.
(while (null ODp)
(setq ODp ODp_previous); problem_2: I'm not sure if it's correct.
(setq ODp (getreal
(strcat "\nSpecify pipe OD <"
ODp_previous
">: "))
); end of setq
); end of while
(while (>= ODp Hole)
(setq ODp ODp_previous); problem_2: I'm not sure if it's correct.
(setq ODp (getreal
(strcat "\nPipe doesn't fit into the hole. Re-enter pipe OD <: "
ODp_previous
">: "))
); end of setq
); end of while
;----------------------------------------------------------
;;;Part (3)
;;;Drawing pipe section
(if (< ODp Hole)
(command "circle" Insert_Pt "d" ODp)
); end of if
;----------------------------------------------------------
;;;Routine ends
(princ)
); end of defun