Follow

I have many MapViewer GSM files containing base maps in one specific directory. How can I swap the PID and SID for all objects in all of the base maps using a script?

This article contains a sample script for swapping the PID and SID for all objects in all base maps of GSM files in a given directory.

To run this script:

  1. Copy the script below, or click here to download the BAS file: RedefineAttribs.BAS.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\MapViewer 8\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
  6. Click Script | Run to run the script.
     

*********

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' RedefineAttribs.BAS
' Copyright (C) Golden Software Inc. 1992-2015
'
' This script demonstrates how to loop through GSM files in a given directory
' and swap the PID and SID for all objects in the base map layers
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Main

'Initializes everything needed to start MapViewer
Dim MapViewer As Object
Set mvApp = CreateObject("MapViewer.Application")
mvApp.Visible = True

'Open MapViewer's Open dialog box
Directory = "C:\Program Files\Golden Software\MapViewer 8\Samples\" 'CHANGE THIS DIRECTORY
file$ = Dir$(Directory + "*.gsm")

While file$ <> ""
    'Open the file in the directory in order
    Set Plot1 = mvApp.Documents.Open(Directory+file$)

    'Loops through all the layers in the file
    For i = 1 To Plot1.Layers.Count

        'Enters the If statement if the layer is a base layer
    	If Plot1.Layers(i).GetMap Is Nothing Then
            'Activates the layer, selects everything in the layer, and swaps the PID and SID
	    Plot1.Layers(i).Activate
	    Plot1.Layers(i).Shapes.SelectAll
	        Plot1.Layers(i).Selection.RedefineAttributes(PIDField:=mvAttribTypeSID, SIDField:=mvAttribTypePID, _
		  Attrib1Field:=mvAttribTypeAttrib1, Attrib2Field:=mvAttribTypeAttrib2, HyperlinkField:=mvAttribTypeHyperlink)
		Plot1.Layers(i).Selection.DeselectAll

    	End If
    Next i

    'Resave file as MapViewer file with a new name
    Plot1.SaveAs(Directory + file$ + "_PIDisSID.gsm")

    'Close the plot window
    Plot1.Close()

    'Open the next file
    file$ = Dir$()
Wend

End Sub

 

Updated November 2, 2016

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.