'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
