Display full version of the post: Wildcard & Lisp

mfkozlow
14.08.2014, 17:17
Hello everyone!I need a lisp that will open a file in the directory that the current file (the one that is currently open in ACAD) is in. On top of that, I need to use a wild card.For example, I have a file by the name of XXXXE001.DWG open in ACAD. I need a lisp that will search in the current directory that XXXXE001.DWG is in and open a file that is called XXXXE003.DWG. The "XXXX" will always change, but the ending of the file will not. I need a wildcard that will search for "E003".Any information is valuable! Please share anything you may know. Thank you!!

mfkozlow
15.08.2014, 15:22
I have tried using this lisp:[CODE](defun C:OPEN_003()    (open "*E003.dwg" "r"))    [/CODE]It's a start, but when I run the command it returns nil.


Kent Cooper
15.08.2014, 15:39
Try this variant of a routine I built some time ago.  It was to open a drawing in the current drawing's folder, but with a dialog box to select which one, rather than always a fixed drawing name ending -- I've removed the (getfiled) part and built the file name with your constant ending.
(vl-load-com); [if needed]
(vla-activate  (vla-open    (vla-get-documents      (vlax-get-acad-object)    )    (strcat (getvar 'dwgprefix) (substr (getvar 'dwgname) 1 4) "E003.dwg")  ))
 
That assumes that the XXXXE003.dwg exists, and that the XXXX variable part is always four characters long.  If not, those possibilities can be accounted for.

mfkozlow
15.08.2014, 16:05
It worked like a charm! The XXXX variable is 5 characters long, but I made the necessary changes. Thanks a million.

mfkozlow
15.08.2014, 17:05
Quick question about your code Kent... where would I insert [CODE](command "script" "g:/_001_auto_bom/SCRIPTS/SHT_003_ATT_EXT.scr")[/CODE]if I want it to run on the E003.dwg that was just opened?Right now I use a batch file to open ACAD and drawing E002 and automatically run a script on it. In the script I call the lisp that you provided. After E003 is opened, however, I would like to run another script. Thanks.


Kent Cooper
18.08.2014, 15:31
[QUOTE=mfkozlow]Quick question about your code Kent... where would I insert [CODE](command "script" "g:/_001_auto_bom/SCRIPTS/SHT_003_ATT_EXT.scr")[/CODE]if I want it to run on the E003.dwg that was just opened?....[/QUOTE]
 
 
I don't think you can do it that way, because I don't think a Lisp routine can "survive" moving into a different drawing from the one it was called in.  I believe you need to incorporate that back at the batch-file level somehow, though it's not something I've done, so others would be better qualified to answer that.