PDA

View Full Version : Building Level routine


jmcshane
2006-07-17, 04:30 PM
Hi,

I'm trying to write this routine to insert a "Building Level" block onto our drawings.

It works fine, but I'm trying to make sure that the user picks a horizontal line
and if the line is not horizontal, that the user will keep picking untill a horizontal line IS picked.

The trouble is I'm not to handy with this (if ....then) stuff.

I would be grateful if somebody could point me in the right direction.

Cheers

John

Leon.Brumin
2006-07-17, 04:51 PM
use (while ...

(while (/= DatumYE DatumYS)
ask to select line again ...
check the line ...
);end of while

then
insert block

jmcshane
2006-07-17, 05:10 PM
I'm sorry, i'm not getting this.

Should I get rid of the (if.....) statement completely ??

Thanks

John

Opie
2006-07-17, 05:38 PM
I'm sorry, i'm not getting this.

Should I get rid of the (if.....) statement completely ??

Thanks

John
You may try this. I have not tested it due to not having access to the block(s).
(DEFUN C:SITELEVEL (/ AT DATUMLINE DATUMYS
DATUMYE DATUMLINE DATUMLEVEL INSERTPNT
ATTVAL
)
(SETVAR "cmdecho" 0)
(IF (= DEFSCALE NIL)
(SETQ DEFSCALE " ")
) ;_ end of if
(PROMPT "\nEnter Scale Factor : <")
(PRINC DEFSCALE)
(PRINC ">")
(SETQ SCALE (GETSTRING))
(IF (= SCALE "")
(SETQ SCALE DEFSCALE)
) ;_ end of if
(SETQ DEFSCALE SCALE)
(SETQ AT (GETVAR "attreq"))
(SETVAR "attreq" 0)
(while (not (SETQ DATUMLINE (ENTSEL "\nSelect Horizontal Datum Line :"))))
(SETQ DATUMLINE (CDR (ENTGET (CAR DATUMLINE))))
(SETQ DATUMYS (CADR (CDR (ASSOC 10 DATUMLINE))))
(SETQ DATUMYE (CADR (CDR (ASSOC 11 DATUMLINE))))

; ***************************************************************************************************************
(WHILE (/= DATUMYE DATUMYS)
(PRINC "\nDatum Line is not Level, Please Try Again :")
(SETQ DATUMLINE NIL)
(WHILE (NOT (SETQ DATUMLINE (ENTSEL "\nPlease select a Horizontal Datum Line :"))))
(SETQ DATUMLINE (CDR (ENTGET (CAR DATUMLINE))))
(SETQ DATUMYS (CADR (CDR (ASSOC 10 DATUMLINE))))
(SETQ DATUMYE (CADR (CDR (ASSOC 11 DATUMLINE))))
)

; ***************************************************************************************************************

;;(IF (= DATUMYE DATUMYS)
;;(PROGN
(SETQ DATUMLEVEL
(ATOF (GETSTRING "\nPlease Enter Datum Level :"))
) ;_ end of setq
(WHILE
(SETQ INSERTPNT (GETPOINT "\nSelect insertion point : "))
(SETQ ATTVAL (RTOS (+ (/ (- (CADR INSERTPNT) DATUMYE) 1000)
DATUMLEVEL
) ;_ end of +
2
3
) ;_ end of rtos
) ;_ end of setq
(COMMAND "-insert" "Side Level" INSERTPNT SCALE SCALE "0")
(COMMAND "-attedit" "y" "*" "*" "*" "l" "v" "r" ATTVAL "")
) ;_ end of while
;;) ;_ end of progn
;;(alert "Datum Line Not Level!")
;;) ;_ end of if

; ***************************************************************************************************************

; ***************************************************************************************************************

(SETVAR "attreq" AT)
(SETVAR "cmdecho" 1)
) ;_ end of defun

The items in red are my changes. Since you would be using a while statement to get a horizontal line, I removed the If statement testing for the horizontal. The While statement will not exit until it a horizontal line is selected.

You may also want to test if you selected a LINE object before getting the coordinates.

T.Willey
2006-07-17, 05:45 PM
FYI...

I always test with "equal" when testing numbers (it seems to be more accurate). So I would change

(WHILE (/= DATUMYE DATUMYS)

to

(WHILE (not (equal DATUMYE DATUMYS 0.0001))

jmcshane
2006-07-17, 06:19 PM
Thanks guys,

Thats working a treat.

I really need to read up on all this (while, not) etc.

John