Subscribe to this thread
Home - General / All posts - Scripting column name change and map components
philw
88 post(s)
#06-Nov-18 08:38

I have been working on a script that will do the following:

1) Select pixels in the active surface from a drawing polygon (UI script - transfer selection)

2) Crop the surface to the selection (Analyzer script)

3) Transform the cropped surface (UI script - Transform)

4) Transfer heights from the transformed surface to points in a drawing.

A couple of issues; a) Can anyone help with renaming a column in the points drawing within the script for (4) above? Essentially the issue is that the UI dialogue for Transfer Heights sends the heights to a "Heights" column, which gets overwritten each time. I would like to rename the column from "Heights" to the name of the surface from which the heights came, so that on the next iteration of the script the "Heights" column can receive the new data and then get renamed etc.

b) as the UI scripting involves some dialogues that are only available within the Map component, can anyone suggest some code to cycle through all the surfaces in the Map with the above script/workflow?

The script for 4) is below:

Sub Main

Dim UI, Dlg

Set UI = Application.UserInterface

UI.InvokeCommand("MapTransferHeights")

' Wait for dialog to show (to avoid timing issues)

Do ' Nothing

Loop Until UI.DisplaysModalDialog

Do ' Nothing

Loop Until UI.ModalDialog.Caption = "Transfer Heights"

Set Dlg = UI.ModalDialog

With Dlg.ControlSet

.Item("ComboBoxSource").Text = "[Application.ActiveWindow.ActiveComponent.Name]"

.Item("ComboBoxTarget").Text = "POINTS"

.Item("ComboBoxTargetColumn").Text = "Application.ActiveWindow.ActiveComponent.Name"

End With

Dlg.Accept

End Sub

adamw


8,204 post(s)
#06-Nov-18 16:11

For (b), this code loops through all map layers and reports surfaces:

'VBScript

Sub Main

  Set map = Document.ComponentSet("Map")

  Set mapLayers = map.LayerSet

  For Each layer In mapLayers

    If layer.Component.Type = ComponentSurface Then

      Application.MessageBox layer.Component.Name, "Script"

    End If

  Next

End Sub

For (a), the Transfer Heights dialog does not allow specifying the name for a new column. You can either create a column with the desired name before invoking the dialog and then select it in the dialog using UI scripting. Or you can accept the default Height column and rename it after the dialog completes. Which one do you want?

philw
88 post(s)
#08-Nov-18 01:31

Thanks Adam. I did not seem possible in the UI for the Transfer Heights dialogue to name the column so my original thought would be to rename the [Height] column after the dialogue completes, preferably to the name of the surface that the heights came from. I just am not sure how to do that by code and could not find any similar scripts to alter in the forum.

adamw


8,204 post(s)
#08-Nov-18 14:22

Renaming an existing column is pretty easy:

'VBScript

Sub Main

  Set table = Document.ComponentSet("Table")

  Set columns = table.ColumnSet

  If columns.ItemByName("Height") < 0 Then

    Exit Sub ' no column with this name

  End If

  Set column = table.ColumnSet("Height")

  column.Name = "Renamed"

End Sub

This locates the table named 'Table', checks if it contains the column named 'Height', and if so, renames that column to 'Renamed'.

Hope this helps.

philw
88 post(s)
#12-Nov-18 06:48

Great, I'll have a go at making the "Renamed" be the active surface name in the script. Thanks for your help.

Manifold User Community Use Agreement Copyright (C) 2007-2017 Manifold Software Limited. All rights reserved.