Jump to content

Create Multileader with default text using lisp


Recommended Posts

Posted

Hi. Please help me with this code, i'm stuck with it, the mleader cant get content from filtboxlist (Lee Mac) :

 

(defun c:demo (/ ans)
  (setq ans (LM:filtlistbox "Pick up a contents" 
                    '(
                      "Item1" 
                      "Item2"
                    ) 
                    60 
                    20
          )
  )
  (command "_mleader" pause pause ans)
) ; end_defun


;; Filtered List Box  -  Lee Mac
;; Displays a list box interface from which the user may select one or more items.
;; Includes an edit box filter to enable the user to filter the displayed list of items.
;; msg - [str] List box dialog title
;; lst - [lst] List of strings to display in the list box
;; mtp - [bol] T=Allow multiple items; nil=Single item selection
;; Returns: [lst] List of selected items, else nil

(defun LM:filtlistbox ( msg lst mtp / _addlist dch dcl des rtn sel tmp )

    (defun _addlist ( key lst )
        (start_list key)
        (foreach x lst (add_list x))
        (end_list)
        lst
    )

    (if
        (and
            (setq dcl (vl-filename-mktemp nil nil ".dcl"))
            (setq des (open dcl "w"))
            (write-line
                (strcat
                    "filtlistbox : dialog { label = \"" msg "\"; spacer;"
                    ": list_box { key = \"lst\"; width = 50; fixed_width = true; height = 15; fixed_height = true; allow_accept = true; "
                    "multiple_select = " (if mtp "true" "false") "; }"
                    ": edit_box { key = \"flt\"; width = 50; fixed_width = true; label = \"Filter:\"; }"
                    "spacer; ok_cancel; }"
                )
                des
            )
            (not (close des))
            (< 0 (setq dch (load_dialog dcl)))
            (new_dialog "filtlistbox" dch)
        )
        (progn
            (_addlist "lst" (setq tmp lst))
            (set_tile "lst" (setq rtn "0"))
            (set_tile "flt" "*")
            (action_tile "lst" "(setq rtn $value)")
            (action_tile "flt"
                (vl-prin1-to-string
                   '(progn
                        (setq flt (strcat "*" (strcase $value) "*")
                              sel (mapcar '(lambda ( n ) (nth n tmp)) (read (strcat "(" rtn ")")))
                        )
                        (_addlist "lst" (setq tmp (vl-remove-if-not '(lambda ( x ) (wcmatch (strcase x) flt)) lst)))
                        (set_tile "lst"
                            (setq rtn
                                (vl-string-trim "()"
                                    (vl-princ-to-string
                                        (cond
                                            (   (vl-sort (vl-remove nil (mapcar '(lambda ( x ) (vl-position x tmp)) sel)) '<))
                                            (  '(0)   )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
            (setq rtn
                (if (= 1 (start_dialog))
                    (mapcar '(lambda ( x ) (nth x tmp)) (read (strcat "(" rtn ")")))
                )
            )
        )
    )
    (if (< 0 dch)
        (setq dch (unload_dialog dch))
    )
    (if (and (= 'str (type dcl)) (findfile dcl))
        (vl-file-delete dcl)
    )
    rtn
)

 

Posted

http://www.lee-mac.com/filtlistbox.html

If you read the example in this link carefully, the snippet requires 3 arguments.

 

 

If you want to insert numeric values into item1 and item2,

you will have to create 1 list and then extract it,

or just hard coding it and process it with the (cond) statement.

Posted
2 hours ago, exceed said:

http://www.lee-mac.com/filtlistbox.html

If you read the example in this link carefully, the snippet requires 3 arguments.

 

 

If you want to insert numeric values into item1 and item2,

you will have to create 1 list and then extract it,

or just hard coding it and process it with the (cond) statement.

 

Hi, I’m new to Lisp programming. Could you help me in a more detailed way? 

Posted
(defun c:demo (/ ans)
  (setq ans (LM:filtlistbox "Pick up a contents" 
                    '(
                      "60" 
                      "20"
                    ) 
                    nil
          )
  )
  (command "_mleader" pause pause (car ans))
) ; end_defun

 

I don't know what you want to put in mleader just by looking at the code, but I guessed that you wanted to put 60 or 20, and changed it like this.

Posted
5 minutes ago, exceed said:
(defun c:demo (/ ans)
  (setq ans (LM:filtlistbox "Pick up a contents" 
                    '(
                      "60" 
                      "20"
                    ) 
                    nil
          )
  )
  (command "_mleader" pause pause (car ans))
) ; end_defun

 

I don't know what you want to put in mleader just by looking at the code, but I guessed that you wanted to put 60 or 20, and changed it like this.

 

sorry, I’m going to insert some text into mleader from filtlistbox, for example: “content1” and “content2”....

Posted
(defun c:demo (/ ans)
  (setq ans (LM:filtlistbox "Pick up a contents" 
                    '(
                      "Content1" 
                      "Content2"
                      "Almost heaven"
                      "West Virginia"
                      "Blue Ridge Mountains"
                      "Shenandoah River"
                    ) 
                    nil
          )
  )
  (command "_mleader" pause pause (car ans))
) ; end_defun

It's as simple as just changing the value between " and " to the value you want.

  • Thanks 1
Posted
14 minutes ago, exceed said:
(defun c:demo (/ ans)
  (setq ans (LM:filtlistbox "Pick up a contents" 
                    '(
                      "Content1" 
                      "Content2"
                      "Almost heaven"
                      "West Virginia"
                      "Blue Ridge Mountains"
                      "Shenandoah River"
                    ) 
                    nil
          )
  )
  (command "_mleader" pause pause (car ans))
) ; end_defun

It's as simple as just changing the value between " and " to the value you want.

 

Thanks so much for your help, you save me a lot !!

  • 1 year later...
Posted

I tried this but I'm running into an issue where no matter what I always get prompted the MText Box at the end! any ideas how to by pass this? Is there a global variable that needs to be set or a style setting?

(defun c:demo ( / ml_txt)
  (setq ml_txt "Aluminium")
  (command "_mleader" pause pause ml_txt)
)

 

Posted

after re-setting autocad to factory default it works again ...this means I mus have inadvertently change some AutoCAD global variable that affects the leader creation. (would love to know what it is so I can force it before issuing the command).

Posted

Try using SYSVARMONITOR to track them.

 

I set a lot of mine in my ACADDOC.lsp

Posted

Thanks for the tip... I'll look into it.

I create a common save and reset functions which a call at the beginning and end of every LISP routine and also reset inside error handler and I add to as I need to..

 

; Set Global variable on load. ---------------------------
(setq g_attdia (getvar 'attdia)) 


;Smaple Lisp ---------------------------------------------
(defun c:foo()    
	(c:savesettings)
  
  ;Change Settings as need
  (setvar 'attdia 1)
  
  ;Catch errors and re-set settings.
  (defun *error* ( msg )
    (if (not (member msg '("Function cancelled" "quit / exit abort")))
      (princ (strcat "\nError: " msg))
    )
    (c:resetsettings)
    (princ)
  )  

	;Add new Code Here
	(princ "\nAdd my code here")
	
	(c:resetsettings)
  (princ)
)

;Store inital settings ------------------------------------
(defun c:savesettings ()
  (princ "\nSave settings..")
	(setq g_attdia (getvar 'attdia))
	(princ)
)

;Restore settings ----------------------------------------
(defun c:resetsettings ()
  (princ "\n...Reset settings")
	(Setvar "ATTDIA"  g_attdia)
	(princ)
)

 

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...