using OpenDesignFileforProgram to get raster file attachment list

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

Parents
  • 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.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Regan,
    Just as Jon's post, you MUST open a file to access its contents. OpenDesignFileForProgram still needs open DGN file but doesn't display file contents on the current session. Unfortunately, the RasterManager object is only applied to active design file, so you have to open your file by using OpenDesignFile method.
    If you don't want display the file contents, maybe automating MicroStation and setting its visible to false is a good approach.
    HTH, YongAn



  • 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 Explicit
    Dim MSApp As Application
    Dim ReportOpened As Boolean
    Dim numMisMatchesFound As Long

    Public Sub CitChecker()
    Dim MSAppCon As ApplicationObjectConnector

    Dim FSO As Scripting.FileSystemObject
    Dim SourceFolder As Scripting.Folder
    Dim FileItem As Scripting.File
    Dim possibleCITname As String
    Dim ReportName As String
    On 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 Sub
    err:
        MsgBox "CitChecker error " & err.Number & vbCrLf & err.Description
    End 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 + 1
    End Sub

    Private Function GetRefsRemoteFile(arrFilePath As String, arrFilename As String) As Boolean
    Dim Dsgn As DesignFile
    Dim myRaster As raster
    Dim rastername As String
    Dim 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.Close
    End Function

    Private Function GetRefsCurrentFile() As Boolean ' for the current open file only
    Dim oRaster As raster
    Dim Count As Long
    Dim 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:
    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

  • 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 Application
    Dim MSAppCon As ApplicationObjectConnector

    Set MSAppCon = New ApplicationObjectConnector
    Set MSApp = MSAppCon.Application
    MSApp.Visible = False

     

  • Hi,

    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

Reply Children
No Data