Twist on Lee Mac's List Box DCL Routine

Twist on Lee Mac's List Box DCL Routine

Anonymous
Not applicable
1,387 Views
7 Replies
Message 1 of 8

Twist on Lee Mac's List Box DCL Routine

Anonymous
Not applicable

Hello everyone,

Am using the above mentioned routine to open a dialogue box with a list of 5 or 6 drawing files that I constantly need to copy details from.  Routine is awesome.  Only gripe I have is that once the dialogue box is open and I selected from the list, the file I want to open...it opens the delected file but returns focus to the original drawing/file I was working on - not the newly opened drawing from the dialogue box.  A minor thing but hopefully it likewise requires only as minor adjustment to focus or stay on the newly opened drawing tab instead of the original.  Hope that makes sense.  Have included the routine below in case anyone doesn't know what it is and/or save you looking for it.  Thanks for reading everyone.

 

;; List Box - Lee Mac
;; Displays a DCL list box allowing the user to make a selection from the supplied data.
;; msg - [str] Dialog label
;; lst - [lst] List of strings to display
;; bit - [int] 1=allow multiple; 2=return indexes
;; Returns: [lst] List of selected items/indexes, else nil

(defun LM:listbox ( msg lst bit / dch des tmp rtn )
(cond
( (not
(and
(setq tmp (vl-filename-mktemp nil nil ".dcl"))
(setq des (open tmp "w"))
(write-line
(strcat "listbox:dialog{label=\"" msg "\";spacer;:list_box{key=\"list\";multiple_select="
(if (= 1 (logand 1 bit)) "true" "false") ";width=120;height=15;}spacer;ok_cancel;}"
)
des
)
(not (close des))
(< 0 (setq dch (load_dialog tmp)))
(new_dialog "listbox" dch)
)
)
(prompt "\nError Loading List Box Dialog.")
)
( t
(start_list "list")
(foreach itm lst (add_list itm))
(end_list)
(setq rtn (set_tile "list" "0"))
(action_tile "list" "(setq rtn $value)")
(setq rtn
(if (= 1 (start_dialog))
(if (= 2 (logand 2 bit))
(read (strcat "(" rtn ")"))
(mapcar '(lambda ( x ) (nth x lst)) (read (strcat "(" rtn ")")))
)
)
)
)
)
(if (< 0 dch)
(unload_dialog dch)
)
(if (and tmp (setq tmp (findfile tmp)))
(vl-file-delete tmp)
)
rtn
)

(Defun c:Open_DWG_Dialogue (/ aDoc filelist dwglist openfile)
(setq aDocs (vla-get-Documents (vlax-get-acad-object)))
(if
(setq filelist nil
dwglist (findfile "C:\\Users\\Brad\\Dropbox\\AutoCad2020\\Actions and LISP\\Open DWG list dialogue box HOME.txt")
);; < -- location of your drawing list
(progn
(setq openfile (open dwglist "r"))
(while (setq fname (read-line openfile))
(setq filelist (cons fname filelist))
)
(close openfile)
(foreach selectedfile
(LM:listbox "Select Files to open" (reverse filelist) 1)
(if (findfile selectedfile)
(vla-open aDocs selectedfile :vlax-false);; < -- opens the file read-only
)
)
)
)
(princ)
)

0 Likes
Accepted solutions (1)
1,388 Views
7 Replies
Replies (7)
Message 2 of 8

pbejse
Mentor
Mentor

@Anonymous wrote:

Hello everyone,

.. I selected from the list, the file I want to open...it opens the delected file but returns focus to the 


(progn
       (setq openfile (open dwglist "r"))
       (while (setq fname (read-line openfile))
	 (setq  filelist (cons fname filelist))
       )
       (close openfile)
       (foreach	selectedfile
		(LM:listbox "Select Files to open" (reverse filelist) 1)
	 (if (findfile selectedfile)	   
	   (vla-open aDocs selectedfile :vlax-false)
	   ;;(vla-activate 
	   ;; < -- opens the file read-only
	 )
       )
       (vla-activate (vla-item aDocs (1- (vla-get-count aDocs))))
     )

 HTH

0 Likes
Message 3 of 8

Anonymous
Not applicable

Thank youu for the quick reply.

I cant get your addition to have any effect though. I have added your bold blue typed line of code into the specified section of the routine but after selecting which file to open from the list dialogue box, it still just opens that file and then reverts back to the file I was originally working on (the one I called the LISP from).

 

Apologies if I've made some embarrassing mistake here.

0 Likes
Message 4 of 8

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

....it still just opens that file and then reverts back to the file I was originally working on (the one I called the LISP from).


That is weird. [ tested on 2017 and 2022 ]

 

(Defun c:Open_DWG_Dialogue (/ aDoc filelist dwglist openfile)
  (setq aDocs (vla-get-Documents (vlax-get-acad-object)))
  (if
    (setq filelist nil
		dwglist (findfile "C:\\Users\\Brad\\Dropbox\\AutoCad2020\\Actions and LISP\\Open DWG list dialogue box HOME.txt")
		);; < -- location of your drawing list
     (progn
       (setq openfile (open dwglist "r"))
       (while (setq fname (read-line openfile))
	 (setq  filelist (cons fname filelist))
       )
       (close openfile)
       (foreach	selectedfile
		(LM:listbox "Select Files to open" (reverse filelist) 1)
	 (if (findfile selectedfile)	   
	   (vla-open aDocs selectedfile :vlax-false)
	   ;; < -- opens the file read-only
	 )
       )
       (vla-activate (vla-item aDocs (1- (vla-get-count aDocs))))
     )
  )
  (princ)
)

 

HTH

 

0 Likes
Message 5 of 8

Anonymous
Not applicable

Works perfectly now.  Doubt you did anything different in that second version you posted it was my bad, dont know what I did wrong but she works beautifully now.  Thank you so much for your time and nursing me through it.  I really appreciate it.

0 Likes
Message 6 of 8

pbejse
Mentor
Mentor

Glad it helps Mr Black

What's the story behind your username btw---> @Anonymous 

 

0 Likes
Message 7 of 8

Anonymous
Not applicable

@pbejse 

The user name...was obsessed with the movie Reservoir Dogs as a young teen & when it came time to create my very first email address, I wanted "Mr Black@..." You can imagine this was quite popular & already taken so the 911 was added.

Again, thankyou for taking the time to help me out. Big hit in the office with workmates!

0 Likes
Message 8 of 8

pbejse
Mentor
Mentor

@Anonymous wrote:

The user name...was obsessed with the movie Reservoir Dogs as a young teen....


 

Figured as much, that is the first place i look for Mr. Black. Thank you for sharing the story 🙂

 

0 Likes