3 COND statement

3 COND statement

Anonymous
Not applicable
1,643 Views
14 Replies
Message 1 of 15

3 COND statement

Anonymous
Not applicable

Good day every one!!!..

 

I need some help in some COND statement....

 

I have 3 COND statement to grab the project number from the path of the Dwg at the time I need to plot...

the first 2 work OK, but the third is the one I can't make it work ....

If the user change the project number I need to set the FLAG = "!ALERT"

 

where is my error? please help...

 

(defun ProjectNumber ()
   (setq SplitDwgPrefix (splitdirs (getvar "dwgprefix")))      ; ("U:" "100000" "elec")
   (setq GetDrive (nth 0 SplitDwgPrefix))                           ; "U:"
   (setq DWG_PATH (getvar "dwgprefix"))                         ; get the path of the files => "U:/100000/elec/"
   (setq user_name (getvar "loginname"))
   (setq PNumber (nth 1 SplitDwgPrefix))                          ; "\\100000\\"

   (set_tile "jobnumber" PNumber)
   (setq PNumber0 (get_tile "jobnumber"))


  (cond
        ; If is Drive "U" and Project Number is not changed manually
        (  (and (= GetDrive "U:") (= PNumber0 PNumber)
                  (setq jobnumber PNumber)
                  (setq Flag "---")
                  (alert (strcat jobnumber " Cond1"))
          )
       )

 

       ; If Project number is NIL and is not in drive "U"
      (  (/= GetDrive "U:")
           (progn
               (ProjectNumberDCL "Please... Enter Project Number... " " * Project Number *" "0000.00")
               (setq jobnumber PrjNumber)
               (setq Flag "!ALERT")
               (alert (strcat jobnumber " Cond2"))                     ; for testing only
          )

      )

 

     ; if the Project Number is changed manually                  --- IS NOT WORKING.!!
     (  (/= PNumber PNumber0)
        (progn
            (setq PNumber1 (get_tile "jobnumber"))
            (setq jobnumber PNumber1)
            (setq Flag "!ALERT")                                           
            (alert (strcat jobnumber " Cond3"))                     ; for testing only 
        )

    )
  )  ; cond
  jobnumber
) ; defun

 

 

at the OK button I have this.....to re-check the project number

 

(action_tile "accept" "(mplt_chkl)(projectNumber)(mplt_Info)")
(action_tile "cancel" "(done_dialog)")

 

 

at the DCL file that section is .....

 

: boxed_column {
  fixed_width = true;
  fixed_height = true;
  label = "Job Number:";
  : edit_box {
    key = "jobnumber";
    width = 12;
    height = 1;
  }
spacer;
}

 

0 Likes
Accepted solutions (2)
1,644 Views
14 Replies
Replies (14)
Message 2 of 15

dbroad
Mentor
Mentor

Even though it's well commented, I haven't got the big picture. That said, in your second case, your comment says that the project number is nil but there is no test for that condition.

 ; If Project number is NIL and is not in drive "U"
      (  (/= GetDrive "U:")

Your last check merely checks to see if the project number has been changed manually.  I'm not sure how the test justifies that assumption.

 ; if the Project Number is changed manually                  --- IS NOT WORKING.!!
     (  (/= PNumber PNumber0)

In general a cond statement should always end with a default case (in your case a 4th case) where any assumptions made that might be false give feedback of an exceptional case.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 3 of 15

Anonymous
Not applicable

thank you  

 

 

 

 
(/= PNumber PNumber0)
 
thanks...
0 Likes
Message 4 of 15

dbroad
Mentor
Mentor

If the drawing hasn't been saved, the dwgprefix could be anything and splitdwgprefix could be returning something other than what is assumed.  Thorough testing of splitdwgprefix for unexpected cases is merited.

 

If the person hadn't entered anything for the job number, I wouldn't say that it had been changed manually. Does your lisp pre populate the job number field?

 

You still need a 4th condition for debugging purposes.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 5 of 15

Anonymous
Not applicable

my comments between the lines...

 

If the drawing hasn't been saved, the dwgprefix could be anything and splitdwgprefix could be returning something other than what is assumed.  Thorough testing of Thorough testing of splitdwgprefix for unexpected cases is merited. .... ;;;>>>> that where COND2 take place and is working OK. getting everything Outside of drive "U:\"

 

If the person hadn't entered anything for the job number, I wouldn't say that it had been changed manually. Does your lisp pre populate the job number field?

Does your lisp pre populate the job number field?  .... ;;;>Yes it is pre-populated and is working OK.

 

You still need a 4th condition for debugging purposes. ... .... ;;;> I added the (T)

 

0 Likes
Message 6 of 15

dbroad
Mentor
Mentor

Why do you need to use  (setq PNumber1 (get_tile "jobnumber")) if you just tested it and already know what it's value is. You just used PNumber0 for comparison purposes. Just use it. I don't know what is not working though.  What does it actually do?

 

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 7 of 15

Anonymous
Not applicable

 

Please, can you or somebody else just take the code, modify and show me, where is my mistake...?

 

Thank you for your help..

0 Likes
Message 8 of 15

dbroad
Mentor
Mentor
Accepted solution

I don't see how anyone could "fix" such incomplete code.  Here is your code gutted of dialog calls and external routines.  Cond3 works fine as far as I can tell.

(defun ProjectNumber (/ DWG_PATH FLAG GETDRIVE JOBNUMBER PNUMBER PNUMBER0 PNUMBER1 PRJNUMBER SPLITDWGPREFIX USER_NAME)
  (setq SplitDwgPrefix  '("U:" "100000" "elec"))
  (setq GetDrive "U:")
  (setq DWG_PATH "U:/100000/elec/")
  (setq user_name "Bob")
  (setq PNumber "\\100000\\")
  (setq PNumber0"\\100001\\")
   (cond
					; If is Drive "U" and Project Number is not changed manually
    ((and (= GetDrive "U:")
	  (= PNumber0 PNumber)
	  (setq jobnumber PNumber)
	  (setq Flag "---")
	  (alert (strcat jobnumber " Cond1"))
     )
    )

					; If Project number is NIL and is not in drive "U"
    ((/= GetDrive "U:")
     (progn
       (setq jobnumber PrjNumber)
       (setq Flag "!ALERT")
       (alert (strcat jobnumber " Cond2")) ; for testing only
     )

    )

					; if the Project Number is changed manually                  --- IS NOT WORKING.!!
    ((/= PNumber PNumber0)
     (progn
       (setq PNumber1 PNumber0)
       (setq jobnumber PNumber1)
       (setq Flag "!ALERT")
       (alert (strcat jobnumber " Cond3")) ; for testing only 
     )

    )
  )					; cond
  jobnumber
)					; defun

 

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 9 of 15

Anonymous
Not applicable

thanks, I will check it.

0 Likes
Message 10 of 15

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

Good day every one!!!..

 

I need some help in some COND statement....

 

I have 3 COND statement to grab the project number from the path of the Dwg at the time I need to plot...

the first 2 work OK, but the third is the one I can't make it work ....

If the user change the project number I need to set the FLAG = "!ALERT"

 

where is my error? please help...

 

---snip

 

  (cond
        ; If is Drive "U" and Project Number is not changed manually
        (  (and (= GetDrive "U:") (= PNumber0 PNumber)
                  (setq jobnumber PNumber)
                  (setq Flag "---")
                  (alert (strcat jobnumber " Cond1"))
          )
       )

 

 ---snip


If this is the original code, the first one is not ok.

 

The only reason you don't get an error and it apears to work is because they all return T(rue) for the AND statement.

The correct way would be:

 

((and (= GetDrive "U:")(= PNumber0 PNumber))

   (setq jobnumber PNumber)
   (setq Flag "---")
   (alert (strcat jobnumber " Cond1"))

)

 

p.s.: You don't need (progn inside a (cond

Message 11 of 15

roland.r71
Collaborator
Collaborator

Your problem is not with the 3 conds, the "problem" is, the 3rd cond is never true, because YOU MAKE IT SO at the beginning:

 

(setq PNumber (nth 1 SplitDwgPrefix))                          ; "\\100000\\"
(set_tile "jobnumber" PNumber)
(setq PNumber0 (get_tile "jobnumber"))

Here, you first retrieve the PNumber var. ("\\100000\\")

Then you set "jobnumber" tile to PNumber var value. ("\\100000\\")

Then you read the "jobnumber" tile into PNumber0 var. (so, again: "\\100000\\")

 

Then, at cond 3 you get:

(/= PNumber PNumber0)

 

Well, that's like saying:

(/= "\\100000\\" "\\100000\\") - which is never going to be True.

0 Likes
Message 12 of 15

roland.r71
Collaborator
Collaborator
(defun ProjectNumber ()
   (setq SplitDwgPrefix (splitdirs (getvar "dwgprefix")))      ; ("U:" "100000" "elec")
   (setq GetDrive (nth 0 SplitDwgPrefix))                           ; "U:"
   (setq DWG_PATH (getvar "dwgprefix"))                         ; get the path of the files => "U:/100000/elec/"
   (setq user_name (getvar "loginname"))
   (setq PNumber (nth 1 SplitDwgPrefix))                          ; "\\100000\\"

   (set_tile "jobnumber" PNumber)
(setq PNumber0 (get_tile "jobnumber")) (cond

The red lines should NOT be inside this function (which you call when user hits the "OK" button)

But BEFORE you test for user input (& the (set_tile ...) should of course be placed AFTER you create the dialog.)

0 Likes
Message 13 of 15

roland.r71
Collaborator
Collaborator

In fact, currently the user can not set it manually, even if he wanted to.

As soon as he hits "OK", whatever he typed into that "tile" get's overwritten by the project number derived from the files path.

 

Something you should notice during testing. (ok, it might be in a bit of a fast flash Smiley Tongue)

0 Likes
Message 14 of 15

john.uhden
Mentor
Mentor

Of course the (alert ...) is within the (and ...), and since alert always returns nil, then the (and ...) will return nil.

 

And it seems that Pnumber is always made = Pnumber0.

 

It's a wonder that any of the conditions is met.

John F. Uhden

0 Likes
Message 15 of 15

Anonymous
Not applicable
Accepted solution

thank you all... dbroad, roland.r71 and john.uhden.

 

I did follow and made some changes to the dbroad suggestion and it work....

 

thank a lot guys....

 

 

 

0 Likes