Jump to content

Using an Edit MText Dialog Box for user input


rcb007

Recommended Posts

I am curious on how I can modify the code; where the user could enter the value in an Edit MText Box rather than on the command line.

 

  (initget 6)
  ;;(setq n (getint "\nHow many more needed: ") ;;<<<<-------- Is it possible to use this (lisped (getvar 'ctab)) for a user to enter a value?
  (setq n (lisped (getint ""))
  ;;(lisped (getvar 'ctab)) ;;<<------- Example Edit MText Dialog Box

        i (+ 1 namei n))

 

Thanks for any help on this!

Capture.JPG

Edited by rcb007
Link to comment
Share on other sites

22 hours ago, mhupp said:

 

Sort of beaten to it, http://www.lee-mac.com/editbox.html, but doesn't have the 'Full editor' option.

 

For the OP, this pop up box approach I think loses the ability to type multiple lines of text won't it? Can't put a new line character in the text box?

Link to comment
Share on other sites

Thanks for the pointer. I have the following full code, but I keep getting an error when running it.

 

; error: bad argument type: fixnump: nil

 

Not quite sure where the error could be within the dialog. It works with the (getint).

 


  (initget 6)

--------------------------------------------------
  ;;(setq n (getint "\nHow many more needed: ") ;;currently works within command line<<<<-------- Is it possible to use this in dialog box?
-------------------------------------------------
  (if (not AH:getvalsm)(load "Multi Getvals.lsp")) ;;BigAl's Dialog Box
  ;(setq n (AH:getvalsm (list "Enter" "How Many More? " 5 4 "100")))

  ;(setq n (atof (nth 0 (AH:getvalsm (list "Enter" "How Many More?" 10 8 (rtos n 2 3 ))))))
----------------------------------------------------

 

(defun c:DeleteAllButCurrentTab nil
 (vl-load-com)
 (vlax-for l
   (vla-get-Layouts
     (vla-get-ActiveDocument
       (vlax-get-acad-object)
     ))
   (if
     (not
       (vl-position (strcase (vla-get-name l))
         (cons
           (strcase (getvar 'CTAB)) '("MODEL")
         )
       )
     )
     (vla-delete l)
   ))
 (princ))
         
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:CopyLayouts ( / *error* oCMDECHO ctab name namer namei nname n i x ans n)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'CMDECHO oCMDECHO)
    (princ))
  
  (setq oCMDECHO (getvar 'CMDECHO))
  (setvar 'CMDECHO 0)
  (setq cur (getvar 'CTAB))
  (c:DeleteAllButCurrentTab)
  (setq ctab (getvar "ctab"))
  (setq name (getvar "ctab"))
  (if (= name "") (setq name ctab))
  (setq n (1+ (strlen name))
        namei "")
  
  (while (and (> n 1)
              (wcmatch (setq x (substr name (setq n (1- n)) 1)) "#"))
    (setq namei (strcat x namei)))
  
  (setq namer (substr name 1 (- (strlen name) (strlen namei)))
        namei (atoi namei))
  
  (initget 6)

--------------------------------------------------
  ;;(setq n (getint "\nHow many more needed: ") ;;currently works within command line<<<<-------- Is it possible to use this in dialog box?
-------------------------------------------------
  (if (not AH:getvalsm)(load "Multi Getvals.lsp")) ;;BigAl's Dialog Box
  ;(setq n (AH:getvalsm (list "Enter" "How Many More? " 5 4 "100")))

  ;(setq n (atof (nth 0 (AH:getvalsm (list "Enter" "How Many More?" 10 8 (rtos n 2 3 ))))))
----------------------------------------------------

        i (+ 1 namei n))
  
  (repeat n
    (setq nname (strcat namer (itoa (setq i (1- i)))))
    (if (member nname (layoutlist))
      (princ (strcat "\nLayout '" nname " ' already exists."))
      (command "_.LAYOUT" "_Copy" name (strcat namer "a")
               "_.LAYOUT" "_Rename" (strcat namer "a") nname)))

  (foreach name	(layoutlist)
    (setvar 'ctab name)
    (setq n (cdr (assoc -1 (dictsearch (namedobjdict) "acad_layout"))))
    (command "-layer"
	     "Freeze"
	     "*"
	     "Thaw"
	     (strcat "*Area" (itoa (cdr (assoc 71 (dictsearch n name)))))
	     ""
    )
    (command "_mspace")
    (command "zoom" "extents")
    (command "ZOOM" "Scale" "1/100xp")
    (command "_pspace")
  )
(setvar 'CMDECHO oCMDECHO)
(setvar 'CTAB cur)
(princ))

 

Link to comment
Share on other sites

fixnump suggests that something in the code is expecting a number but is getting given something else, a string, list or something.

 

BigAl will correct me shortly I am sure, but I think the output from his getvalsm routine is a list and each variable in the list is a string. In this case it is a list of length 1.

 

Putting this after you call his routine:

 

(setq n (atoi (car n)))

 

should make n into a single number and able to be used from then on

Link to comment
Share on other sites

When you use a dcl edit box it only accepts or out puts a string even though you will seem to put in a number like 123 the dcl returns "123" as a string , so Steven P is correct need to convert to a number atof for real or atoi for integer. In the multi getvals you can save a variable say num = 123, then in the multi call just convert it to a string and it will be displayed. Please note that the Multi getvals returns a list of the values, so as you only have one then use the (car to get the 1st value in the list.

 

(if (not AH:getvalsm)(load "Multi Getvals.lsp")) ;;BigAl's Dialog Box
(if (= n nil)(setq n 100))
(setq n (atof (car (AH:getvalsm (list "Enter" "How Many More? " 5 4 (rtos n 2 0))))))

 

image.png.3afea4a66985c0f4891ce13b185d436a.png

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

What is posted does make sense. However, when I place the updated code, it still seems to be getting that error. The error happens immediately once I load the routine.

 

Layouts.lsp") ; error: bad argument type: fixnump: nil

 

I have flipped the atof to the atoi to force the string to become an integer number, but still errors.

 

  (setq namer (substr name 1 (- (strlen name) (strlen namei)))
        namei (atoi namei))
  
  (initget 6)

--------------------------------------------------
  ;(setq n (getint "\nHow many more needed: ") ;;currently works within command line<<<<-------- Is it possible to use this in dialog box?
-------------------------------------------------
(if (not AH:getvalsm)(load "Multi Getvals.lsp")) ;;BigAl's Dialog Box
(if (= n nil)(setq n 100))
(setq n (atof (car (AH:getvalsm (list "Enter" "How Many More? " 5 4 (rtos n 2 0))))))

----------------------------------------------------

        i (+ 1 namei n))
  
  (repeat n
    (setq nname (strcat namer (itoa (setq i (1- i)))))

 

Its weird, the (setq n (getint), is used, and the dialog is commented out, it seems to run from the get go.

 

Link to comment
Share on other sites

The value n is being returned correct, as mentioned earlier use atoi if want an integer, also change 5 4 to bigger numbers if need to enter a large number like 100000.123 use 12 11.

 

If using getvals remove (initget 6) maybe that is the problem.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...