View Full Version : Need to create a dialog to insert text
mhannan.100562
2006-06-28, 11:03 PM
I would like to create a menu or dialog box that will insert room names for me at the correct scale. I'm a little new to menu creating in AutoCAD but did write a version of it in another CAD software that doesn't use LISP or VBA for this.
I've been looking for an example menu interface that I then could modify to my liking but have had no luck in finding anything.
I attached an example of what I did in the other software and if anyone could point me in the right direction or help me out with even put of the menu it would be greatly appreciated.
T.Willey
2006-06-28, 11:29 PM
I would like to create a menu or dialog box that will insert room names for me at the correct scale. I'm a little new to menu creating in AutoCAD but did write a version of it in another CAD software that doesn't use LISP or VBA for this.
I've been looking for an example menu interface that I then could modify to my liking but have had no luck in finding anything.
I attached an example of what I did in the other software and if anyone could point me in the right direction or help me out with even put of the menu it would be greatly appreciated.
If those are each buttons, then you could use dcl and lisp, or you could use vba. It is all what you are used to using, or feel comfortable with. I don't know vba, but it is real nice with dialog interfaces, and would most likely work best for your situation.
Hope that helps.
mhannan.100562
2006-06-28, 11:38 PM
If those are each buttons, then you could use dcl and lisp, or you could use vba. It is all what you are used to using, or feel comfortable with. I don't know vba, but it is real nice with dialog interfaces, and would most likely work best for your situation.
Hope that helps.
They are each buttons, and I've made one example using macro in a toolbar button, but I would like to make as many as seen in the picture. I would use any programming code if I could find a good example to start with. I'm just not sure how to start a program like this.
T.Willey
2006-06-28, 11:54 PM
You can go afralisp (http://www.afralisp.net/) to get some help. They have some great tutorials for both lisp/dcl and vba. If I could, I would post a little vba, as I think that way will be better, but I can do a little lisp routine with a dcl for you. You will have to unzip the file, and place both of the files into your support path for acad. Then you can load the lisp (.lsp) file, either through "appload" or you can drag and drop the file from window's exploer into Acad. Then type "ButtonExample" on the command line to execute.
CAB2k
2006-06-29, 12:23 AM
How about a different approach?
T.Willey
2006-06-29, 12:46 AM
Alan always has to one-up me!!
j/k. :wink: Nice one Alan.
CAB2k
2006-06-29, 02:27 AM
That's cause you get there first, if you'd let me be first you could top me. :)
mhannan.100562
2006-06-29, 07:36 PM
How about a different approach?
This would be great, but I'd like to simplify the process a little bit.
I don't want to scare of my other users at the moment.
I'd like to insert mtext with two to four click.
I attached the start of what I'd like to see, but I'm not sure how to get the Living Room button to close the dialog box and run the mtext command.
Thanks for the helps guys, I thought I lost this thread this morning, that why I didn't reply until now.
T.Willey
2006-06-29, 08:04 PM
(action_tile "Test" "(done_dialog 1)")
(action_tile "Test2" "(done_dialog 2)")
(action_tile "Test3" "(done_dialog 3)")
(action_tile "cancel" "(done_dialog 0)")
In the code I posted, this is what controls the buttons pushed. The (done_dialog #) is a way to see what button is pushed. This is what read the buttons pushed.
(setq DiaRtn (start_dialog))
Now that we know what button was pused, we can code the right text string to insert, that is where the (cond.... comes into play.
(cond
((= DiaRtn 1)
(alert "Button \"Test\" was pushed.")
)
((= DiaRtn 2)
(alert "Button \"Test2\" was pushed.")
)
((= DiaRtn 3)
(alert "Button \"Test3\" was pushed.")
)
(t
(alert "\"Cancel\" was pushed.")
)
)
In your code, you don't have anything happening when you push the "LIVING ROOM" button. You only have code for the "accept" button. You could add this to your routine to show that the "LIVING ROOM" button was pushed.
(action_tile "btn1"
"(setq TxtStr \"LIVING ROOM\") (done_dialog)"
)
You can test to make sure that the variable TxtStr has the right value, by typing and exclamation mark in front of it at the command line. ie !TxtStr, it should return "LIVING ROOM".
Hope that helps.
mhannan.100562
2006-06-29, 10:45 PM
Tim,
Thanks for the button example that helped a lot.
My only question now is how do I insert text into the drawing with each button.
I'm attaching the changes I made to my roomnames menu.
T.Willey
2006-06-29, 11:08 PM
How many buttons are you going to have? If you are going to have as many as you did before, you might want to go another route than buttons. Maybe with radio buttons, and an okay/cancel button combo on the bottom.
But to answer you question, the simplest way is to use the text command. The only problem there is if you have a height set up per style because you will be short one prompt. You could use (entmake..... or if you know some ActiveX controls from other programing, you could use those. But for now lets just stick to the command way.
To check to see if the current text has a height designated with it, you will want to do this.
(if
(equal
0.0
(cdr
(assoc
40
(entget
(tblobjname "style" (getvar "textstyle"))
)
)
)
)
(command "_.text" "_j" "_m" (getpoint "\n Middle point of text to be inserted: ") (* (getvar "dimscale") (/ 3 32.0)) 0.0 TxtStr)
(command "_.text" "_j" "_m" (getpoint "\n Middle point of text to be inserted: ") 0.0 TxtStr)
)
Now this assumes that you have a variable named TxtStr, that has a string of text assigned to it. This will happen from your dialog box, so instead of using the alert, we will setq TxtStr to the corrisponding number. One way to do that following the (cond... method, is like this.
(cond
((= DiaRtn 1)
(setq TxtStr "1/2 BATH")
)
((= DiaRtn 2)
(setq TxtStr "2 CAR GARAGE")
)
((= DiaRtn 3)
(setq TxtStr "3 CAR GARAGE")
)
((= DiaRtn 4)
(setq TxtStr "BALCONY")
)
(t
(alert "\"Cancel\" was pushed.")
)
)
You will want to add the first portion of code provided here after this second bit of code. Right now it will error if the cancel button is pushed, so you can test that with another if statement, or you can have the (cond... statement exit the program if the cancel button is pushed, but I figure this is enough for now.
CAB2k
2006-06-30, 01:26 AM
Here is an example of how it could be done, but you will need to build on it.
mhannan.100562
2006-06-30, 02:10 PM
Alan, thank you very much, this helps me out a lot. I'll be able to adjust this to our liking and build off of this for other menus.
CAB2k
2006-06-30, 09:24 PM
Corrected a bug in the previous routine & revised to get the text string from the
DCL file label from each button, thereby reducing the maintenance.
;;;=======================[ RoomNames lsp ]=========================
;;; Author: Charles Alan Butler
;;; Version: 1.0 June 30, 2006
;;; Purpose: Run a DCL with buttons for each text to insert
;;; Insert the text when the user picks it then start the dcl again
;;; Uses current layer & text style
;;; Sub_Routines: -None
;;; Requirements: -None
;;; Returns: -None
;;;
;;; No error routine to catch the user ESCAPE from text placement
;;;=================================================================
(defun c:rn () (c:room_names) (princ)) ; short cut
(defun c:room_names (/ dcl_id diartn txt)
(cond
;; open the dcl file
((not (setq dcl_id (load_dialog "roomnames.dcl")))
(alert "DCL File not found. - Aborting.")
(exit)
)
;; verify the dialog name is in the dcl file
;; here we are using "main_dialog_name"
((not
(new_dialog "roomnames" dcl_id "(setq txt (get_attr $key \"label\"))(done_dialog 1)")
)
(alert "DCL Label not found. - Aborting.")
(exit)
)
)
(while (not (zerop (start_dialog)))
(if txt
(if (= (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))) 0)
(command "._text" "_mc" pause "" 0 txt)
(command "._text" "_mc" pause 0 txt)
)
)
(new_dialog "roomnames" dcl_id "(setq txt (get_attr $key \"label\"))(done_dialog 1)")
(action_tile "done" "(done_dialog 0)")
)
(unload_dialog dcl_id)
(princ)
)
// DCL File - roomnames.dcl
// used by RoomNames.lsp
dcl_settings : default_dcl_settings { audit_level = 3; }
roomnames : dialog { label = "[ Room Names v1.1 ]" ;
:column {
: boxed_row { label = "[ Residential Room Names ]" ;
: column {
: button { key = "r1c1" ; label = "1/2 BATH" ; } // Row 1 Column 1
: button { key = "r2c1" ; label = "2 CAR GARAGE" ; }
}
: column {
: button { key = "r1c2" ; label = "BEDROOM #4" ; }
: button { key = "r2c2" ; label = "BONUS ROOM" ; }
}
: column {
: button { key = "r1c3" ; label = "DINETTE" ; }
: button { key = "r2c3" ; label = "DINING ROOM" ; }
}
: column {
: button { key = "r1c4" ; label = "LAUNDRY" ; }
: button { key = "r2c4" ; label = "LAV" ; }
}
: column {
: button { key = "r1c5" ; label = "OPEN TO ENTRY" ; }
: button { key = "r2c5" ; label = "OPEN TO FOYER" ; }
}
}
//
//==============================================
//
: boxed_row { label = "[ Health Care Room Names ]" ;
: column {
: button { key = "rh1c1" ; label = "ACTIVITY ROOM" ; } // Row 1 Column 1
: button { key = "rh2c1" ; label = "ADMIN OFFICE" ; }
}
: column {
: button { key = "rh1c2" ; label = "CORRIDOR" ; }
: button { key = "rh2c2" ; label = "ELECTRICAL" ; }
}
: column {
: button { key = "rh1c3" ; label = "JANITOR" ; }
: button { key = "rh2c3" ; label = "LIBRARY" ; }
}
: column {
: button { key = "rh1c4" ; label = "MED. STORAGE" ; }
: button { key = "rh2c4" ; label = "MEN" ; }
}
: column {
: button { key = "rh1c5" ; label = "SOILED UTILITY"; }
: button { key = "rh2c5" ; label = "STAIR" ; }
}
}
// spacer_1;
: button { key = "done" ; label = "&DONE" ; is_default = true; is_cancel= true;
fixed_width = true; alignment = centered ;}
}
}// End dialog
mhannan.100562
2006-07-06, 04:40 PM
Thanks again for everyone's help on this, I was pulling my hair out working on this.
I still wish I could insert the text as Mtext rather than DText, but I found that I can convert the text after inserting it.
I'm attaching a picture of the final menu for everyone to view.
CAB2k
2006-07-06, 04:56 PM
Try this:
(entmake (list
'(0 . "MTEXT")
'(100 . "AcDbEntity")
'(100 . "AcDbMText")
(cons 10 loc) ; insert point
(cons 7 (getvar "TextStyle")) ; Current Style
(cons 40 txt_ht) ; (getvar "TextSize")) ; Current height
(cons 41 width) ; 0 Width = no wrap
(cons 71 align_code) ; 1 = Top Left
(cons 50 rotang) ; rotation angle
)
)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.