Follow

How can I set my base map limits using the limits from my DXF file via Surfer automation?

This article contains a sample script for reading the true extents from the DXF file and using this information to set the base map limits. This is useful when the DXF file imports with large extents due to 3D extrusions or other unsupported objects.

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 14\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.
     

*********

'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 13, 2017

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.