CAD Forum - Database of tips, tricks and utilities for AutoCAD, Inventor and other Autodesk products [www.cadforum.cz]
CZ | EN | DE
Login or
registration
  Visitors: 4296
RSS channel - CAD tips RSS tips
RSS discussions

Discussion Discussion forum

 

HelpCAD discussion

 
CAD Forum - Homepage CAD discussion forum - ask any CAD-related questions here, share your CAD knowledge on AutoCAD, Inventor, Revit and other Autodesk software with your peers from all over the world. To start a new topic, choose an appropriate forum.

Please abide by the rules of this forum.

How to post questions: register or login, go to the specific forum and click the NEW TOPIC button.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedWildcard & Lisp

 Post Reply Post Reply
Author
mfkozlow View Drop Down
Groupie
Groupie


Joined: 14.Jul.2014
Location: United States
Using: AutoCAD Electrical 2014
Status: Offline
Points: 25
Direct Link To This Post Topic: Wildcard & Lisp
    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!!
Back to Top
mfkozlow View Drop Down
Groupie
Groupie


Joined: 14.Jul.2014
Location: United States
Using: AutoCAD Electrical 2014
Status: Offline
Points: 25
Direct Link To This Post 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.
Back to Top
Kent Cooper View Drop Down
Senior Member
Senior Member


Joined: 12.Mar.2013
Location: United States
Using: AutoCAD2020, 2023
Status: Offline
Points: 632
Direct Link To This Post 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.
Back to Top
mfkozlow View Drop Down
Groupie
Groupie


Joined: 14.Jul.2014
Location: United States
Using: AutoCAD Electrical 2014
Status: Offline
Points: 25
Direct Link To This Post 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.
Back to Top
mfkozlow View Drop Down
Groupie
Groupie


Joined: 14.Jul.2014
Location: United States
Using: AutoCAD Electrical 2014
Status: Offline
Points: 25
Direct Link To This Post 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.
Back to Top
Kent Cooper View Drop Down
Senior Member
Senior Member


Joined: 12.Mar.2013
Location: United States
Using: AutoCAD2020, 2023
Status: Offline
Points: 632
Direct Link To This Post 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.
Back to Top

Related CAD tips:


 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0,414 seconds.