Saturday, March 1, 2008

Streamlining Local File creation

Creating local files for workset-enabled projects can be confusing to users and is quite an unelegant task. A while back I started a thread on the AUGI Revit forums titled "Transparent Local file creation". Thanks to AutoHotKey, I was able to come up with a nice, automated way to help teams working on workshared projects get started every morning in a consistent and easy way.

Since then the thread has had over 2,400 hits and numerous users have contributed to the ideas and solutions of this script. Today I finished version 2 and decided to post about it here. If you like what you see, go to the thread above (or click here) and download the script. I hope it will be as useful to you as it has been to me and a lot of AUGI members. All you need to do is to place a copy of the exe file (compiled version of the AHK script) in the central file folder and have team members create shortcuts to this file on their local drives (the Desktop is ideal). Then just double click the shortcut and wait until it's finished doing it's magic!

-------------------------------------------------------------------------------------------------

The script will do the following:


1) Check if the Central file exists. Filename is assumed to be XXXXX #VV central.rvt, where XXXXX can be anything of any length, # is the discipline (A, S or MEP, where the 3 letters in MEP can be expressed in any order) and VV is the version number (since we’re on 2008, we would use 08, but the script doesn’t care about this and you could in theory type anything). The spaces shown in the filename can be any character you want, including a space. So 123456789 Project_A08-Central.rvt would work the same as 123456789-Project-A08_Central.rvt (you get the idea).

2) If no Central is found or more than one exists, dialog warnings will be issued. The Central file folder will open in Explorer so you can investigate the problem immediately.

3) The discipline is evaluated (from # above) and if the input is not as expected, you will be warned and the script will terminate. The Central file folder is opened in Explorer so you can investigate the problem immediately.

4) Local files will be created in C:\Revit Local Files\XXXXX #VV\ so if the folder does not exist, the script will create it. It will also automatically create backups of your local files just in case you might need one (like if the Central becomes corrupt). So first it will delete the last backup and place it in the Recycle bin (it will stay there until you empty your trash). Then it renames your local file and appends “_BAK” to the filename, copies the Central file to this folder, and removes “central” from the name and replaces it with your Windows username (Ex: 123456789-Project-A08_DBaldacchino.rvt).

5) Check if the required Revit flavor is installed. If not, it will give you the option to open the file with the Revit flavor you have installed on your PC (Ex: it will use Revit Structure 2008 to open an Architectural file). If no Revit is installed, it will let you know and ask you to contact IT (niiiiiice!), after which the script will terminate.

6) The username in the Revit.ini is deleted to prevent problems down the line (you've all experienced having two people working on a project with the same username and one of them complaining they cannot STC, right?!). This ensures that when Revit opens, the username will be set to your Windows username. If multiple flavors of Revit are installed, only the ini file of the discipline that you’re trying to use will be edited.

7) The script will now evaluate what command line/switch was sent through the shortcut. It recognizes "detach" or "worksets" (not case sensitive). In the "Target" field of your shortcut, leave a space at the end and type "detach" or "worksets". If you type anything else, the script ignores it and opens the local file as if no command was sent. So for example your shortcut target would look like this: "\\servername\Projects\ABC\Central\test_A08-Central.rvt" worksets. In this case, the script will write a custom journal called "select_ws.txt" in your journal folder and fire it up in a new instance of Revit. If the command line parameter was detach, a journal called "detach.txt" would be written and used. The script still makes a copy of the central file as a precaution when detaching. Note that currently there is no way to run a journal in an already running Revit session through AHK, so using one of the two switches will cause a new instance of Revit to open.

8) If there is no command line parameter (or an unrecognized one) in the shortcut, the script proceeds as before. First it checks if Revit is already running. If it is, the session will be activated and the local file will start opening. If not, a new session is fired up and the local file starts to open.

9) When the annoying dialog shows up (that this Central has been copied….), it is automatically dismissed, thus rendering the whole process entirely transparent.


Share/Save/Bookmark

8 comments:

David Light said...

Dave,

Thanks for sharing this!!! Not being a code junkie I didn't have a clue where to start. :-)

Dave Baldacchino said...

You're welcome :) I was able to get this together thanks to public support and knowledge sharing of the AutoHotKey forum users. On the AUGI forums, it generated a lot of interest and a very similar exposition of the generous sharing attitude of AUGI members. Thanks to all the comments and efforts from that post, the scripts (there are several posted variations from other users, especially David Kingham) keep getting better and more refined. Ahhh, the beauty of synergy :)

Anonymous said...

if I read the last step correctly, there is a command line switch called "detach" that I could put in to open a file detached from central?

would the command line read like this: "C:\Program Files\Revit Architecture 2008\Program\Revit Filename.rvt /detach"


Thanks,
J. Howard Munsell Jr.,

Dave Baldacchino said...

The target needs to read the following:

"C:\Program Files\Revit Architecture 2008\Program\Revit Filename.rvt" detach

You just add [ detach] or [ worksets] (notice the space and omit the brakets). Anything else will be ignored and the script runs as if no command line parameter was added.

Anonymous said...

I cant seem to get it to work, im trying to open Revit from a batch file and I would like it to open our template and have it be disassociated when it opens for starting new projects.

is there a way I can send you my bat file for you to look at?

Thanks
J. Howard Munsell Jr.

Dave Baldacchino said...

Batch file? There's no batch file involved with my script/application. You just place the app. in the same folder where your Revit workset enabled project is and then either run it from there or create a shortcut to it anywhere you desire. Then in the Target field of the shortcut, add [ detach] or [ worksets] as described in my previous comment.

Template files cannot be workset-enabled, so I'm not sure I follow what you're trying to do as my app won't open anything except rvt files.

Anonymous said...

Dave

Sorry to bother you with troubleshooting on this tool, but it cannot find my Revit app. It copies down the file, renames it, creates the backup, and deletes the previous backup. However it cannot locate the app. It says it's looking for Revit MEP 2009 which is correct. Could it be that I am on 64-bit? I am running 64-bit revit so the folder structures are the same as a 32-bit machine/software combo. Any ideas?

Dave Baldacchino said...

Hey, not a problem!

Yes, it's probably because of 64 bit. I made a change recently to solve this issue. As soon as I get a chance, I'll repost the script and compiled exe to the AUGI post. basically the built-in %A_ProgramFiles% in AutoHotKey is retrieving Program Files (x86) in a 64it OS instead. So I'm not using that built-in AHK parameter and specifying the folder directly. The script will then work on both 32 and 64 bit versions. I'll post a notice to my blog once it's done.

Post a Comment