Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Open .dwg/.dwt, save as, close, repeat

11 REPLIES 11
Reply
Message 1 of 12
ryled
505 Views, 11 Replies

Open .dwg/.dwt, save as, close, repeat

First I would like to say I have been looking for some help on this for a couple hours but being brand new to lisps I cannot make sense of most of what I find.

 

What I am trying to do is open a drawing or the template off our network, and save it onto the individual computer and then close the file.  Each computer has a copy of each block and template as a back up and for when they must leave the network but still need to use our AutoCAD tools.  Since I am constantly updating and adding new blocks I would like it to be a single click of a menu item for the users to update all of their blocks and template when I make a change. 

 

What I believe would be the simplist way to do that is to Open the block, Save As onto the correct location on their cpu, then Close the drawing, and then I would repeat this code for every block we used.  This way they would just click the menu macro to load this lisp off the network and run it and it would update all their information needed.

 

(defun:updatedwgs ()
  (command "open""G:\\Stalworth Policy\\Stalworth AutoCAD Station\\Shapes\\Steel - W DBlocks")
  (command "saveas""C:\\Users\\dryle\\Documents\\Stalworth AutoCAD Station\\Shapes\\Steel - W DBlocks")
  (command "close")
  (command "open""........etc.)



(I know this code is not feasible but it is what I am looking to accomplish.)

 

Could someone help me code this once and explain it.  I know I cant use (command "open") because that only works with single document and stops the command, however through my reading I still am completely lost on the "vla" commands and what they do.  Also, would it be best if I run a script to open desired drawing, then run a lisp on that drawing to save it to a certain directory, and then use the script to close it and open the next one?

 

Any help would be extremely appreciated!  Thank you!

 

 

11 REPLIES 11
Message 2 of 12
dgorsman
in reply to: ryled

I'd drop that entirely and use Offline Files.  It will refresh the computers automatically with any new content.

 

If you *must* have dedicated local copies, use a BAT file with calls to XCOPY with some switches to refresh newer content (so you aren't copying the entire contents every single time), or use Robocopy or another transfer method.  They are much, much faster than LISP.

 

If you *must* use LISP, then considering you only need a copy of the file there isn't a need to open it in the first place.  You can use (vl-file-copy ...) to copy the file to another location but it won't overwrite another file.  You'll need to mix in some (vl-file-delete ...) calls to do that.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 3 of 12
ryled
in reply to: dgorsman

I believe to work with Offline Files you need to upload to the cloud, which is something I was asked to avoid.  Is this correct?

 

Also, you are going to have to excuse me but I have no idea what a BAT file is.  I'm assuming this is a batch file, but even so I do not know what that is, and Google is not giving me much help.  Is it something like a batch plot? but instead opens a large amount of files? Perhaps either of these are the more efficient way but they are just foreign to me.

 

 I also want to note speed is not a huge issue here. The majority of the users here only use AutoCAD to check things or for small sketches.  The updates are seldom and most likely would occur prior to them leaving on the weekend, or before moving out to the field.  In which case they would run this update, and even if it took 5-10 minutes that wouldn't be an issue.

 

The thing is, the other people here have larger priorities than working with AutoCAD.  If I was to have them update everytime a block was changed, they would most likely look past this or forget to do it, and if they did do it there is a good chance they accidently ruin folder structure and/or set up to the workstation.  I was hoping to give them a one press button that would update all they needed, with no work on their end and I assumed a lisp was the best route for this.

 

In regards to needing to delete and copy, I was hoping a 'save as' would be  available because that would overwrite the file.  Is this possible?

 

Message 4 of 12
hmsilva
in reply to: ryled

Hi ryled,

 

something like this perhaps

 

(defun c:updatedwgs ( / files path path1)
  (setq path "G:/Stalworth Policy/Stalworth AutoCAD Station/Shapes/Steel - W DBlocks"
	path1 "C:/Users/dryle/Documents/Stalworth AutoCAD Station/Shapes/Steel - W DBlocks/")
  (if (setq files (vl-directory-files path nil 1))
    (foreach file files
      (if (wcmatch (vl-filename-extension file) ".dwg,.dwt")
	(if (findfile (strcat path1 file))
	  (progn
	    (vl-file-delete (strcat path1 file))
	    (vl-file-copy (strcat path "/" file) (strcat path1 file))
	    )
	  (vl-file-copy (strcat path "/" file) (strcat path1 file))
	  )
	)
      )
    )
  (princ)
  )

 

HTH

Henrique

EESignature

Message 5 of 12
dgorsman
in reply to: ryled

Offline Files is a Windows feature - nothing to do with any type of cloud.  We've used it successfully with laptops for some time.  You control when offline content is updated, such as at log-on or log-off or both.

 

BAT files are old-tech, but *extremely* useful to have in the toolkit (not to mention, easier than LISP).  Have a search for XCOPY and "Command Reference Overview" in the Windows help.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 6 of 12
ryled
in reply to: dgorsman

Thank you both for the help here.  Work picked up a bit so I do not have time to focus on this at the moment, but I will return to it shortly and research both your answers and see if they are what I'm looking for.  Just don't want you to think I am ignoring the advice.

 

Thanks again for the help and I will return to it shortly!

Message 7 of 12
ryled
in reply to: hmsilva

dgorsman,

 

I checked into offline files more, they seem useful for what I would like to do, however I would need to rewrite the menu and CUI's to work accordingly, as the files are pathed.  This honestly seems like a lot more work than a lisp may be, for the content I would need to do it to.  Also, I am not very confident I completely understand offline files and I would prefer to stay away from them for the time being.

 

I also checked into XCopy and it seemed like I would need to go to each station and run this to updated the files per computer.  Perhaps I am wrong? but this is something I was hoping to avoid.

 

 

 

Henrique,

I ran the lisp you provided and it updated the local folder just as I would like.  I have a couple questions.  If you were to stop the path after "shapes" would it still update "steel - W DBlocks" and all other folders contained within shapes?

 

Also, would you mind helping me with one more part of this?

 

If you could update this file: G:\Stalworth Policy\Stalworth AutoCAD Station\Template

To this file: C:\Users\dryle\Documents\Stalworth AutoCAD Station\Template

 

Could this be kept in the same code?  Just added as an additional.  This way I could reference the first code, and then the part of the code that shows how to repeat and I can then repeat for each folder I need to.

 

This would be very appreciated!

 

Thank you both for your help.

Message 8 of 12
dgorsman
in reply to: ryled

We don't have any pathing issues when using Offline Files.  They retain the same pathing as if it was on the network, which is the point of the system.  As for the BAT file, yes it does need to be run on each computer (although the BAT file itself can be on the network) but your users will be doing that anyways with LISP; either they can be trained to run it manually or  you can always have it run at log-in or other start-up script so they (and you) don't have to lift a finger.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 9 of 12
ryled
in reply to: dgorsman

I assume you have something such as your template pathed.  When I had searched for where these files are stored I was told " C:\Windows\CSC" which would differ from the network path drive.  Therefore I would assume I'd have a broken path for my blocks, lisps, templates, slides etc. 

 

Running a batch file that updates on log-on seems ideal, however I would still be in the same boat as I do not know how to code.  I will look into this more, lisp was just the most efficient way I thought would have existed. 

 

Message 10 of 12
hmsilva
in reply to: ryled

ryled,

 

the code I've posted, it was just a starting point for you...

 

As dgorsman already stated, using a .bat file will be much faster and easy to copy, replace files and directories, and you can use a .lsp file to run the XCOPY.

Again, only as a starting point

 

(command "_.shell"
	 (strcat
	   "XCopy"
	   " "
	   "\"G:\\Stalworth Policy\\Stalworth AutoCAD Station\\Shapes\""
	   " "
	   "\"C:\\Users/dryle\\Documents\\Stalworth AutoCAD Station\\Shapes\\\""
	   " "
	   "/S/Y/D"
	  )
)

 

HTH

Henrique

 

EESignature

Message 11 of 12
ryled
in reply to: hmsilva

Thanks Henrique,

 

I ran that first code, as is, and it worked perfectly, I didn't think there was anything I had to add to it.  It also ran seemlessly and fast.  I will look more into this XCopy, but perhaps I should wait on this until I become more comfortable with coding, as I am going to be taking classes next semester.

 

Thank you guys for your help.

Message 12 of 12
hmsilva
in reply to: ryled


@ryled wrote:

Thanks Henrique,

 

I ran that first code, as is, and it worked perfectly, I didn't think there was anything I had to add to it.  It also ran seemlessly and fast.  I will look more into this XCopy, but perhaps I should wait on this until I become more comfortable with coding, as I am going to be taking classes next semester.

 

Thank you guys for your help.


You're welcome, ryled!

 

Please note that using XCOPY (the second code) will copy files and folders at once after .../Shapes/...

 

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost