Raster with opendesignfileforprogram

I can modify rasters using "Opendesignfile".  Does anyone kow how to do it with "Opendesignfileforprogram"?  I'm using Microstation V8i SS2.

For Each file In Files
   Set oFile = oApplication.OpenDesignFile(file, False)
   For Each oRaster In oApplication.RasterManager.Rasters

   . . . Manipulate Raster here . . .

   next oRaster
   oFile.Close
next file

Sincerely,

Christmas May

  • You can not. All you can do is to manipulate its element. What you need to do with it?

  • We have software that renames our attachments when they become obsolete.  Then when you open the Microstation drawing the attachment fails to load properly because the filename of the attachment has changed.  Therefore to answer you question we need to change the filename of the attachment.

  • How about Raster.SetAttachName?  VBA Help has this:

    SetAttachName Method

    Sets the current raster attachment file name and reload the raster

     
    Regards, Jon Summers
    LA Solutions

  • Unknown said:

    How about Raster.SetAttachName?  VBA Help has this:

    SetAttachName Method

    Sets the current raster attachment file name and reload the raster

    Jon, they use model opened for program, so they do not have RasterManager initialised, that means, Raster interfaces are not usable...

    Dan

  • Unknown said:
    they do not have RasterManager initialised

    Oops!

     
    Regards, Jon Summers
    LA Solutions

  • Unknown said:
    Therefore to answer you question we need to change the filename of the attachment.

    Renaming and so on is only possible in model opened normally. Fortunately, MicroStation is a COM object, so we are able to use it in hidden mode. ComplexWay is just example of working with new MicroStation that has a custom address space, so all objects need to be created in it using special function. SimplerWay is example of doing it without use of elements. Note that GetRasterFromElement works only if design file is opened not for program.

    Sub ComplexWay()
      Dim dgn As DesignFile
      Dim ss As ElementScanCriteria
      Dim ee As ElementEnumerator
      Dim rast As Raster
      Dim aoc As ApplicationObjectConnector
      Dim app As MicroStationDGN.Application
        
      ' create new application
      Set aoc = New ApplicationObjectConnector
      Set app = aoc.Application
      app.Visible = False

      ' open design in it
      Set dgn = app.OpenDesignFile("full dgn path"False, msdV7ActionWorkmode)
      
      ' if dgn is valid object
      If Not dgn Is Nothing Then
        
        ' create element scan criteria in address space of new MicroStation process
        Set ss = app.CreateObjectInMicroStation("MicroStationDGN.ElementScanCriteria")
        ss.ExcludeAllTypes
        ss.IncludeType msdElementTypeRasterFrame ' raster element frame
        
        ' scan for raster elements
        Set ee = dgn.DefaultModelReference.Scan(ss)
        
        ' iterate rasters
        While ee.MoveNext()
          ' get Raster for element
          Set rast = app.RasterManager.Rasters.GetRasterFromElement(ee.Current)
          
          ' do whatever with raster
          Debug.Print rast.RasterInformation.FullName
        Wend
      End If
      
      ' quit new application
      app.Quit
      
    End Sub

    Sub SimplerWay()
      Dim dgn As DesignFile
      Dim rast As Raster
      Dim aoc As ApplicationObjectConnector
      Dim app As MicroStationDGN.Application
        
      ' create new application
      Set aoc = New ApplicationObjectConnector
      Set app = aoc.Application
      app.Visible = False

      ' open design in it
      Set dgn = app.OpenDesignFile("full dgn path"False, msdV7ActionWorkmode)
      
      ' if dgn is valid object
      If Not dgn Is Nothing Then
        For Each rast In app.RasterManager.Rasters
          ' do whatever with raster
          Debug.Print rast.RasterInformation.FullName
        Next rast
      End If
      
      ' quit new application
      app.Quit
      
    End Sub
     
    Dan
  • Both methods seem to work.  Is there any advantage to doing it the "complex way"?  Is there supposedly some speed advantage?  I only did it on a few files for testing purposes.