Jump to content
Serabis

Opening documents with a wildcard character - script

Recommended Posts

Serabis

I am trying to open up a document in a script routine, and I know the beginning of the file name (and it is unique) but when I add a wildcard character, the script throws an error. For example, say the file name is Project_1-title.dwg, I want to be able to open that file with ' open "Project_1*.dwg" ', or even just Project_1*. Is there any way of doing this, or must you know the entire file name in order to open the document? Thanks in advance.

 

-Serabis

Share this post


Link to post
Share on other sites
BlackBox

If memory serves, Scripts do not support wildcard matching as you're attempting to do... You may need to consider using LISP's Findfile function to test for a valid file path instead.

Share this post


Link to post
Share on other sites
ReMark

I'm pretty sure one can use wildcards in a script. Here is an example I found elsewhere.

 

LAYER C 51

*|A-*

C 2

*|A-AREA-IDEN

F

*|A-*

T

*|A-AREA-IDEN*,*|A-DOOR-*,*|A-WALL-FULL*,etc.

 

The following note was included too.

 

Wildcards can be asterisks or question marks. Asterisks match multiple characters and question marks match a single character.

The above script was created using Notepad.

Share this post


Link to post
Share on other sites
MSasu

The wildcards will work on command prompt and/or script if is about selection of named items - as per ReMark's layer edit example. It is expected to don't work when is about to open an existing drawing - since the script is executed one drawing at the time, how will decide AutoCAD which drawing to open and process if there are more than one sharing the said name pattern?

Share this post


Link to post
Share on other sites
Serabis

I am well aware that wildcards work in scripts, I am however speaking about one specific command, and that is open (which I know doesn't accept wildcards in the filename, because I have tested it). Also, AutoCAD doesn't have to guess which one to open, because I know a unique beginning to each file, I simply want to open it without having to know that "Junk" that follows the unique bit. For example lets say I have these files:

 

project1-00_Title.dwg

project1-01_Power_Circuit.dwg

project1-02_Inputs.dwg

project1-03_Outputs.dwg

 

I know that no matter what else is going on in the drawing name, there is going to be a project1-00 with SOMETHING attached to the end, a descriptor of sorts. I want to be able to open that document without having to know the descriptor that is added on the end. There are no repeat files with project1-00 in them.

Share this post


Link to post
Share on other sites
MSasu

I’m afraid you missed my point – I understood you case from the first post; my comments were on the way I presume that the script interpreter should behave to avoid processing a wrong file, hence the lack of support for wildcards for that command.

 

 

However you may try to use an AutoLISP statement to get the name (although, not sure if will work):

 (car (vl-directory-files "C:\\MyProject\\Drawings" "project1-00*.DWG"))

Please notice the doubled backslash.

Share this post


Link to post
Share on other sites
BlackBox

I am well aware that wildcards work in scripts, I am however speaking about one specific command, and that is open (which I know doesn't accept wildcards in the filename, because I have tested it). Also, AutoCAD doesn't have to guess which one to open, because I know a unique beginning to each file, I simply want to open it without having to know that "Junk" that follows the unique bit.

 

 

I want to be able to open that document without having to know the descriptor that is added on the end.

 

I’m afraid you missed my point – I understood you case from the first post; my comments were on the way I presume that the script interpreter should behave to avoid processing a wrong file, hence the lack of support for wildcards for that command.

 

 

However you may try to use an AutoLISP statement to get the name (although, not sure if will work):

 (car (vl-directory-files "C:\\MyProject\\Drawings" "project1-00*.DWG"))

Please notice the doubled backslash.

 

 

 

If only I had suggested that wildcard matching wouldn't work with the Open Command, and to look to LISP instead. *kicks dirt*

 

 

 

whistling.gif

Edited by BlackBox

Share this post


Link to post
Share on other sites
MSasu

Sorry, I really missed that.

Share this post


Link to post
Share on other sites
Serabis

Thank you all, apparently I was missing some point somewhere, but nonetheless, I just started learning AutoLISP so bear with me: Your supplied code works great! I was trying and failing messing around with the findfile command. Now, does anyone know how I can use this information I am given to open said document? For example can I do something like

 

(setq str (car (vl-directory-files "C:\\MyProject\\Drawings" "project1-00*.DWG")))

(command "_.open" str)

 

well I know that doesn't work becaues I tried it, but is there some code actually works that does what I want?

Share this post


Link to post
Share on other sites
BlackBox
Sorry, I really missed that.

 

No worries, my friend. :beer:

 

Thank you all, apparently I was missing some point somewhere, but nonetheless, I just started learning AutoLISP so bear with me: Your supplied code works great! I was trying and failing messing around with the findfile command. Now, does anyone know how I can use this information I am given to open said document? For example can I do something like

 

(setq str (car (vl-directory-files "C:\\MyProject\\Drawings" "project1-00*.DWG")))

(command "_.open" str)

 

well I know that doesn't work becaues I tried it, but is there some code actually works that does what I want?

 

Unfortunately, there are limitations.

 

One of which being that a Script can execute LISP, but it (the LISP) needs to be on a single line, which makes it harder to maintain.... Please disregard; I am mistaken about this (sorry, I don't do much Scripting, I mostly use LISP & .NET now).

 

For a short snippet such as this, you can simply use:

 

(if (setq dwg (car (vl-directory-files "C:\\MyProject\\Drawings" "project1-00*.DWG"))) (command "._open" dwg) (prompt "\n** Drawing not found ** "))

** Note the return following the last paren (the empty line below the LISP).

 

 

... If your LISP gets much more complex, perhaps it would be simpler to actually have the Script call the LISP (loading if needed prior).

 

HTH

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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