Set base map limits using the limits from a DXF file via Surfer automation

When working with a DXF file that contains 3D extrusions, the map limits in Surfer will often be much larger than intended because 3D extrusions are unsupported. The script below can be used to edit the limits of the resulting map to match the intended extents of the DXF.

To run this script:

  1. Copy the script below, or download the attached BAS file: DXF_Extent.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
  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. Open Surfer.
  7. Click Home | New Map | Base | Base, select the DXF file and click Open.
  8. Click Script | Run in Scripter to run the script.  The changes will be applied to the map you created in steps 6 & 7.

*********

'DxfExtents.bas reads the true extents from the DXF file and
' uses this information to set the base map limits. TB - 05 May 04.
'To use this script:
'1. Open Surfer
'2. Load the DXF file As a Base map
'3. Run this script, selecting the same DXF file.

Sub Main
	Debug.Print "----- ";Time;" -----"
	On Error GoTo errormessage
	Set surf = GetObject(,"surfer.application")
	Set plotdoc1 = surf.ActiveDocument
	Set shapes1 = plotdoc1.Shapes
	Set mapframe1 = shapes1("map") 'Base map must be displayed in current doc window.
	path1 = "c:\incoming\"
	file1 = GetFilePath("crater map2.dxf","dxf",path1,"Get DXF File")
	If file1 = "" Then End
	Debug.Print file1;" ";Format(FileLen(file1),"0,0"); " bytes"
	Open file1 For Input As #1
	While Not EOF(1)
		Line Input #1,a
		If a = "$EXTMIN" Then
			Debug.Print a; " (should be $EXTMIN)"
			Line Input #1, a 'should be 10.
			Debug.Print a;" (Should be 10.)
			Line Input #1,dxfxmin
			Debug.Print dxfxmin; " (Should be dxfxmin.)
			Line Input #1,a 'should be 20.
			Debug.Print a; " (Should be 20.)
			Line Input #1, dxfymin
			Debug.Print dxfymin; " (Should be dxfymin.)
			Line Input #1, a
			Debug.Print a;" (Should be 30.)
			Line Input #1, a
			Debug.Print a;" (Should be dxfzmin.)
			Line Input #1, a
			Debug.Print a;" (Should be 9.)
			Line Input #1, a
			Debug.Print a;" (Should be $EXTMAX.)
			Line Input #1, a
			Debug.Print a;" (Should be 10.)
			Line Input #1, dxfxmax
			Debug.Print dxfxmax;" (Should be dxfxmax.)
			Line Input #1, a
			Debug.Print a;" (Should be 20.)
			Line Input #1, dxfymax
			Debug.Print dxfymax;" (Should be dxfymax.)
			Line Input #1, a
			Debug.Print a;" (Should be 30.)
			Line Input #1, dxfzmax
			Debug.Print dxfzmax;" (Should be dxfzmax.)
			Exit While  'exit the while loop.
		End If
	Wend
	'On Error Resume Next
	'Set mapframe1 = shapes1.AddBaseMap(file1)

	With mapframe1
		.SetLimits(dxfxmin,dxfxmax,dxfymin,dxfymax)
		If dxfxMax - dxfxMin > dxfyMax - dxfyMin Then
			.xLength = 6
			.yMapPerPU = .xMapPerPU
		Else
			.yLength = 6
			.xMapPerPU = .yMapPerPU
		End If
	End With
	End
	errormessage:
	MsgBox("Open Surfer, create a base map from the DXF," + vbCrLf + _
		"and run DxfExtents.bas in Surfer Scripter.",vbOkOnly, _
		"Error")

End Sub

 

Updated February 2021

Was this article helpful?
1 out of 1 found this helpful

Comments

0 comments

Please sign in to leave a comment.