Connect Autolisp file to my Dialog box file

Connect Autolisp file to my Dialog box file

christian_paulsen98V29
Enthusiast Enthusiast
770 Views
11 Replies
Message 1 of 12

Connect Autolisp file to my Dialog box file

christian_paulsen98V29
Enthusiast
Enthusiast

Hello! I recently just created a dialog box which i think I've got looking almost exactly how i want it to look.

 

Now i am trying to create the Autolisp file that calls forward the dialog box, and then performs actions based off of the users input.

At first the dialog box was popping up, and you could check/uncheck the boxes and also type in the text field. Now when i try to open the dialog box it pops up but then instantly closes. I'm getting the error on my command line "; error: too many arguments".

So i guess the first part of fixing this would be to stop it from instantly closing.

The second part is making it functional. The purpose of this dialog box is to rename my current layout based off of which options are selected in the dialog window. Ideally you would check the boxes, then based off of what is checked it would then get passed down to the text field, then when you click ok whatever is in the text field would then get passed to your current tab name.

I will post both the dcl code and lisp code below. Please give me any advice you may have, all input is appreciated.

layoutrename : dialog {
 label = "Edit Layout Title" ;

	: row {

		:boxed_row {
		label = "Select Layout Options" ;

			: toggle {
			key = "tb1" ;
			label = "Plan" ;
			value = "1" ;
			}

			: toggle {
			key = "tb2" ;
			label = "Elevations" ;
			}

			: toggle {
			key = "tb3" ;
			label = "Sections" ;
			}

			: toggle {
			key = "tb4" ;
			label = "Details" ;
			}

			: toggle {
			key = "tb5" ;
			label = "Isometrics" ;
			}

			: toggle {
			key = "tb6" ;
			label = "Fabrications" ;
			}

		}

	}

	: row {

		: edit_box {
		key = "eb1" ;
		label = "Layout Name :" ;
		edit_width = 60 ;
		}

	}

	ok_cancel ;
					
}

 

(defun C:layoutrename ()	

	(setq layoutname "test")

	(setq dclfilename "layoutrename.dcl")
	(setq dialogname "layoutrename")

	(setq dcl_id (load_dialog dclfilename))
	(new_dialog dialogname dcl_id)

	(action_tile "tb1" "(setq layoutname (strcat layoutname "Plan"))")
	(action_tile "tb2" "(setq layoutname (strcat layoutname "Elevations"))")
	(action_tile "tb3" "(setq layoutname (strcat layoutname "Sections"))")
	(action_tile "tb4" "(setq layoutname (strcat layoutname "Details"))")
	(action_tile "tb5" "(setq layoutname (strcat layoutname "Isometrics"))")
	(action_tile "tb6" "(setq layoutname (strcat layoutname "Fabrications"))")

	(set_tile "eb1" layoutname)

	(action_tile
	"cancel"
	"(done_dialog)"
	)

	(action_tile
	"accept"
	"(command "-layout" "r" layoutname "")"
	"(done_dialog)"
	)

	(start_dialog)
	(unload_dialog dcl_id)

)

 

0 Likes
771 Views
11 Replies
Replies (11)
Message 2 of 12

paullimapa
Mentor
Mentor

These are the modifications that I made to both your DCL and LSP:

1. DCL - instead of toggle buttons you should use radio buttons so that only the current choice is selected. I commented out your lines of code and entered new ones:

 

 

//		:boxed_row {
		:boxed_radio_row {
		label = "Select Layout Options" ;

//			: toggle {
      : radio_button {
			key = "tb1" ;
			label = "Plan" ;
			value = "1" ;
			}

//			: toggle {
      : radio_button {
			key = "tb2" ;
			label = "Elevations" ;
			}

//			: toggle {
      : radio_button {
			key = "tb3" ;
			label = "Sections" ;
			}

//			: toggle {
      : radio_button {
			key = "tb4" ;
			label = "Details" ;
			}

//			: toggle {
      : radio_button {
			key = "tb5" ;
			label = "Isometrics" ;
			}

//			: toggle {
      : radio_button {
			key = "tb6" ;
			label = "Fabrications" ;
			}

		}

 

 

2. LSP - assuming your dcl file is located under one of the Options>Files>Support File Search Paths, then the following changes should be made:

a. Localize variables - this can be done once you've finished troubleshooting the code replacing the following line:

 

 

(defun C:layoutrename () 

 

 

With this:

 

 

(defun C:layoutrename (/ dialogname dclfilename layoutname layoutname stid) ; localize variables 

 

 

b. Add this line to check if currently in Model tab which cannot be renamed then switch to layout tab:

 

 

  ; if in Model switch to layout since model tab cannot be renamed
  (if(not(zerop(getvar"tilemode")))(setvar"tilemode"0))

 

 

c: Quotes listed in action_tile statements need to be prefixed using backslash as the escape key so: " need to be: \"

d: edit_box key "eb1" should reflect radio_button selection 

e: instead of replacing the layoutname variable I added a new one layoutnamenew so layoutname string can be preserved

So replace the following lines of code:

 

 

	(action_tile "tb1" "(setq layoutname (strcat layoutname "Plan"))")
	(action_tile "tb2" "(setq layoutname (strcat layoutname "Elevations"))")
	(action_tile "tb3" "(setq layoutname (strcat layoutname "Sections"))")
	(action_tile "tb4" "(setq layoutname (strcat layoutname "Details"))")
	(action_tile "tb5" "(setq layoutname (strcat layoutname "Isometrics"))")
	(action_tile "tb6" "(setq layoutname (strcat layoutname "Fabrications"))")
  
  (set_tile "eb1" layoutname)

 

 

With these:

 

 

  (set_tile "eb1" (setq layoutnamenew (strcat layoutname "Plan"))) ; initial setting
  
	(action_tile "tb1" "(set_tile \"eb1\" (setq layoutnamenew (strcat layoutname \"Plan\")))")
	(action_tile "tb2" "(set_tile \"eb1\" (setq layoutnamenew (strcat layoutname \"Elevations\")))")
	(action_tile "tb3" "(set_tile \"eb1\" (setq layoutnamenew (strcat layoutname \"Sections\")))")
	(action_tile "tb4" "(set_tile \"eb1\" (setq layoutnamenew (strcat layoutname \"Details\")))")
	(action_tile "tb5" "(set_tile \"eb1\" (setq layoutnamenew (strcat layoutname \"Isometrics\")))")
	(action_tile "tb6" "(set_tile \"eb1\" (setq layoutnamenew (strcat layoutname \"Fabrications\")))")

 

 

f. The dialog needs to be closed first and then you can perform a layout rename 

g. Clicking the cancel key vs accept should return different values

h. Then based on if dialog is accepted then run the layout rename command

So change the following lines of code:

 

 

	(action_tile
	"cancel"
	"(done_dialog)"
	)

	(action_tile
	"accept"
	"(command "-layout" "r" layoutname "")"
	"(done_dialog)"
	)

	(start_dialog)

	(unload_dialog dcl_id)

 

 

To these:

 

 

	(action_tile
	"cancel"
	"(done_dialog 0)"
	)

	(action_tile
	"accept"
	"(done_dialog 1)"
	)

	(setq stid (start_dialog)) ; save return dialog status per clicked done_dialog value
  
	(unload_dialog dcl_id)
  
  (if (= stid 1) ; chk if ok clicked
   (if(not(member layoutnamenew (layoutlist))) ; chk if layoutname exists
	  (command "_.-Layout" "_R" (getvar "ctab") layoutnamenew) ; then rename current layout
    (alert (strcat "Current Layout Name: \n\t[" (getvar "ctab") "]\nCannot be Renamed to an Existing Layout Name: \n\t[" layoutnamenew "]")) ; else show
   )
  )
 (princ) ; clean exit

 

paullimapa_0-1728507979550.png

 

 

 


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

christian_paulsen98V29
Enthusiast
Enthusiast

Im on my phone right now so i cant plug in the lisp and test it.

 

However i can tell you that the radio buttons will not work. Its not always just one of those options. Sometimes it is a combination of multiple options. For example "Sections Elevations Isometrics".

I was going to change the code to add things in with an "&" sign before them like "(strcat layoutname "& Elevations")" or "(strcat layoutname "& Isometrics")". The only issue with that is that if it is the first item in the list then the "&" sign is not necessary.

0 Likes
Message 4 of 12

paullimapa
Mentor
Mentor

In that case I've changed the dcl file back to toggle buttons and modified the lisp.

The code now includes a subfunction set_eb1 that's used by the action statements by all the toggle buttons.

Depending on if the toggle button is checked then add the selected name if not already done vs unchecked then  remove the selected name. Then it'll define an updated layoutname for the rename.

Give this a shot.

paullimapa_1-1728524701600.png

 

 

 


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

MrJSmith
Advocate
Advocate

@paullimapa You really went all out!

 

@christian_paulsen98V29 It is better to save your variables at the done_dialog phase and then run commands afterwards based on the variables (as paullimapa did). My only other suggestion would be to write the DCL in LISP, that way you don't have to manage two separate files for your program.

0 Likes
Message 6 of 12

christian_paulsen98V29
Enthusiast
Enthusiast

How do you write the dcl in lisp? This was my first attempt at anything to do with dialog boxes.

0 Likes
Message 7 of 12

paullimapa
Mentor
Mentor

Read all about it in my Jan article on Dialog Fun Facts:

AUGIWORLD by AUGI, Inc. - Issuu

 

You can also load and run the attached (DCL2LSP) function and select a dcl file & it'll convert it into lisp code for you to load with your lsp program.


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

john.uhden
Mentor
Mentor

@christian_paulsen98V29 ,

One thing I see is in your action_tiles.

Every thing in DCL requires a string, so when you want to add a string to an action_tile action you must "Esc" the quoted string by adding a backslash before each of its quotes...

EDITED

Not:  

 

(action_tile "tb1" "(setq layoutname (strcat layoutname "Plan"))")

 

But:  

 

(action_tile "tb1" "(setq layoutname (strcat layoutname \"Plan\"))")
                                                        ^     ^
                                                        |     |

 

 

John F. Uhden

0 Likes
Message 9 of 12

christian_paulsen98V29
Enthusiast
Enthusiast

I was wondering why there was so many quotations. I knew there was some kind of rule but i couldnt figure out the exact one.

0 Likes
Message 10 of 12

john.uhden
Mentor
Mentor

@christian_paulsen98V29 ,

Take look again.  I edited my response to correct an error.

John F. Uhden

0 Likes
Message 11 of 12

Sea-Haven
Mentor
Mentor

Have a look at this for convert a dcl to lsp. Compliments to RLX.

 

0 Likes
Message 12 of 12

MrJSmith
Advocate
Advocate
0 Likes