Revit Central files to Local Files without a revit server

Right Click to create LOCAL files from CENTRAL files (not Revit Server)

The Issue:

Revit Central Files require users to create local files. Normally if you open a central file it asks if you want to create a local copy, but it doesn't replace *CENTRAL* with *LOCAL*.

First I started with a VBS that you can add to the right-click send to. This works pretty well, but I want better for my users and myself so I did a little research into registry and shell addins. Come to find out it isn't that difficult of a trick to manage.

The Solution:

and A script I created and have been modifying for years...

Always back up your registry prior to any registry additions!
This is a registry entry
in the (Default) Of the Command Of the Localize Central subkey...
WScript.exe  "\\YOUR_SERVER_AD_HERE.local]\_SCRIPT\Revit\REVIT_Localize.vbs" "%1"
The Registry entry looks more like this in the .REG file:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Revit.Project\shell\Localize Central\Command]
@="WScript.exe  \"\\\\[YOUR_SERVER_AD_HERE.local]\\_SCRIPT\\Revit\\REVIT_Localize.vbs\" \"%1\""
 Which adds a connect to the Script:
Where [YOUR_SERVER_AD_HERE.local] is the Active Directory (AD) path back to your local content set up with your IT department or as a common location to your scripts.  


With this in the registry, You get a shell extension like this when you right click any .rvt file:

By right-clicking and selecting Localize Central


Executes the script

Passes the file with the "%1"

And the Script does the rest.

An example of a script I need to clean up is below- sorry it is really messy and I need to remake it simpler- but the code to hack and slash the filename and clean it up is part of the subroutines.

The Subroutines look for job numbers and some other organizing information to create a local copy in

You can sub your own script there : ) Or modify this one. I will clean this up later and repost.


Const ThisScriptVersion = "2010-01-21.01.00"''Revisions''2010-01-21-Central to local - added delimeters for CENTRAL and LOCAL''2010-01-21-defined basic arguments for drag&Drop''Define constants
''CENTRAL TO LOCAL DELIMETERSPublic Const StrFileLocalDelim = "-LOCAL-"Public Const StrFileCentralDelim = "CENTRAL"Public Const StrFileCentralRegex = ".?(CENTRAL)" ''Regexp for *central*
''''<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<''''BEGIN SCRIPT<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<''''<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<''''Sub Main()
   ''BEGIN BODY   ''cHECK ARGS- IF USER DOUBLE CLICKED OR NO ARGS RETURN INSTRUCTIONS   If WSCRIPT.Arguments.Count = 0 Then      MsgBox "This Script version:" & ThisScriptVersion & vbCr & "Drag and drop a file or folder, or SendTo " & WSCRIPT.ScriptFullName & " to localize *CENTRAL*", vbOK, "Error"      WSCRIPT.Quit   End If      If WSCRIPT.Arguments.Count > 0 Then      Dim ArgItem  ''Arg Item in wscript      Dim DirCt    ''Count Directories in drag and drop      Dim FileCt   ''Count Files in drag and drop            For Each ArgItem In WSCRIPT.Arguments         If FileExists(ArgItem) Then FileCt = FileCt + 1         If FolderExists(ArgItem) Then DirCt = DirCt + 1      Next            If DirCt + FileCt <> WSCRIPT.Arguments.Count Then         MsgBox "File Or Directory Does Not Exist", vbOK, "Source File or Folder error"         EXIT_CLEANUP      End If   End If      ''Parse through arguments - find '*CENTRAL*.RVT' references   Dim InstrPos      ''Position locator for "CENTRAL"   Dim DestFullName  ''Destination Filename & PATH   Dim DestPath      ''Destination Path   Dim LocalPrefix   ''Local Prefix Path for project files   Dim X, XX         ''For split   Dim I, j          ''generic counter   Dim JobNo         ''For Job Number string      For j = 0 To WSCRIPT.Arguments.Count - 1   ''For Each ArgItem In WSCRIPT.Arguments      ArgItem = WSCRIPT.Arguments(j)         InstrPos = 0      ArgItem = UCase(ArgItem)         InstrPos = InStr(ArgItem, StrFileCentralDelim)         ''If not revit then rest instr regardless      If Right(ArgItem, 4) <> ".RVT" Then         InstrPos = 0      End If
      '''''''''''''      ''set local prefix to C:      LocalPrefix = "C:\" & "__" & UCase(GetUserLoginID) & "\_Projects\"                     If InstrPos > 0 And FileExists(ArgItem) Then         DestFullName = CentralToLocal(ArgItem)           X = Split(ArgItem, "\")         For I = 0 To UBound(X)             JobNo = ""             JobNo = GetJobNo(X(I))             DestPath = ""             DestFullPath = ""                ''If JobNo > "" Then  ''''Found Job NO
                DestPath = LocalPrefix & JobNo & "\"                DestFullName = DestPath & CentralToLocalRegExp(X(UBound(X)))                 msgbox DestFullName 
                If Not (FolderExists(DestPath)) Then                ''Need To Create Dir                   Set DestFolder = CreateNewFolder(DestPath)                End If             ''MsgBox ArgItem & vbCr & " TO " & vbCr & DestFullName             CopyFile ArgItem, DestFullName                          ''End If ''jobno         Next '' i      End If   Next

   ''Do Cleanup   EXIT_CLEANUP
''''End Sub ''main''''<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<''''END SCRIPT<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<''''<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Sub EXIT_CLEANUP()   WSCRIPT.Echo "Build number: " & _      ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion & "." & ScriptEngineBuildVersion & _         vbCr & "This Script version:"  & ThisScriptVersion & vbcr & WSCRIPT.ScriptFullName & vbCr &_    vbCr & "(" & FileCt & ") File(s), (" & DirCt & ") - Folder(s)"   WSCRIPT.QuitEnd Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''BEGIN FUNCTIONS'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''fileCopyFunction CopyFile(Source, DestinationFolder)    Dim ObjFSO               ''As FileSystemObject    Dim RevitBackupFolder    ''Revit backup folder name    Set ObjFSO = CreateObject("Scripting.FileSystemObject")    If ObjFSO.FileExists(Source) Then       ObjFSO.CopyFile Source, DestinationFolder, True       RevitBackupFolder = _         (Left(DestinationFolder, Len(DestinationFolder) - 4)) & "_backup"       If FolderExists(RevitBackupFolder) Then           ObjFSO.DeleteFolder RevitBackupFolder       End If    End If    Set CopyFile = ObjFSOEnd Function
Sub TestCreateFileCopy()   Dim X ''As File   CopyFile "S:\Healthcare\3683a-00 VA Bay Pines\2.0 Drawings\2.4 Revit\1.0 Project Files\1.1 Central\3683a_CENTRAL_PLUMBING_EB.rvt" _          , "C:\__RALLEN\_Projects\3683A-00\3683A-LOCAL-_PLUMBING_EB.RVT"End Sub
'''''''''''''''''''''''''''''create new folderFunction CreateNewFolder(FolderPath)   Dim ObjFSO   Dim I        Set ObjFSO = CreateObject("Scripting.FileSystemObject")        If ObjFSO.FolderExists(FolderPath) Then            ''return folder            Set CreateNewFolder = ObjFSO.GetFolder(FolderPath)         Else            For I = Len(FolderPath) To 1 Step -1              If Mid(FolderPath, I, 1) = "\" And I < Len(FolderPath) Then Exit For            Next ''I            CreateNewFolder (Left(FolderPath, I))            Set CreateNewFolder = ObjFSO.CreateFolder(FolderPath)        End IfEnd Function
Sub TestCreateNewFolder()   Dim X 'As Folder   Set X = CreateNewFolder("C:\temp\foo1\foo2")End Sub

'''''''''''''''''''''''''''''Get user login IDFunction GetUserLoginID()  Dim WSHNetwork  Set WSHNetwork = CreateObject("WScript.Network")  GetUserLoginID = CStr(WSHNetwork.UserName)End FunctionSub Foo2() MsgBox GetUserLoginIDEnd Sub''''''''''''''''''''''''''''''Return jobno with RegExp''Matching first ####?-##''#=digit''.=any characterFunction GetJobNo(PathStr)
  On Error Resume Next
    Dim Match    Dim Matches ''for regex matches    Dim re    Set re = New RegExp    re.Pattern = "\d{4}.-\d{2}"    re.IgnoreCase = True    re.MultiLine = False    Set Matches = re.Execute(PathStr)    Set Match = Matches(0)    GetJobNo = Match.Value
  On Error GoTo 0
End Function
''''''''''''''''''''''''''''''''''Function central to local RegexpFunction CentralToLocalRegExp(FName)    Dim re    Set re = New RegExp    re.Pattern = StrFileCentralRegex  ''Constant for central pattern match    re.Global = True    CentralToLocalRegExp = re.Replace(FName, StrFileLocalDelim)End Function
'''''''''''''''''''''''''''''''''''Strip Central and replace with -LOCAL-Function CentralToLocal(FName)   ''returns lcase filename representation of central filename   ''replacing central with LOCAL   Dim X   Dim FN      X = Split(FName, "\")   FN = X(UBound(X))   CentralToLocal = FN      Dim I   I = InStr(1, FN, StrFileCentralDelim) - 1   If I < 1 Then Exit Function      CentralToLocal = LCase(Left(FN, I))      If Right(CentralToLocal, 1) = "-" Then CentralToLocal = Left(CentralToLocal, Len(CentralToLocal) - 1)      CentralToLocal = CentralToLocal & StrFileLocalDelim _      & LCase(Right(FN, (Len(FN) - Len(StrFileCentralDelim) - I)))End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''See if file exists- returns false for directoryFunction FileExists(sFileName)   Dim ObjFSO ''As FileSystemObject   Set ObjFSO = CreateObject("Scripting.FileSystemObject")      If (ObjFSO.FileExists(sFileName)) Then      FileExists = True   Else      FileExists = False   End If      Set ObjFSO = NothingEnd Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''See if Dir Folder exists- returns false for filesFunction FolderExists(sDirName)   Dim ObjFSO ''As FileSystemObject   Set ObjFSO = CreateObject("Scripting.FileSystemObject")      If (ObjFSO.FolderExists(sDirName)) Then      FolderExists = True   Else      FolderExists = False   End If      Set ObjFSO = NothingEnd Function


Popular posts from this blog

Revit area plans adding new types and references (Gross and rentable)

Organization and management of data in Revit across omniclass, Masterformat, Uniclass, and Uniformat