Print Page | Close Window

Wildcard & Lisp

Printed From: CAD Forum
Category: EN
Forum Name: AutoCAD
Forum Description: Discussion about AutoCAD and AutoCAD LT, viewers, DWG and DWF formats, Design Review, AutoCAD 360, add-ons
URL: https://www.cadforum.cz/forum_en/forum_posts.asp?TID=10624
Printed Date: 25.May.2026 at 00:31


Topic: Wildcard & Lisp
Posted By: mfkozlow
Subject: Wildcard & Lisp
Date Posted: 14.Aug.2014 at 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!!



Replies:
Posted By: mfkozlow
Date Posted: 15.Aug.2014 at 15:22
I have tried using this lisp:


(defun C:OPEN_003()
    (open "*E003.dwg" "r")
)   


It's a start, but when I run the command it returns nil.


Posted By: Kent Cooper
Date Posted: 15.Aug.2014 at 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.


Posted By: mfkozlow
Date Posted: 15.Aug.2014 at 16:05
It worked like a charm! The XXXX variable is 5 characters long, but I made the necessary changes. Thanks a million.


Posted By: mfkozlow
Date Posted: 15.Aug.2014 at 17:05
Quick question about your code Kent... where would I insert


(command "script" "g:/_001_auto_bom/SCRIPTS/SHT_003_ATT_EXT.scr")


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.


Posted By: Kent Cooper
Date Posted: 18.Aug.2014 at 15:31
Originally posted by mfkozlow mfkozlow wrote:

Quick question about your code Kent... where would I insert


(command "script" "g:/_001_auto_bom/SCRIPTS/SHT_003_ATT_EXT.scr")


if I want it to run on the E003.dwg that was just opened?
....
 
 
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.



Print Page | Close Window