Follow

How can I add a prefix/suffix to all PIDs for the selected objects using MapViewer automation?

This article contains a sample script for appending a prefix or suffix to the current value of any ID or attribute field of selected objects in an open MapViewer plot.

To run this script:

  1. Copy the script below, or click here to download the BAS file: ID_Append.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.
     

*********

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ID_Append.bas
' Copyright (C) Golden Software Inc. 1992-2015
'
' This script appends a prefix and/or suffix to the current value of any
' ID or attribute field of the selected objects.
'
' To run this script, first open your MapViewer GSM file in MapViewer
' and select the objects whose IDs/attributes you wish to edit.
' Then run this script in Scripter.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub Main
    Dim mvApp, lyr As Object

    ' Find MapViewer and create a pointer to the application object
    Set mvApp = GetObject(,"MapViewer.Application")

    ' Make sure that at least one object is selected
    Set lyr = mvApp.ActiveDocument.ActiveLayer
    If lyr.Selection.Count = 0 Then
      MsgBox "Appending to IDs requires that" & vbCrLf & "one or more objects be selected first."
      End
    End If

    ' Create and display the dialog to find out which
    ' ID should be modified and get the strings to use
    ' for the prefix and/or suffix.
    Dim ID_List(4) As String
    ID_List(0) = "PID"
    ID_List(1) = "SID"
    ID_List(2) = "Attrib 1"
    ID_List(3) = "Attrib 2"
    ID_List(4) = "Hyperlink"
    Begin Dialog UserDialog 270,119,"Append to IDs" ' %GRID:10,7,1,1
        DropListBox 90,7,180,112,ID_List(),.ID1
        Text 30,42,60,14,"Prefix",.Text2,2
        OKButton 40,91,90,21
        CancelButton 150,91,90,21
        Text 0,7,80,14,"ID to modify",.Text1,1
        TextBox 10,56,110,21,.Prefix
        TextBox 150,56,110,21,.Suffix
        Text 180,42,50,14,"Suffix",.Text3,2
    End Dialog
    Dim dlg As UserDialog
    dlg.ID1 = 0
    Dim sts As Integer

    sts = Dialog(dlg)

    ' The Cancel button returns 0.
    ' The OK button returns -1.
    If sts = 0 Then ' cancel button pressed
      End
    End If

    ' For each selected object, get the current attribute value,
    ' add the prefix and suffix and store it back.
    Dim i As Integer

    Select Case dlg.ID1
    Case 0 'PID
        For i = 1 To lyr.Selection.Count
            lyr.Selection.Item(i).PIDName = dlg.Prefix & lyr.Selection.Item(i).PIDName & dlg.Suffix
        Next
    Case 1 'SID
        For i = 1 To lyr.Selection.Count
            lyr.Selection.Item(i).SIDName = dlg.Prefix & lyr.Selection.Item(i).SIDName & dlg.Suffix
        Next
    Case 2 'Attrib1
        For i = 1 To lyr.Selection.Count
            lyr.Selection.Item(i).Attrib1 = dlg.Prefix & lyr.Selection.Item(i).Attrib1 & dlg.Suffix
        Next
        ' refresh the OM
        lyr.Shapes.InvertSelection()
        lyr.Shapes.InvertSelection()
    Case 3 'Attrib2
        For i = 1 To lyr.Selection.Count
            lyr.Selection.Item(i).Attrib2 = dlg.Prefix & lyr.Selection.Item(i).Attrib2 & dlg.Suffix
        Next
        ' refresh the OM
        lyr.Shapes.InvertSelection()
        lyr.Shapes.InvertSelection()
    Case 4 'Hyperlink
        For i = 1 To lyr.Selection.Count
            lyr.Selection.Item(i).HyperlinkStr = dlg.Prefix & lyr.Selection.Item(i).HyperlinkStr & dlg.Suffix
        Next
        ' refresh the OM
        lyr.Shapes.InvertSelection()
        lyr.Shapes.InvertSelection()
    End Select

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.