Hi,
I need to scan several hundred design files for their raster attachments.
I'm trying to avoid having to open each file as that really slows the process down.
Has anyone had success using OpenDesignFileforProgram to get raster file attachment list?
I don't want to manipulate any files, just get the list.
Thanks,
Regan
Unknown said:I am running this macro from Microstation
What is the reason ApplicationObjectConnector is used if you are running the macro from MicroStation? The connector object is a way how to work with MicroStation (or other application) from another process. If you start the macro from MicroStation using key-in or from Project manager, this object is not required.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Jon,
I am running this macro from Microstation, no Excel or any other application being used.
The goal here is to identify incorrect CIT attachments in the Raster Manager.
I belive its coming from the ApplicationObjectConnector:
Dim MSApp As ApplicationDim MSAppCon As ApplicationObjectConnector
Set MSAppCon = New ApplicationObjectConnectorSet MSApp = MSAppCon.ApplicationMSApp.Visible = False
Unknown said:Dim MSApp As Application
It looks like you're attempting to run MicroStation from another application, such as Excel. Could you explain more clearly what you are doing?
Regards, Jon Summers LA Solutions
Thanks Jon and YongAn.
I took your advice and used this approach which works well most of the time. However, every now and then I get
"error 462 The remote server machine does not exist or is unavalable". What causes this? Here is my code:
'---------------------- code starts here --------------------------------
Option ExplicitDim MSApp As ApplicationDim ReportOpened As BooleanDim numMisMatchesFound As Long
Public Sub CitChecker()Dim MSAppCon As ApplicationObjectConnector
Dim FSO As Scripting.FileSystemObjectDim SourceFolder As Scripting.FolderDim FileItem As Scripting.FileDim possibleCITname As StringDim ReportName As StringOn Error GoTo err
If MsgBox("Check for incorrect CIT attachments?", vbYesNo, "") = vbNo Then Exit Sub
' Get new MicroStation Application Object Set MSAppCon = New ApplicationObjectConnector Set MSApp = MSAppCon.Application MSApp.Visible = False
Set FSO = New Scripting.FileSystemObject Set SourceFolder = FSO.GetFolder(ActiveDesignFile.Path) ReportOpened = False numMisMatchesFound = 0 Application.ShowStatus "checking for incorrect CIT files..." DoEvents For Each FileItem In SourceFolder.Files ' go through all files in folder If FileItem.Type = "DGN File" Then possibleCITname = Left$(FileItem.Name, Len(FileItem.Name) - 4) & ".cit" ' if CIT exists for current dgn If FSO.FileExists(SourceFolder.Path & "\" & possibleCITname) Then ' if CIT exists for DGN, check to see if its attached If UCase(ActiveDesignFile.FullName) = UCase(FileItem.Name) Then If GetRefsCurrentFile = False Then Call SendToReport(SourceFolder.Path, ActiveDesignFile.FullName) End If Else If GetRefsRemoteFile(FileItem.Path, FileItem.Name) = False Then Call SendToReport(SourceFolder.Path, FileItem.Path) End If End If ' if in current file End If ' if proposed CIT exists End If ' if DGN file Next FileItem Application.ShowStatus "" If ReportOpened Then Print #1, " " Print #1, "---------------------------------------------------------------" Print #1, numMisMatchesFound & " Dgn file(s) found" Close #1 Dim ret ret = Shell("C:\WINDOWS\system32\notepad.exe " & SourceFolder.Path & "\" & "CitErrorReport", vbNormalFocus) Else ' if no mismatched cit's then just show 'done' message MsgBox "No incorrect CIT attachments found for:" & vbCrLf & SourceFolder.Path, vbInformation, "done" End If ' release Application MSApp.Quit Set MSApp = Nothing Exit Suberr: MsgBox "CitChecker error " & err.Number & vbCrLf & err.DescriptionEnd Sub
Private Sub SendToReport(arrSourceFolder As String, arrFileNameToAddToReport As String) If ReportOpened = False Then Open arrSourceFolder & "\" & "CitErrorReport" For Output As #1 Print #1, "Dgn files missing correct CIT attachment:" ReportOpened = True End If Print #1, UCase(arrFileNameToAddToReport) numMisMatchesFound = numMisMatchesFound + 1End Sub
Private Function GetRefsRemoteFile(arrFilePath As String, arrFilename As String) As BooleanDim Dsgn As DesignFileDim myRaster As rasterDim rastername As StringDim a ' array to capture full path of file
Set Dsgn = MSApp.OpenDesignFile(arrFilePath, True) GetRefsRemoteFile = False arrFilename = LCase(arrFilename) ' Iterate all rasters in Rasters collection For Each myRaster In MSApp.RasterManager.Rasters a = Split(myRaster.RasterInformation.FullName, "\") ' get the filename at the end of the path rastername = LCase(a(UBound(a))) If Right$(rastername, 3) = "cit" Then 'if attached file is CIT then check if its name matches the active design file If Left$(rastername, Len(rastername) - 4) = Left$(arrFilename, Len(arrFilename) - 4) Then GetRefsRemoteFile = True Exit Function End If End If
Next myRaster Dsgn.CloseEnd Function
Private Function GetRefsCurrentFile() As Boolean ' for the current open file onlyDim oRaster As rasterDim Count As LongDim temp As String
GetRefsCurrentFile = False For Count = 1 To RasterManager.Rasters.Count() ' go through all raster attachments
With oRaster Set oRaster = RasterManager.Rasters.Item(Count) temp = oRaster.RasterInformation.Name ' if current attached raster file is correct CIT that was found when filelist was created, then return TRUE flag If LCase(temp) = LCase(ActiveDesignFile.FullName) Then GetRefsCurrentFile = True ' the correct CIT has been attached, get out now Exit Function End If End With
Next Count
End Function
' ----------------- code ends here --------------------------
Unknown said:I'm trying to avoid having to open each file as that really slows the process down
If you want to look inside any file, you have to open it. Whether the file is plain old text, a Word document, an Excel workbook or a DGN file you must run an executable that can read that sort of data. For a DGN file, the application that can open it is MicroStation.