REvit CAche parser for C4R files to ID Revit Files



Public fso As New FileSystemObject Public oUsrFolder As Folder Public oRvtFolder As Folder Public rvers As Integer Public ifp As String Public sfp Public GUID_FILES As ArrayList Sub LinkToJournalFiles() Set GUID_FILES = CreateObject("System.Collections.ArrayList") 'array list to manage file path, file name & CSLID pairs Set fso = CreateObject("Scripting.FileSystemObject") ''Current user (Or all users?) For Each oUsrFolder In fso.GetFolder("C:\users").subfolders ''Scan for versions of Revit ifp = oUsrFolder.Path & "\AppData\Local\Autodesk\revit" If fso.FolderExists(ifp) Then For Each oRvtFolder In fso.GetFolder(ifp).subfolders Set sfp = regexp(oRvtFolder.Path, ".*\\(Autodesk Revit .*)\\{0,1}") If sfp.count > 0 Then ParseRevitFolder (oRvtFolder) Next End If Next oUsrFolder ''''''''''' ''GUID_FILES is a list of strings of filepath > GUID > and corresponding actual filename Sub ParseRevitFolder(RevitFolder) FilePath = RevitFolder & "\Journals\" Set RevitFolder = fso.GetFolder(FilePath) Dim ofile Dim subfolders As Folder Dim rfile Dim fstr ''As String ''scan the folders ''Gather GUIDs ''Create MKlinks or shortcuts to the GUIDs based on the file names For Each ofile In RevitFolder.Files If regexp(ofile.Name, "(journal\.\d{4}\.txt)").count > 0 Then ''match with journal files we are after Set rfile = fso.OpenTextFile(ofile.Path, ForReading) ''open Journel file fstr = rfile.ReadAll ''Read jounral into a string to parse in its entireity rfile.Close ''Close the file Set pgroups = regexp(fstr, "(IDOK.+CLD.+\.rvt\" & Chr(34) & ")") ''find groups to pull pairs of GUIDs and filenames from If pgroups.count > 0 Then ''Matched group For Each cslid_fn_groups In pgroups ''For each matched group found - parse Set PairSearch = regexp(cslid_fn_groups.Value, "\:\/\/(\{.+\})(.+)\/(\{.+\})(.+)").Item(0).SubMatches If PairSearch.count > 0 Then PushPairs PairSearch, FilePath ''each item in pairsearch ''n(0)=CSLID Project ''n(1)=Project Name ''n(2)=CSLID model file '''<<<<<<<<<<<<<< ''n(3)=MODEL File name '''<<<<<<<<<<<<<< End If Next cslid_fn_groups End If ''use regex to search multipline file ot return values End If Next ofile End Sub Sub PushPairs(PairSearch, fp) ''push regex search results to list of items ''GUID_FILES as public list Dim found As Boolean Dim I As Integer Dim J For I = 0 To PairSearch.count - 1 Step 2 found = False For Each J In GUID_FILES If LCase(Split(J, ">")(0)) = LCase(PairSearch.Item(I)) Then found = True Exit For End If Next J If Not found Then GUID_FILES.add (fp & ">" & PairSearch.Item(I) & ">" & PairSearch.Item(I + 1)) ''add in pair of {GUID} with a ">" and the file path and ">" and then file name Next I End Sub Private Function regexp(strSource, strPattern As String) As Variant Dim objRegEx As New regexp Dim result ''As String Dim allMatches ''As Object Set objRegEx = CreateObject("vbscript.regexp") On Error Resume Next objRegEx.Pattern = strPattern ''objRegEx.Global = True objRegEx.IgnoreCase = True Set allMatches = objRegEx.Execute(strSource) Set regexp = allMatches End Function

Comments

Popular posts from this blog

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

Powerpoint countdown and current time in slides VBA

Revit 2019 and up tab colorizer