File open dialogue box with selected list of files

File open dialogue box with selected list of files

Anonymous
Not applicable
4,249 Views
20 Replies
Message 1 of 21

File open dialogue box with selected list of files

Anonymous
Not applicable

Hi guys, hope everyone is well.

 

I feel like this is so common it has already been addressed but I've searched and searched with no joy.  So, apologies in advance if I missed something glaringly obvious.

 

What I would like is a lisp routine that would produce a dialogue box, populated with a list of half a dozen drawings/files that I could then click on to instantly open.

 

I open and begin all my jobs from the same template file but then I need to constantly refer/open other drawings to refer to and to copy blocks and details from etc.  My boss won't change anything that might make our lives easier so these DWGs that contain the needed blocks and details etc are scatterred everywhere.  Some on local drives but buried deep inside 47 different subfolders while some are in network locations and servers etc.  Obviously I can make links or favourites to all of them within windows explorer but as I will do this task at least a dozen times on each job, I would love to keep it all in AutoCad.

 

I have found and tried to read up on some works by Lee Mac such as 'List Box' and 'Get Files Dialogue' but its turned out to be well above my paygrade.

 

I just want to conjure up a dialogue box that maybe refers to a text file (I'm just guessing here) or some pre-saved location that contains a list of drawings to choose from.  Then I could add the drawings/files I want to appear in the dialogue box.

 

Again, I'm sorry if this has been addressed elsewhere and I apologise I'm now dumping my lisp coding ineptitude on you guys.

 

Hopefully this isn't too difficult for someone here. Thanks for reading.

 

Brad 

0 Likes
Accepted solutions (2)
4,250 Views
20 Replies
Replies (20)
Message 2 of 21

Sea-Haven
Mentor
Mentor

Using lee-mac list box some examples.

Replace item with your filenames 

(setq ans (nth 0 (LM:listbox "Select an Item" '("Item 1" "Item 2" "Item 3" "Item 4" "Item 5") 1)))
for 1 pick
(setq ans (LM:listbox "Select an Item" '("Item 1" "Item 2" "Item 3" "Item 4" "Item 5") 1)))
will get multiple picks in list ans


 Please note use \\ double backslash in each directory name D:\\acadtemp\\myfiles\\dwg1

 

You can make a text file and read it in making a list if stuck how to ask, very easy. or else just hard code to a directory then no need for getfile.

 

(setq ans (LM:listbox "Select an Item" filelist) 1))

(setq fo (open "D:\\myfiles\\mydwglist.txt "r"))
(setq filelist '())
(while (setq fname (read-line fo))
(setq filelist (cons fname filelist))
)
(close fo)

 

For a server if not mapped as a drive you will need 4 \\\\ at start implies its a server name. \\\\abcd-enterprises\\dwgs

0 Likes
Message 3 of 21

Anonymous
Not applicable

I appreciate the quick respose and you showing me those examples.  Maybe when I said "I had looked at Lee Macs routine/s and they were above my paygrade", I didn't convey just exactly how much I didn't understand of it.

I assume the snippets you've provided are to be insterted into the "ListBox.lsp" file..?  I have no idea where to do this or even how to execute his lisp as, typing "listbox" after loading the lisp into AutoCad does nothing.  I've loaded many lisp routines into AutoCad before and they have always worked fine by typing the defun: command.  This one is obviously different but I have no idea why.

Maybe I'll just stick with creating lists of windows explorer shortcuts and favourites etc.

Thanks very much for trying to help though, I appreciate your time.

0 Likes
Message 4 of 21

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

... but buried deep inside 47 different subfolders while some are in network locations and servers etc...


 

The highlighted item is what you need to replace on the attached lisp file.

The program will also open the files as read-only

The fomat for the txt file should include the whole path and file extension

D:\ServerFolder\TheFile.dwg
D:\ServerFolder\BLock\Thetest.dwg
D:\ServerFolder\Templates\Thetest.dwt
(Defun c:InstantlyOpen (/ aDoc filelist dwglist openfile)
(setq aDocs (vla-get-Documents (vlax-get-acad-object)))
  (if
    (setq filelist nil
	  dwglist  (findfile "C:\\temp\\mydwglist.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" filelist 1)
	 (if (findfile selectedfile)
	 	(vla-open aDocs selectedfile :vlax-true);; < -- opens the file read-only 
	   )
       )
     )
  )
  (princ)
)

LM:listbox is included upon loading of InstantlyOpen.lsp 

 

HTH

 

0 Likes
Message 5 of 21

Kent1Cooper
Consultant
Consultant

[Nothing in Reply to the quoted Message?]  [corrected]

Kent Cooper, AIA
0 Likes
Message 6 of 21

pbejse
Mentor
Mentor

@Kent1Cooper wrote:

[Nothing in Reply to the quoted Message?]


 

Haha, you're right. Sometimes my fingers have a mind of its own 😀

Thanks Kent, edited and posted

 

EDIT 2.0: and then right after that i forgot the attachment 😂

 

 

0 Likes
Message 7 of 21

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... I need to constantly refer/open other drawings to refer to and to copy blocks and details from etc. .... 


That sounds like a job for the Design Center [DC or ADC shortcut to ADCENTER command], with which you can bring Blocks [and Layers, and Dimension and Text Styles, and so on] into the current drawing from another drawing without actually opening that other drawing.  [If there are drawn elements that are not in Blocks that you want to pull, for those you would need to open the drawing.]

 

If you can bring yourself to put all those other source drawings in one folder, you can call up the Design Center already opened to that folder, where there will be the list of drawings to choose from and enter to pull things out of.  You can even have it open up in a particular drawing and already in the Blocks list, with this kind of thing:

 

  (command "adcenter" "adcnavigate" "X:/Your/File/Path/YourDrawing.dwg/Blocks")

Kent Cooper, AIA
0 Likes
Message 8 of 21

pbejse
Mentor
Mentor

@Kent1Cooper wrote:

.... which you can bring Blocks [and Layers, and Dimension and Text Styles, and so on] into the current drawing from another drawing without actually opening that other drawing...

 

 (command "adcenter" "adcnavigate" "X:/Your/File/Path/YourDrawing.dwg/Blocks")


 

Ahh that's a good idea, and once you setup the files then you can develop a Tool palette for it. Viola! instant access

 

 

 

 

 

0 Likes
Message 9 of 21

Anonymous
Not applicable

Hi Kent,

 

Thats what I've currently been using as a work-around...have favourites and shortcuts areas all set up.

Your solution would be ideal but as I say, the organisation regarding file management where I work is outdated and a shambles.  The "blocks" from other sheets I seed I need to constantly refer to and use, are not really blocks at all; we just half 6-8 DWG files scattered all over the shop that contain within them all the individual details we use; not done as blocks but just regular linework drawings within the sheet.  So I need to open these files and copy-paste the parts I need to steal. I've mislead you there sorry.

I do always value your input here on these forums though so thank you.

Brad

0 Likes
Message 10 of 21

Sea-Haven
Mentor
Mentor

For us that dont use tool palette Lee-mac Steal.lsp works very well. To many years using image in menu files.

0 Likes
Message 11 of 21

Anonymous
Not applicable

@pbejse 

Nailed it!  Thank you so very much for this and breaking it down into something I can understand ( can only imagine your frustration level).  Permission to show this off to the other workers (who currently believe LISP and any form of automation is Whitchcraft) and leave out the part where I had no clue and relied heavily on you to do this for me..?😉

Seriously though, if the office implements it, full credit and recognition will by duly identified and made known.

Thanks again,  it may not be massive but its just shy of 'game changing' from my point of view.

0 Likes
Message 12 of 21

Anonymous
Not applicable

Very sorry.  Quick question/s:

 

1.  The order I enter the files into the .TXT doc is not the order they appear in the dialogue box.  It also appears to not be doing them in alphabetical order.  Is there any way to ensure what order my included files will appear or list in the dialogue box.

 

2.  May I ask where in the LISP I can alter the dimensions of the dialogue box, so that I may see the full name and directory info for each file listed as I noticed it cannot simply be stretched by the corners.

EDIT: - Have solved question 2 so its just the ordering issue I have.

 

SOrry to drag you back in where you were almost rid of this.

0 Likes
Message 13 of 21

pbejse
Mentor
Mentor

@Anonymous wrote:

Very sorry.  Quick question/s:

 

1.  The order I enter the files into the .TXT doc is not the order they appear in the dialogue box.  It also appears to not be doing them in alphabetical order.  Is there any way to ensure what order my included files will appear or list in the dialogue box.


 

The list is in reverse order right?

On the InstantlyOpen.lsp file Change this

 

(LM:listbox "Select Files to open" filelist 1)

 

to

 

(LM:listbox "Select Files to open" (reverse filelist) 1)

 

 


@Anonymous wrote:

SOrry to drag you back in where you were almost rid of this.


From what movie.png

0 Likes
Message 14 of 21

Sea-Haven
Mentor
Mentor

Copy, paste to excel sort the filenames.

Copy, paste back into file will be alphabetical. 

0 Likes
Message 15 of 21

Anonymous
Not applicable

This routine has been very well received in the office; its the very first time, that usage of LISP has been deemed worthy of adopting so please put that little feather in your cap with much gratitude.

 

There is one little hiccup though; the files opened by the lisp, open as read only.  So any changes to those detail sheets while they're open/in use, require a 'save-as', then the original version closed and deleted before giving the newly created (the 'save-as') file, the original file name so that it matches the one being referred to in the accompanying text file.

 

Is there any way we could change this behaviour so changes could be saved instead of going the long way around as described above?

 

Thanks everyone.

0 Likes
Message 16 of 21

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

There is one little hiccup though; the files opened by the lisp, open as read only. ..

Hmmmn.. What do we have here...

(vla-open aDocs selectedfile :vlax-true);; < -- opens the file read-only 

I wonder what will happen if i change the :vlax-true to ;vlax -false.....  🤔

 

 

0 Likes
Message 17 of 21

Anonymous
Not applicable

Apologies.  My knowledge of LISP is so slender I didn't even look at it myself.  Deserving of the mocking but I thank you anyway.

0 Likes
Message 18 of 21

pbejse
Mentor
Mentor

@Anonymous wrote:

Apologies.  My knowledge of LISP is so slender I didn't even look at it myself.  Deserving of the mocking but I thank you anyway.


Apologies if it came across like that, there's no mocking here on this forum. 😄

 

If you have been around here long, you will get to know that we let the OP try and figure it out for themeselves and we just drop hints here and there. Teaching how to fish kind a thing.

 

Did it work for you? Anyhoo. I attached the modified lsp. file, keep in mind that there will still be users ending up with read-only version of the file.

 

Tell us how it goes OK?

 

 

 

 

 

 

 

0 Likes
Message 19 of 21

Anonymous
Not applicable

I realised it was a good natured poke.  It served as a good reminder that although my lisp ability can't hold a candle to you guys, I have actually learned somethings during my studying.  You forget that along the way, if you spend too long comparing.  I should have had a bo beep inside the lisp file instead of automatically throwing my hands in the air and deciding it wasn't something I could do.

 

It works beautifully. Tremendous time saver.  Previously, I would just need to have all these sheets/dwg's open whilst working on the main file.  Whilst I have a great deal under the hood in my PC, there were times it would complain and things would be slightly delayed. Having this routine and easy access to drawings I refer to all the time means I don't need to have 12 tabs open at  once and everything runs nicely.  As I say, I'd been showing the other guys in the office how lisp could be employed to automate a lot of the mundane tasks but they were never convinced.  Showed them this one though and they immediately asked for it to be loaded on their machines!  Super handy.

 

Thank you very much for taking the time to work this out with (for) me.  Genuinely appreciated.

0 Likes
Message 20 of 21

pbejse
Mentor
Mentor

Good for you @Anonymous  Appreciate the kind words.

We are happy to help.

 

 

0 Likes