KB no longer maintained - MapViewer is a Legacy Product. Legacy Products are still supported, but no longer receive new features or updates. Many of MapViewer's features have been moved to Surfer. Please contact support@goldensoftware.com with any questions. |
This article contains a sample script for replacing substrings in the ID field of all selected objects in an open MapViewer plot.
To run this script:
- Copy the script below, or click here to download the BAS file: ID_Replace.bas.
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\MapViewer 8\Scripter.
- Double click on Scripter.exe to launch Scripter.
- Press Ctrl+A to select all of the existing lines then press Delete.
- 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.
- Click Script | Run to run the script.
'=========================================== ' ID_Replace.bas ' Replaces substrings in the ID or attribute field of the selected objects. ' ' To run: ' 1. Open your GSM file in MapViewer and select one or more objects. ' 2. Run the script in Scripter. ' 3. Type in the old name and new name of the selected ID/Attribute. For all of the ' selections with that old name, the ID/Attribute will be renamed to the new name. '=========================================== 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 "Replacing strings in IDs requires that" & vbCrLf & "one or more objects be selected first." End End If ' Create and display the dialog to find out which ' IDs should be modified and what to change Dim ID_List(4) As String ID_List(0) = "PID" ID_List(1) = "SID" ID_List(2) = "ID3" ID_List(3) = "ID4" ID_List(4) = "Hyperlink" Begin Dialog UserDialog 270,119,"Replace substring in IDs" ' %GRID:10,7,1,1 DropListBox 90,7,180,112,ID_List(),.ID1 Text 30,42,60,14,"Find",.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,.OldStr TextBox 150,56,110,21,.NewStr Text 155,42,100,14,"Replace with",.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, replace the old string ' with the new and store it back. Dim i As Integer Select Case dlg.ID1 Case 0 'PID For i = 1 To lyr.Selection.Count If Len(lyr.Selection.Item(i).PIDName) > 0 Then lyr.Selection.Item(i).PIDName = Replace(lyr.Selection.Item(i).PIDName,dlg.OldStr,dlg.NewStr) End If Next ' Refresh display lyr.Shapes.InvertSelection() lyr.Shapes.InvertSelection() Case 1 'SID For i = 1 To lyr.Selection.Count If Len(lyr.Selection.Item(i).SIDName) > 0 Then lyr.Selection.Item(i).SIDName = Replace(lyr.Selection.Item(i).SIDName,dlg.OldStr,dlg.NewStr) End If Next ' Refresh display lyr.Shapes.InvertSelection() lyr.Shapes.InvertSelection() Case 2 'ID3 For i = 1 To lyr.Selection.Count If Len(lyr.Selection.Item(i).Attrib1) > 0 Then lyr.Selection.Item(i).Attrib1 = Replace(lyr.Selection.Item(i).Attrib1,dlg.OldStr,dlg.NewStr) End If Next ' Refresh display lyr.Shapes.InvertSelection() lyr.Shapes.InvertSelection() Case 3 'ID4 For i = 1 To lyr.Selection.Count If Len(lyr.Selection.Item(i).Attrib2) > 0 Then lyr.Selection.Item(i).Attrib2 = Replace(lyr.Selection.Item(i).Attrib2,dlg.OldStr,dlg.NewStr) End If Next ' Refresh display lyr.Shapes.InvertSelection() lyr.Shapes.InvertSelection() Case 4 'Hyperlink For i = 1 To lyr.Selection.Count If Len(lyr.Selection.Item(i).HyperlinkStr) > 0 Then lyr.Selection.Item(i).HyperlinkStr = Replace(lyr.Selection.Item(i).HyperlinkStr,dlg.OldStr,dlg.NewStr) End If Next ' Refresh display lyr.Shapes.InvertSelection() lyr.Shapes.InvertSelection() End Select End Sub
Updated May 1, 2018
Comments
0 comments
Please sign in to leave a comment.