Customer Service | Training | Contact Us
You are here: Home > User Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects Visual Basic for Application (VBA) forum

DOModalSave   Jussi Niilahti Jul 13, 2003
Re: DOModalSave   Olivier Damanet Jul 13, 2003
Re: DOModalSave   Jussi Niilahti Jul 13, 2003
Re: DOModalSave   Olivier Damanet Jul 14, 2003
Re: DOModalSave   Jussi Niilahti Jul 14, 2003
Re: DOModalSave   Olivier Damanet Jul 14, 2003
Re: DOModalSave   Jussi Niilahti Jul 14, 2003
Re: DOModalSave   Olivier Damanet Jul 14, 2003
Re: DOModalSave   Jussi Niilahti Jul 14, 2003
Report Inappropriate Content • Top • Print • Reply    
Subject DOModalSave 
Author Jussi Niilahti 
Date Jul 13, 2003 
Message Hi! How can I make a sub that saves the top-most layer with the help of file-dialog? I´ve heard something about DoModalSave method, is that the solution...? Would someone please give me example code? THANX! 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: DOModalSave 
Author Olivier Damanet 
Date Jul 13, 2003 
Message See below 
 
Sub SaveFirstLayer()
  Dim pMxDoc As IMxDocument
  Set pMxDoc.FocusMap
  SaveLayerDialog pMxDoc.FocusMap.Layer(0), Application.hWnd
End Sub

Public Function SaveLayerDialog(ByRef pLayer As ILayer, Optional lParentWindow As Long = 0, Optional ByRef sLayerPath As String) As IGxLayer

  On Error GoTo SaveLayerDialog_ERR

  Dim pGxBrowser As IGxDialog
  Set pGxBrowser = New GxDialog

  Dim pFilter As IGxObjectFilter
  Set pFilter = New GxFilterLayers

  Set pGxBrowser.ObjectFilter = pFilter
  Dim sLayer As String
  Dim sDir As String
  Dim pGLayer As IGraphicsLayer
  Dim pLayer As ILayer
  Dim pGXFile As IGxFile
  Dim pGXLayer As IGxLayer

  If pGxBrowser.DoModalSave(lParentWindow) Then
    
    sLayer = pGxBrowser.name & ".lyr"
    sDir = pGxBrowser.FinalLocation.FullName
    If Right(sDir, 1) <> "\" Then sDir = sDir & "\"
    
    Set pGXLayer = New GxLayer
    Set pGxLayer.Layer = pLayer
    Set pGXFile = pGXLayer
    
    pGXFile.Path = sDir & sLayer
    pGXFile.Save
    sLayerPath = sDir & sLayer
    Set SaveLayerDialog = pGXLayer
    
  End If

  Exit Function

SaveLayerDialog_ERR:
    Debug.Print "SaveLayerDialog_ERR: " & Err.Description
    Debug.Assert 0

End Function
 
  Olivier. 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: DOModalSave 
Author Jussi Niilahti 
Date Jul 13, 2003 
Message Olivier, Unfortunately this code gives combile error (ambiguous name detected: SaveLayerDialog) .

Also Set pMxDoc.FocusMap gives error (= expected)

Is there some way to make samekind of macro for exporting first layer to shapefile?

Thanks again! 
 
Sub SaveFirstLayer()
  Dim pMxDoc As IMxDocument
  Set pMxDoc.FocusMap
  SaveLayerDialog pMxDoc.FocusMap.Layer(0), Application.hWnd
End Sub
 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: DOModalSave 
Author Olivier Damanet 
Date Jul 14, 2003 
Message Sorry, I mistyped that line. Besides, I adapted the SaveLayerDialog function from the one in ArcGISDialogs.bas from the Developer Kit. I guess you added that module to your VBA project, and that causes the 'Ambiguous name' error. 
 
Set pMxDoc = ThisDocument
 
  Olivier. 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: DOModalSave 
Author Jussi Niilahti 
Date Jul 14, 2003 
Message Sorry again, but I´m quite VBA-newbie. This code gives new combile error again:

"Dublicate declaration in current scope". When I remowed that it brings up the dailog but after typed the filename it crashed...=(

What should I do now.... Thanks again! 
 
 Sub SaveFirstLayer()
  Dim pMxDoc As IMxDocument
  Set pMxDoc = ThisDocument
  SaveLayerDialog pMxDoc.FocusMap.Layer(0), Application.hWnd
End Sub

Public Function SaveLayerDialog(ByRef pLayer As ILayer, Optional lParentWindow As Long = 0, Optional ByRef sLayerPath As String) As IGxLayer

  On Error GoTo SaveLayerDialog_ERR

  Dim pGxBrowser As IGxDialog
  Set pGxBrowser = New GxDialog

  Dim pFilter As IGxObjectFilter
  Set pFilter = New GxFilterLayers

  Set pGxBrowser.ObjectFilter = pFilter
  Dim sLayer As String
  Dim sDir As String
  Dim pGLayer As IGraphicsLayer
  Dim pLayer As ILayer
  Dim pGXFile As IGxFile
  Dim pGXLayer As IGxLayer

  If pGxBrowser.DoModalSave(lParentWindow) Then
    
    sLayer = pGxBrowser.name & ".lyr"
    sDir = pGxBrowser.FinalLocation.FullName
    If Right(sDir, 1) <> "\" Then sDir = sDir & "\"
    
    Set pGXLayer = New GxLayer
    Set pGXLayer.Layer = pLayer
    Set pGXFile = pGXLayer
    
    pGXFile.Path = sDir & sLayer
    pGXFile.Save
    sLayerPath = sDir & sLayer
    Set SaveLayerDialog = pGXLayer
    
  End If

  Exit Function

SaveLayerDialog_ERR:
    Debug.Print "SaveLayerDialog_ERR: " & Err.Description
    Debug.Assert 0

End Function

 
 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: DOModalSave 
Author Olivier Damanet 
Date Jul 14, 2003 
Message I should work now. Actually, the path had to be set to the GxLayer object before setting the reference to the layer. 
 
Sub SaveFirstLayer()
  Dim pMxDoc As IMxDocument
  Set pMxDoc = ThisDocument
  SaveLayerDialog pMxDoc.FocusMap.Layer(0), Application.hWnd
End Sub

Public Function SaveLayerDialog(ByRef pLayer As ILayer, Optional lParentWindow As Long = 0, Optional ByRef sLayerPath As String) As IGxLayer

  On Error GoTo SaveLayerDialog_ERR

  Dim pGxBrowser As IGxDialog
  Set pGxBrowser = New GxDialog

  Dim pFilter As IGxObjectFilter
  Set pFilter = New GxFilterLayers

  Set pGxBrowser.ObjectFilter = pFilter
  Dim sLayer As String
  Dim sDir As String
  Dim pGLayer As IGraphicsLayer
  Dim pGXFile As IGxFile
  Dim pGXLayer As IGxLayer

  If pGxBrowser.DoModalSave(lParentWindow) Then
    
    sLayer = pGxBrowser.Name & ".lyr"
    sDir = pGxBrowser.FinalLocation.FullName
    If Right(sDir, 1) <> "\" Then sDir = sDir & "\"
    
    Set pGXLayer = New GxLayer
    Set pGXFile = pGXLayer
    
    pGXFile.Path = sDir & sLayer
    Set pGXLayer.Layer = pLayer
    pGXFile.Save
    sLayerPath = sDir & sLayer
    Set SaveLayerDialog = pGXLayer
    
  End If

  Exit Function

SaveLayerDialog_ERR:
    Debug.Print "SaveLayerDialog_ERR: " & Err.Description
    Debug.Assert 0

End Function
 
  Olivier. 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: DOModalSave 
Author Jussi Niilahti 
Date Jul 14, 2003 
Message Yeah, now it works! I was wondering is it possible to make samekind of macro to save shapes besides lyr-files? THANK YOU SO MUCH AGAIN,Olivier! 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: DOModalSave 
Author Olivier Damanet 
Date Jul 14, 2003 
Message See below. It uses IExportOperation to create the new shapefile. 
 
Sub SaveFirstLayerAsShapefile()
  Dim pMxDoc As IMxDocument
  Set pMxDoc = ThisDocument
  Dim pFeatureLayer As IFeatureLayer
  Set pFeatureLayer = pMxDoc.FocusMap.Layer(0)
  SaveShapeFileDialog pFeatureLayer.FeatureClass, Application.hWnd
End Sub

Public Function SaveShapeFileDialog(ByRef pFeatureClass As IFeatureClass, Optional lParentWindow As Long = 0)

  On Error GoTo SaveShapefileDialog_ERR

    Dim pGxBrowser As IGxDialog
    Set pGxBrowser = New GxDialog
    
    Dim pFilter As IGxObjectFilter
    Set pFilter = New GxFilterShapefiles
    
    Set pGxBrowser.ObjectFilter = pFilter
    Dim sShapefile As String
    Dim sDir As String
    Dim pGxObject As IGxObject
    
    If Not pGxBrowser.DoModalSave(lParentWindow) Then Exit Function
    
    sShapefile = pGxBrowser.Name
    sDir = pGxBrowser.FinalLocation.FullName
    If Right(sDir, 1) <> "\" Then sDir = sDir & "\"
    
    Dim pWorkspaceName As IWorkspaceName
    Set pWorkspaceName = New WorkspaceName
    With pWorkspaceName
        .PathName = sDir
        .WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1"
    End With
    
    Dim pOutDatasetName As IDatasetName
    Set pOutDatasetName = New FeatureClassName
    Set pOutDatasetName.WorkspaceName = pWorkspaceName
    pOutDatasetName.Name = sShapefile
    
    Dim pInDataset As IDataset
    Set pInDataset = pFeatureClass
        
    Dim pExportOp As IExportOperation
    Set pExportOp = New ExportOperation
    pExportOp.ExportFeatureClass pInDataset.FullName, _
                                 Nothing, _
                                 Nothing, _
                                 pFeatureClass.Fields.Field(pFeatureClass.Fields.FindField(pFeatureClass.ShapeFieldName)).GeometryDef, _
                                 pOutDatasetName, _
                                 Application.hWnd

  Exit Function

SaveShapefileDialog_ERR:
    Debug.Print "SaveShapefileDialog_ERR: " & Err.Description
    Debug.Assert 0

End Function
 
  Olivier. 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: DOModalSave 
Author Jussi Niilahti 
Date Jul 14, 2003 
Message I don´t know how much to thank you! You saved my day ;) THANK YOU!