Follow

How can I change the fill and line properties for all objects at once via MapViewer automation?

This article contains a sample script for changing the fill of all closed objects and the line properties of all polyline and spline polyline objects.

 

To run this script:

  1. Copy the text below, from the Sub Main start line to the End Sub end line, or click here to download the BAS file: ChangeSharedProperties.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.

 

**************

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Change_Shared_Properties.bas
' Copyright (C) Golden Software Inc. 1992-2015
'
' Selects all closed shapes in the open GSM and changes the fill properties,
' then selects all closed shapes and lines and changes the line properties.
'
' ***To use this script:***
' Have MapViewer running with your GSM file open
' then run this script from within Scripter.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub Main

    Dim mvApp, Plot, CurrentLayer, MapShapes As Object
    Set mvApp = GetObject(,"MapViewer.Application")
    mvApp.Visible = True
	Set Plot = mvApp.ActiveDocument

	'Go through all the layers in the map
	For layerNum=1 To Plot.Layers.Count
		Set CurrentLayer = Plot.Layers.Item(layerNum)
		Set MapShapes = CurrentLayer.Shapes

		'Selects all closed shapes (polygons, spline polygons, rectangles, squares, rounded rectangles,
		'rounded squares, ellipses, circles) and changes the fill properties of all at once
		MapShapes.SelectByType(Area:=True, Rectangle:=True,	RoundedRect:=True, Square:=True, _
			Ellipse:=True, Circle:=True)
		For i=1 To CurrentLayer.Selection.Count 'Loop through the selected items and change their fill properties
			Set closedshape = CurrentLayer.Selection.Item(i)
			closedshape.Fill.Pattern = "Diagonal Cross"
			closedshape.Fill.ForeColor = mvColorBlue
		Next
		CurrentLayer.Selection.DeselectAll

		'Selects all closed shapes plus all polylines and spline polylines and changes the line properties
		MapShapes.SelectByType(Area:=True, Curve:=True, Rectangle:=True, RoundedRect:=True, _
			Square:=True, Ellipse:=True, Circle:=True)
		For i=1 To CurrentLayer.Selection.Count 'Loop through the selected items and change their line properties
			Set shapeswithline = CurrentLayer.Selection.Item(i)
			shapeswithline.Line.Style = ".1 in. Dash"
			shapeswithline.Line.color = mvColorRed
		Next
	Next

End Sub

Updated: September 17, 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.