Jump to content

Search a string on the the file name....


Recommended Posts

Posted

I've search every where but couldn't find a lisp routine so I might as well ask.

 

Let say I have a file named "Mech-Poject1" , "Project1-Mech-Job#" , "Job#-Mech". We don't have a standard on naming files so i'm having problem stripping out the file name and look for the word "MECH" on it.

 

With a lisp routine how can I know if the file name of my current drawing have the word "MECH" on it. I'm planning to modify my "qsave and save" command to do an extra command/lisp routine if I'm in one of those drawings.

 

To make it more clear, if I'm working on my mechanical drawing with the string "MECH" on the file name, it will run a routine that will create a backup file on a super-seeded folder with the date on it and then do a save command as well. If I open a drawing named "Elec-Project" and hit save. It will just save the drawing since I don't have the string "mech" on the file name.

 

Any help is much appreciated.

Posted

You would have to call up the system variable DWGNAME

(getvar "DWGNAME")

the result is a string which you would have to then filter with your string "mech"

Posted

I know how to get the file name with dwgname or vl-filename-base. I just don't know how to check if the string "mech" is on the filename since it can be in the 1st, middle, or last string on the file name. I don't know how to start my code. If it just the first 4 string or the last 4 string on the filename, that I can do but to search on the entire filename, that I can't do. :(

Posted

Instead of using substr, try this:

 

(vl-load-com)
(vl-string-search "MECH" (strcase (getvar 'dwgname)))

 

This will find the string, no matter the position (i.e., beginning, middle, end, etc.).

 

Hope this helps!

Posted

Thanks LibertyOne and RenderMan. That's the one that I been looking for. Been thinking of a complicated code but a simple vlisp function do the job pretty well. I can sleep well for now.

 

Instead of using substr, try this:

 

(vl-load-com)
(vl-string-search "MECH" (strcase (getvar 'dwgname)))

 

This will find the string, no matter the position (i.e., beginning, middle, end, etc.).

 

Hope this helps!

Posted

Sometimes it's the little things we overlook... Glad to help. :)

Posted

You could also use wcmatch

eg.

(wcmatch (strcase (getvar 'dwgname) "*MECH*")

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