Attribute VB_Name = "ExportSymbols"
Public Sub ExportSyms()
'This routine was written for testing in VBA
Dim mxd As IMxDocument
'If you put this code in the "ThisDocument" object in VBA then
'change the following variable assignment to "Me". If you keep
'this code in a separate module, then leave the following line
'as is.
Set mxd = ThisDocument 'Me
Call SaveRenderer(mxd.SelectedLayer, "C:\roads.agl")
End Sub
Public Sub RestoreSyms()
'This routine was written for testing in VBA
Dim mxd As IMxDocument
'If you put this code in the "ThisDocument" object in VBA then
'change the following variable assignment to "Me". If you keep
'this code in a separate module, then leave the following line
'as is.
Set mxd = Me
Call LoadRenderer(mxd.SelectedLayer, mxd, "C:\roads.agl")
End Sub
Private Sub SaveRenderer(oGeoLayer As IGeoFeatureLayer, sFileName As String)
'This routine should work in either VBA or VB6
On Error GoTo eh
Dim oMemBlob As IMemoryBlobStream
Dim oObjectStream As IObjectStream
Dim oPropSet As IPropertySet
Dim oPersistStream As IPersistStream
'Set up the objects to persist the symbology
Set oMemBlob = New MemoryBlobStream
Set oObjectStream = New ObjectStream
Set oObjectStream.Stream = oMemBlob
Set oPropSet = New PropertySet
Set oPersistStream = oPropSet
'Persist the layer's symbology
oPropSet.SetProperty "Symbology", oGeoLayer.Renderer 'persist the renderer to the PropertySet
oPersistStream.Save oObjectStream, False 'Save the persist stream to the blob via the object stream
oMemBlob.SaveToFile sFileName 'write the blob to a file
Exit Sub
eh:
MsgBox "There was an error exporting the symbology: " & Err.Number & "::" & Err.Description, vbCritical, "Export Error!"
End Sub
Private Sub LoadRenderer(oGeoLayer As IGeoFeatureLayer, oMxd As IMxDocument, sFileName As String)
'This routine should work in either VBA or VB6
On Error GoTo eh
Dim oMemBlob As IMemoryBlobStream
Dim oObjectStream As IObjectStream
Dim oPropSet As IPropertySet
Dim oPersistStream As IPersistStream
'Set up the objects to depersist the symbology
Set oMemBlob = New MemoryBlobStream
Set oObjectStream = New ObjectStream
Set oObjectStream.Stream = oMemBlob
Set oPropSet = New PropertySet
Set oPersistStream = oPropSet
'Get the symbology from the file
oMemBlob.LoadFromFile sFileName 'read the file into the blob
oPersistStream.Load oObjectStream 'load the persist stream
Set oGeoLayer.Renderer = oPropSet.GetProperty("Symbology") 'depersist the renderer and assign it
oMxd.ActiveView.Refresh 'refresh the map
oMxd.CurrentContentsView.Refresh oMxd.SelectedItem 'refresh the TOC
Exit Sub
eh:
MsgBox "There was an error restoring the symbology: " & Err.Number & "::" & Err.Description, vbCritical, "Import Error!"
End Sub
Wednesday, December 10, 2008
export import symbology
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment