 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
david.kingham
Joined: 06 Nov 2007 Posts: 24
|
Posted: Fri Dec 19, 2008 1:28 am Post subject: Revit Launcher |
|
|
If you don't use Revit this is pointless and you can move along
If you do and you are using worksharing in Revit this will be a godsend for you!
This program is used to create a local file automaticaly, open the file in Revit with the option to Specify worksets, Detach from central, etc.
The Revit Launcher.exe can be placed in the same folder as the central file, but I would recomend putting it in one location on your network.
If you place it on your network you will then need to create a shortcut to this file. After you create the shortcut go to the properties, the target should already be pointing to the location of the Revit Launcher.exe, Start In needs to be the path to the central file.
There can only be one Revit file in this folder.
The name of the central file must 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
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
The following dialog will come up when the shortcut is double clicked.
From here you can select the discipline of Revit you want to use, 64 or 32 bit Revit, if you want to open all worksets (default), Specify Worksets, Detach from central, Only open Revit or Only Create Local File.
If you click on the Advanced tab you can see how much RAM is installed in the machine and the size of the central file.
When you click OK a local file will be created in C:\Revit Local Files\XXXXX Where XXXXX is the first portion of the central files name
The local file will be renamed to remove Central and add the current users username
If a local file already exists it will be moved to C:\Revit Local Files\Archive
If an archive exists it will be moved to the Recycle Bin first
The program automatically opens the correct version of Revit based upon the version number in the filename (works for 2008 and up)
If the central file is named incorrectly or there are more than one Revit files in the folder, or if the correct version/discipline of Revit is not installed a error message will be displayed.
The local file is then opened automatically with whatever workset option you have selected or detaches from central if the option is selected
The warning about copying the local file is automatically dismissed
The worksharing monitor will be automatically opened if it is installed
The program is compatible with XP, XP64, Vista and Vista 64
Currently compatible with Revit Architecture/Structure/MEP 2008/2009 64 and 32 Bit
I will be updating for Revit 2010 when it is released
The script can be terminated at any time by pressing Win+X
| Code: | ;---###Scripted by David Baldacchino 08/10/2007, with lots of help from the Discussion Forum at AutoHotKey.com. Thanks guys!!
;---###ModIfied by David Kingham 10/02/2007, added Gui added standard file replacement and registry entries, added Version identIfication so the script will work with future Versions of Revit
;---###ModIfied by David Kingham 03/04/2008, Revised to remove macro function, replaced with journal file method thanks to David Baldacchino again!
;---###Completely revised by David Kingham 12/18/2008, Changed the GUI to have more options
Hotkey #x, EOF ; Allows script to be terminated with Win + X
#SingleInstance force ; If the script is currently running this will kill it
#WinActivateForce
VarSetCapacity( MEMORYSTATUSEX,64,0 ), NumPut( 64,MEMORYSTATUSEX )
DllCall( "GlobalMemoryStatusEx", UInt,&MEMORYSTATUSEX )
TotalPhys := NumGet( MEMORYSTATUSEX,8,"Int64"), VarSetCapacity( PhysMem,16,0 )
DllCall( "shlwapi.dll\StrFormatByteSize64A", Int64,TotalPhys, Str,PhysMem, UInt,16 )
StringTrimRight PhysMem, PhysMem, 3
ThisProcess := DllCall("GetCurrentProcess")
; If IsWow64Process() fails or can not be found,
; assume this process is not running under wow64.
; Otherwise, use the value returned in IsWow64Process.
If !DllCall("IsWow64Process", "uint", ThisProcess, "int*", IsWow64Process)
IsWow64Process := false
If IsWow64Process
{
ActualBit = 64
BitOption = 32
Bit = 64
}
else
{
ActualBit = 32
Bit = 32
}
CheckCentral:
i = 0
Loop, *central.rvt, 0, 0 ; Don't include folders (0) or Recurse into subfolders (0)
;---#### The script is designed to be placed in the location of the central file. First we're going to loop through
;---#### all files in the folder to check If there is only one central file. If there are more files that match the
;---#### searched pattern, the script will issue a dialog, open the folder and terminate execution.
;---#### 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
;---#### 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
{
i := i+1
CentralFile = %A_LoopFileName%
StringTrimRight ProjectName, CentralFile, 16
FileGetsize CentralSize, %CentralFile%, M
}
If i > 1
{
; This will execute If more than one central exists
MsgBox, 16, Problem encountered!!, %i% Central Files were found! Please make sure there is only one Central File in the folder.
ExitApp
}
Else If i = 0
{
; This will execute If no central is found
MsgBox, 16, Problem encountered!!, No Central File was found!
ExitApp
}
CheckVersion: ; Check Version
Version = %3%
If Version =
{
Version := 2000 + SubStr(CentralFile,-13,2)
}
If Version = 2008
{
Bit = 32
BitOption = 32
}
CheckDiscipline:
Discipline = %2%
If Discipline =
{
Discipline := SubStr(CentralFile,-14,1) ; Pick the 14th character to determine the discipline
}
If (Discipline = "A" or Discipline = "L")
{
Discipline = Revit Architecture %Version%
DisciplineOption1 = Revit Structure %Version%
DisciplineOption2 = Revit MEP %Version%
GoSub CheckOpenType
}
If Discipline = S
{
Discipline = Revit Structure %Version%
DisciplineOption1 = Revit Architecture %Version%
DisciplineOption2 = Revit MEP %Version%
GoSub CheckOpenType
}
If (Discipline = "M" or Discipline = "E" or Discipline = "P")
{
Discipline = Revit MEP %Version%
DisciplineOption1 = Revit Architecture %Version%
DisciplineOption2 = Revit Structure %Version%
GoSub CheckOpenType
}
else
{
MsgBox, 16, Undefined Discipline!!, The discipline designator ("%Discipline%") in the filename is incorrect.`n Please rename the file correctly and try again.
GoSub EOF
}
CheckOpenType:
If 1 = All
{
OpenType = Open All Worksets
OpenOption1 = Specify Worksets
OpenOption2 = Detach From Central
OpenOption3 = Only Open Revit
OpenOption4 = Only Create Local
}
If 1 =
{
OpenType = Open All Worksets
OpenOption1 = Specify Worksets
OpenOption2 = Detach From Central
OpenOption3 = Only Open Revit
OpenOption4 = Only Create Local
}
If 1 = Specify
{
OpenType = Specify Worksets
OpenOption1 = Open All Worksets
OpenOption2 = Detach From Central
OpenOption3 = Only Open Revit
OpenOption4 = Only Create Local
}
If 1 = Detach
{
OpenType = Detach From Central
OpenOption1 = Specify Worksets
OpenOption2 = Open All Worksets
OpenOption3 = Only Open Revit
OpenOption4 = Only Create Local
}
If ActualBit = 64
{
RevitProgramFiles = %ProgramFiles%
StringTrimRight RevitProgramFiles, RevitProgramFiles, 6
{
IfNotExist %RevitProgramFiles%\%Discipline%\Program\Revit.exe
{
Bit = 32
BitOption =
}
}
}
GuiMenu:
Gui, Add, Tab,, Open|Advanced
Gui, Add, Text, x30 y40, %ProjectName%
Gui, Add, Text, x20 y63 w60 h20 , Program:
Gui, Add, DropDownList, x80 y60 w150 vDiscipline, %Discipline%||%DisciplineOption1%|%DisciplineOption2%
Gui, Add, Text, x20 y103 w60 h20 , 64/32 Bit:
Gui, Add, DropDownList, x80 y100 w150 vBit, %Bit%||%BitOption%|
Gui, Add, Text, x20 y143 w60 h20 , Open Type:
Gui, Add, DropDownList, x80 y140 w150 vOpenType, %OpenType%||%OpenOption1%|%OpenOption2%|%OpenOption3%|%OpenOption4%|
Gui, Add, Button, x2146 y1140 w-1180 h-1160 , Button
Gui, Add, Button, Default, OK
Gui, Add, Button, x20 y180 w100 h30, OK
Gui, Add, Button, x135 y180 w100 h30 , &Cancel
Gui, Tab, Advanced
Gui, Add, Text, x30 y40, %ProjectName%
Gui, Add, Text, x30 y60, RAM Installed: %PhysMem% gb
Gui, Add, Text, x30 y80, Central File Size: %CentralSize% mb
Gui, Show, h225 w260, Revit Launcher
pause
ButtonOK:
Gui Submit
Gui Destroy
If OpenType = Only Create Local
GoSub CreateLocal
If OpenType = Only Open Revit
GoSub OpenRevit
else
GoSub SetDiscipline
ButtonCancel:
ExitApp
SetDiscipline:
If Discipline = Revit Architecture %Version%
{
Discipline1 = Architecture
Discipline2 = Building
Discipline3 = RAC
GoSub BitVersion
}
If Discipline = Revit Structure %Version%
{
Discipline1 = Structure
Discipline2 = Structure
Discipline3 = RST
GoSub BitVersion
}
If Discipline = Revit MEP %Version%
{
Discipline1 = MEP
Discipline2 = Systems
Discipline3 = RME
GoSub BitVersion
}
BitVersion:
If Version = 2008
{
RevitProgramFiles = %ProgramFiles%
GoSub ApplicationPath
}
If Bit = 32
{
RevitProgramFiles = %ProgramFiles%
GoSub ApplicationPath
}
If Bit = 64
{
RevitProgramFiles = %ProgramFiles%
StringTrimRight RevitProgramFiles, RevitProgramFiles, 6
{
IfNotExist %RevitProgramFiles%\%Discipline%\Program\Revit.exe
RevitProgramFiles = %ProgramFiles%
GoSub ApplicationPath
}
}
ApplicationPath:
AppPath = %RevitProgramFiles%\Revit %Discipline1% %Version%\Program\
DataPath = %RevitProgramFiles%\Revit %Discipline1% %Version%\Data\
JournPath = %RevitProgramFiles%\Revit %Discipline1% %Version%\Journals\
CheckRevitInstall:
IfNotExist %AppPath%Revit.exe
{
MsgBox 16, Revit Install, Revit %Discipline1% %Version% is not installed. `n Please contact the Help Desk to have it installed.
ExitApp
}
CreateLocal: ; Create Local File
;---#### Create local file folder in case it doesn't exist. Delete the backup copy of the local file. Rename the existing local file so it becomes the new backup.
;---#### Then copy the central file to this folder and rename it to reflect the user's username, thus becoming the new local file.
StringTrimRight, PARTFILE, CentralFile, 11 ; Trims central.rvt off the file name
SetTitleMatchMode 2
IfWinExist, %PARTFILE%
{
MsgBox, 16, Local file already open!, A local file for project %PARTFILE% belonging to user %username% is already running.`n The local file will not be created and launched to avoid loss of data.
ExitApp
}
SetTitleMatchMode 1
Destination = C:\Revit Local Files\%PARTFILE% ; Sets the destination folder with a subfolder that is the project name
FileCreateDir C:\Revit Local Files\Archive ; Creates the archive folder
LocalFile = %PARTFILE%%username%.rvt ; Adds "username.rvt" to the file name
FileRecycle C:\Revit Local Files\Archive\%PARTFILE% ; If there is an existing backup it is sent to the recycle bin
FileMoveDir %Destination%, C:\Revit Local Files\Archive\%PARTFILE%, 2 ; If there is an existing local folder it is moved to the archive folder
FileCreateDir %Destination% ; Creates the local folder and subfolder with project name
FileCopy %CentralFile%, %Destination%, 0 ; Do not overwrite existing files (0). Copy central to destination
FileMove %Destination%\%CentralFile%, %Destination%\%LocalFile% ; Rename copied central to appropriate local filename
If OpenType = Only Create Local
GoSub EOF
If OpenType = Open All Worksets
GoSub All
If OpenType = Specify Worksets
GoSub Specify
If OpenType = Detach From Central
GoSub Detach
Specify: ; Opens the correct discipline and Version of Revit, opens the local file with SpecIfy worksets selected
FileDelete %JournPath%specIfy.txt
; Now we create the journal so Revit will prompt us to open select worksets
FileAppend,
(
'
Set Jrn = CrsJournalScript
Jrn.Command "Menu" , "Open an existing project , 57601 , ID_REVIT_FILE_OPEN"
Jrn.Data "File Name" _
, "IDOK", "%Destination%\%LocalFile%"
Jrn.Data "WorksetConfig" _
, "Editable", 0
Jrn.Data "MessageBox" _
, "IDOK", "This Central File has been copied or moved from ""%A_WorkingDir%\%CentralFile%"" to ""%Destination%\%LocalFile%""." & vbCrLf & "" & vbCrLf & "If you wish this file to remain a Central File then you must re-save the file as a Central File. To do this select ""Save As"" from the ""File"" menu and check the ""Make this a Central File after save"" check box (under the options button) before you save." & vbCrLf & "" & vbCrLf & "If you do not save the file as a Central File then it will be considered a local user copy of the file belonging to user ""%USERNAME%""."
Jrn.Command "Menu" , "Workset control , 33460 , ID_SETTINGS_PARTITIONS"
), %JournPath%specIfy.txt
; Open Revit and open the file
Run %AppPath%Revit.exe "%JournPath%specIfy.txt"
GoSub OpenWorksharingMonitor
Detach: ; Opens the correct discipline and Version of Revit, opens the local file with detach from central option selected
FileDelete %JournPath%detach.txt
FileAppend,
(
'
Set Jrn = CrsJournalScript
Jrn.Command "Menu" , "Open an existing project , 57601 , ID_REVIT_FILE_OPEN"
Jrn.Data "FileOpenSubDialog" _
, "DetachCheckBox", "True"
Jrn.Data "MessageBox" _
, "IDOK", "Detaching creates an independent file and prohiBits saving any changes back to the original Central File."
Jrn.Data "File Name" _
, "IDOK", "%Destination%\%LocalFile%"
Jrn.Data "WorksetConfig" _
, "Custom", 0
), %JournPath%detach.txt
; Open Revit and open the file
Run %AppPath%Revit.exe "%JournPath%detach.txt"
All: ; Opens the correct discipline and Version of Revit, opens the local file with all worksets selected
FileDelete %JournPath%open_all.txt
; Now we create the journal so Revit will prompt us to open select worksets
FileAppend,
(
'
Set Jrn = CrsJournalScript
Jrn.Command "Menu" , "Open an existing project , 57601 , ID_REVIT_FILE_OPEN"
Jrn.Data "File Name" _
, "IDOK", "%Destination%\%LocalFile%"
Jrn.Data "WorksetConfig" _
, "All", 0
Jrn.Data "MessageBox" _
, "IDOK", "This Central File has been copied or moved from ""%A_WorkingDir%\%CentralFile%"" to ""%Destination%\%LocalFile%""." & vbCrLf & "" & vbCrLf & "If you wish this file to remain a Central File then you must re-save the file as a Central File. To do this select ""Save As"" from the ""File"" menu and check the ""Make this a Central File after save"" check box (under the options button) before you save." & vbCrLf & "" & vbCrLf & "If you do not save the file as a Central File then it will be considered a local user copy of the file belonging to user ""%USERNAME%""."
), %JournPath%open_all.txt
; Open Revit and open the file
Run %AppPath%Revit.exe "%JournPath%open_all.txt", Max
GoSub OpenWorksharingMonitor
OpenRevit:
FileDelete %JournPath%openstart.txt
FileAppend,
(
'
Set Jrn = CrsJournalScript
Jrn.Command "Menu" , "Close the active project , ID_REVIT_FILE_CLOSE"
Jrn.Command "ToolBar" , "Create a new project , ID_REVIT_FILE_NEW"
), %JournPath%openstart.txt
Run %AppPath%Revit.exe "%JournPath%openstart.txt"
OpenWorksharingMonitor:
IfWinExist Worksharing Monitor for Revit %Version%
GoSub EOF
else
IfWinExist Worksharing Monitor for Revit
Process Close, WorksharingMonitor.exe
IfExist %A_ProgramFiles%\Autodesk\Worksharing Monitor for Revit %Version%\WorksharingMonitor.exe
Run %A_ProgramFiles%\Autodesk\Worksharing Monitor for Revit %Version%\WorksharingMonitor.exe
EOF:
ExitApp
|
|
|
| Back to top |
|
 |
jmqrsq
Joined: 17 Feb 2009 Posts: 2
|
Posted: Tue Feb 17, 2009 4:24 pm Post subject: instruictions? |
|
|
Hello. I wanted to give this a try but I am not sure where to find the RevitLauncher.exe file. I have copied your code and pasted it into a .ahk file and have run it but the GUI does not look like the one you have show n in this thread. Any help would be greatly appreciated.
Jaysyn |
|
| Back to top |
|
 |
david.kingham
Joined: 06 Nov 2007 Posts: 24
|
|
| Back to top |
|
 |
jmqrsq
Joined: 17 Feb 2009 Posts: 2
|
Posted: Tue Feb 17, 2009 6:34 pm Post subject: |
|
|
thanks david. I really appreicate it. Thanks for doing this as well. IS there any other revit scripting sites around that people have shared their scripts with yet?
Jaysyn |
|
| Back to top |
|
 |
david.kingham
Joined: 06 Nov 2007 Posts: 24
|
Posted: Tue Feb 17, 2009 6:58 pm Post subject: |
|
|
| There's an API forum on AUGI if you're interested in that, but as far as scripts go there is not, there's just random posts on AUGI for various things, just do a search for autohotkey and you'll find them |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|