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 combining two ID fields together and creating new ID field. Uses selected objects in an already open MapViewer plot.
To run this script:
- Copy the script below, or click here to download the BAS file: ID_Concatenate.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_Concatenate.bas ' Concatenates two attribute fields together and stores the results to the field of choice. ' ' Open your GSM file in MapViewer and select one or more objects before running script. '======================================================================= 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 "Concatenating 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 concatenated and where the result ' should be stored. 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 300,126,"Concatenate IDs" ' %GRID:10,7,1,1 DropListBox 110,7,180,119,ID_List(),.ID1 DropListBox 110,28,180,119,ID_List(),.ID2 Text 10,63,90,14,"and assign to",.Text2,1 DropListBox 110,63,180,119,ID_List(),.ID3 OKButton 70,98,90,21 CancelButton 180,98,90,21 Text 10,7,90,14,"Concatenate",.Text1,1 Text 70,28,30,14,"with",.Text3,1 End Dialog Dim dlg As UserDialog dlg.ID1 = 0 dlg.ID2 = 0 dlg.ID3 = 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 first attribute, ' concatenate the second, and store in the third. Dim newID As String Dim i As Integer For i = 1 To lyr.Selection.Count Select Case dlg.ID1 Case 0 'PID newID = lyr.Selection.Item(i).PIDName Case 1 'SID newID = lyr.Selection.Item(i).SIDName Case 2 'ID3 newID = lyr.Selection.Item(i).Attrib1 Case 3 'ID4 newID = lyr.Selection.Item(i).Attrib2 Case 4 'Hyperlink newID = lyr.Selection.Item(i).HyperlinkStr End Select Select Case dlg.ID2 Case 0 'PID newID = newID & lyr.Selection.Item(i).PIDName Case 1 'SID newID = newID & lyr.Selection.Item(i).SIDName Case 2 'ID3 newID = newID & lyr.Selection.Item(i).Attrib1 Case 3 'ID4 newID = newID & lyr.Selection.Item(i).Attrib2 Case 4 'Hyperlink newID = newID & lyr.Selection.Item(i).HyperlinkStr End Select Select Case dlg.ID3 Case 0 'PID lyr.Selection.Item(i).PIDName = newID Case 1 'SID lyr.Selection.Item(i).SIDName = newID Case 2 'ID3 lyr.Selection.Item(i).Attrib1 = newID Case 3 'ID4 lyr.Selection.Item(i).Attrib2 = newID Case 4 'Hyperlink lyr.Selection.Item(i).HyperlinkStr = newID End Select Next If dlg.ID3 > 1 Then 'Refresh display lyr.Shapes.InvertSelection() lyr.Shapes.InvertSelection() End If End Sub
Updated May 1, 2018
Comments
0 comments
Please sign in to leave a comment.