DCL Error Trap Help

DCL Error Trap Help

Jonathan3891
Advisor Advisor
1,609 Views
10 Replies
Message 1 of 11

DCL Error Trap Help

Jonathan3891
Advisor
Advisor

My lisp runs as it should, but I get "error: quit / exit abort" after its finished.

 

Can someone with more experience help me out?

 

Thanks!

 

;Modify Z Elevation
;by Jonathan Norton
(defun c:modz (/ dcl_id ) (if(not Elv) (setq Elv "0.00") ) (setq flag 4) (setq dcl_id (load_dialog "ModZ.dcl")) (while (> flag 2) (if (not (new_dialog "ModZ" dcl_id)) (exit) ) (set_tile "Elv" Elv) (action_tile "Elv" "(setq Elv $value)") (action_tile "Accept" "(saveVars)(done_dialog 1)") (action_tile "Pick" "(saveVars)(done_dialog 4)") (action_tile "Cancel" "(done_dialog 0)(setq Elv nil)") (setq flag (start_dialog)) (if (= flag 1) (progn (setq ssi (ssget "X")) (unload_dialog dcl_id) (command "_.CHANGE" ssi "" "_P" "_E" Elv "") (princ(strcat "Object(s) Elevation set to " Elv)) ) ) (if (= flag 4) (progn (setq ss (ssget)) (unload_dialog dcl_id) (command "_.CHANGE" ss "" "_P" "_E" Elv "") (princ(strcat "Object(s) Elevation set to " Elv)) ) ) ) (princ) );defun (defun saveVars(/ Elv) (setq Elv(distof(get_tile "Elv"))) ) (princ)
ModZ : dialog {

label = "Modify Z";
 
	: edit_box
	{
	label = "Elevation:";
	key = "Elv";
	alignment = left;
	edit_limit = 20;
	edit_width = 20;
	}

	: row {
		: spacer { height = 1; }
		}

		:row {
		
	: button {
	label = "ALL";
	key = "Accept";
	alignment = centered;
	width = 12;
	is_default = true;
	allow_accept = true;
	mnemonic = "A";
	}

		: button {
	label = "PICK";
	key = "Pick";
	alignment = centered;
	width = 12;
	is_default = true;
	allow_accept = true;
	mnemonic = "P";
	}
 
	: button {
	label = "CANCEL";
	key = "Cancel";
	alignment = centered;
	width = 12;
	is_default = false;
	is_cancel = true;
	mnemonic = "C";
	}
	}
	}



Jonathan Norton
Blog | Linkedin
0 Likes
Accepted solutions (1)
1,610 Views
10 Replies
Replies (10)
Message 2 of 11

paullimapa
Mentor
Mentor

Looks like you've programmed a while loop:

(while (> flag 2)

But you've unloaded the dialog when you select Pick:

    (if (= flag 4)
      (progn
	(setq ss (ssget))
	(unload_dialog dcl_id)
	(command "_.CHANGE" ss "" "_P" "_E" Elv "")
	(princ(strcat "Object(s) Elevation set to " Elv))
	)
      )
    )

 Then the routine will loop back to the top & attempt to load the dialog again but it's no longer loaded:

  (if (not (new_dialog "ModZ" dcl_id))
    (exit)
  )

That's why you're getting the (exit) error message.

 

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 11

Jonathan3891
Advisor
Advisor
Can you show me how to fix it please?

Jonathan Norton
Blog | Linkedin
0 Likes
Message 4 of 11

paullimapa
Mentor
Mentor

Just don't unload the dcl when you select Pick:

    (if (= flag 4)
      (progn
	(setq ss (ssget))
; place a semicolon to not execute this code	(unload_dialog dcl_id) 
	(command "_.CHANGE" ss "" "_P" "_E" Elv "")
	(princ(strcat "Object(s) Elevation set to " Elv))
	)
      )
    )

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 11

Jonathan3891
Advisor
Advisor

I want the dialog to unload.

 

 


Jonathan Norton
Blog | Linkedin
0 Likes
Message 6 of 11

paullimapa
Mentor
Mentor
Accepted solution

If you want the dialog to unload then why create the while loop?

Just remove that completely from the code to eliminate the error message:

;Modify Z Elevation
;by Jonathan Norton
(defun c:modz (/ dcl_id ) (if(not Elv) (setq Elv "0.00") ) (setq flag 4) (setq dcl_id (load_dialog "ModZ.dcl")) ;
; no need for while loop
; (while (> flag 2)
; (if (not (new_dialog "ModZ" dcl_id)) (exit) ) (set_tile "Elv" Elv) (action_tile "Elv" "(setq Elv $value)") (action_tile "Accept" "(saveVars)(done_dialog 1)") (action_tile "Pick" "(saveVars)(done_dialog 4)") (action_tile "Cancel" "(done_dialog 0)(setq Elv nil)") (setq flag (start_dialog)) (if (= flag 1) (progn (setq ssi (ssget "X")) (unload_dialog dcl_id) (command "_.CHANGE" ssi "" "_P" "_E" Elv "") (princ(strcat "Object(s) Elevation set to " Elv)) ) ) (if (= flag 4) (progn (setq ss (ssget)) (unload_dialog dcl_id) (command "_.CHANGE" ss "" "_P" "_E" Elv "") (princ(strcat "Object(s) Elevation set to " Elv)) ) ) ;
; don't execute this closing bracket to while loop
; ) ; (princ) );defun (defun saveVars(/ Elv) (setq Elv(distof(get_tile "Elv"))) ) (princ)

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 11

Jonathan3891
Advisor
Advisor

Its in there because I was following the Afralisp guide on hiding dialog boxes. I'm trying to learn DCL.

 

What makes the DCL hide to make a selection?

Thanks for your help!


Jonathan Norton
Blog | Linkedin
0 Likes
Message 8 of 11

paullimapa
Mentor
Mentor
You can always execute (unload_dialog dcl_id) code at the very end without including it inside your (if (= flag test which does not hide the dialog

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 11

scot-65
Advisor
Advisor
(if (= flag 4)
(progn
(setq ss (ssget))
(unload_dialog dcl_id) <<<<<<<<<<<<< (setq flag 0)
(command "_.CHANGE" ss "" "_P" "_E" Elv "")
(princ(strcat "Object(s) Elevation set to " Elv))
)
)

Rewrite this to set the flag so it can escape the while loop.
Then, after closing the while loop, unload the dialog.

);while
(unload_dialog dcl_id)

Also, protect the user input!
(if (setq ss (ssget))...

Do not underestimate the ingenuity of complete fools.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 10 of 11

salman_majgaonkar
Contributor
Contributor
ModZ : dialog { label = "Modify Z";
: edit_box { label = "Elevation:"; key = "Elv"; alignment = left; edit_limit = 20; edit_width = 20;}
: row {
: spacer { height = 1; }}
:row {
: button { label = "ALL"; key = "Accept"; alignment = centered; width = 12; is_default = true; allow_accept = true; mnemonic = "A";}
: button { label = "PICK"; key = "Pick"; alignment = centered; width = 12; is_default = true; allow_accept = true; mnemonic = "P";}
: button { label = "CANCEL"; key = "Cancel"; alignment = centered; width = 12; is_default = false; is_cancel = true; mnemonic = "C";} }
:row {
: button { label = "Front view"; key = "Pick1"; alignment = centered; width = 12; is_default = true; allow_accept = true; mnemonic = "F";}
: button { label = "Top view"; key = "Pick2"; alignment = centered; width = 12; is_default = true; allow_accept = true; mnemonic = "T";} } }
(defun c:modz()
(if (not Elv) (setq Elv 0))
(setq flag 4)
(setq dcl_id (load_dialog "ModZ.dcl"))
(if (not (new_dialog "ModZ" dcl_id)) (exit))
(set_tile "Elv" (rtos Elv 2 3))
(action_tile "Elv" "(saveVars)")
(action_tile "Accept" "(done_dialog)(setq ddiag 1)")
(action_tile "Pick" "(done_dialog)(setq ddiag 2)")
(action_tile "Pick1" "(done_dialog)(setq ddiag 3)")
(action_tile "Pick2" "(done_dialog)(setq ddiag 4)")
(action_tile "Cancel"  "(setq ddiag 0)")
(start_dialog) (unload_dialog dcl_id)

(if (= ddiag 0) (progn (setq Elv nil) ))

(if (= ddiag 1) (progn
(setq ssi (ssget "X")) (if ssi (progn
(command "-view" "o" "t")
(command "_.CHANGE" ssi "" "_P" "_E" Elv "")
(princ (strcat "Object(s) Elevation set to " (rtos Elv 2 3) "\n")) )) ))

(if (= ddiag 2) (progn
(acet-error-init (list (list "cmdecho" 0) nil))
(setq ss (ssget)) (if ss (progn
(command "_.CHANGE" ss "" "_P" "_E" Elv "")
(princ (strcat "Object(s) Elevation set to " (rtos Elv 2 3) "\n"))
(acet-error-restore) )) ))

(if (= ddiag 3) (progn
(command "-view" "o" "f") (c:modz)))

(if (= ddiag 4) (progn
(command "-view" "o" "t") (c:modz)))

)

(defun saveVars()
(setq Elv (atof (get_tile "Elv"))))

(princ)
0 Likes
Message 11 of 11

scot-65
Advisor
Advisor
Try this -

From:
(action_tile "Pick2" "(done_dialog)(setq ddiag 4)")
...
(start_dialog)

To:
(action_tile "Pick2" "(done_dialog 4)")
...
(setq ddiag (start_dialog))

Let's take advantage of done_dialog's integer return to the start_dialog.

🙂

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes