Button press required twice to update values

I have some plot update code to alter the axis limits that takes two button pushes to update the variables I'm using to store the axis limit values.

The plot updates on the first button push. The variables xrdYAxisMin and xrdYAxisMax don't update until I push the button again.

I want to track the values of the axes so I can do other things with them.

What am I doing wrong?

A minimised version of the code is:

//---------------------------------------------------------------------------

function updateCWTWindowProc(ctrlName) : ButtonControl
	String ctrlName

	NVAR xAxisMin   =root:Packages:PeakPanelFolder:xAxisMin
	NVAR xAxisMax   =root:Packages:PeakPanelFolder:xAxisMax
	NVAR xrdYAxisMin =root:Packages:PeakPanelFolder:xrdYAxisMin
	NVAR xrdYAxisMax =root:Packages:PeakPanelFolder:xrdYAxisMax 
	

	//Data window
	SetActiveSubwindow PeakPanel#G1

	SetAxis/A=2 //autoscales the Y axis to match the values in the current X range
	SetAxis bottom xAxisMin,xAxisMax
	GetAxis /Q left
	xrdYAxisMin = V_min
	xrdYAxisMax = V_max

end

//---------------------------------------------------------------------------



.


Full code for the button if I mangle the above:

//---------------------------------------------------------------------------

function updateCWTWindowProc(ctrlName) : ButtonControl
	String ctrlName

	Variable autoScaleInt=0
	ControlInfo/W=PeakPanel peakAutoScaleIntCheck
	if(V_Value)
		autoScaleInt=1
	endif

	NVAR cwtColour  =root:Packages:PeakPanelFolder:cwtColour

	NVAR xAxisMin   =root:Packages:PeakPanelFolder:xAxisMin
	NVAR xAxisMax   =root:Packages:PeakPanelFolder:xAxisMax
	NVAR xrdYAxisMin =root:Packages:PeakPanelFolder:xrdYAxisMin
	NVAR xrdYAxisMax =root:Packages:PeakPanelFolder:xrdYAxisMax 
	NVAR cwtYAxisMin =root:Packages:PeakPanelFolder:cwtYAxisMin
	NVAR cwtYAxisMax =root:Packages:PeakPanelFolder:cwtYAxisMax
	
	//CWT window
	SetActiveSubwindow PeakPanel#G0
	ModifyImage M_CWT ctab= {-cwtColour,cwtColour,RedWhiteBlue,0}
	SetAxis bottom xAxisMin,xAxisMax
	SetAxis left cwtYAxisMin, cwtYAxisMax

	//Data window
	SetActiveSubwindow PeakPanel#G1

	if(autoScaleInt)
		SetAxis/A=2 //autoscales the Y axis to match the values in the current X range
		SetAxis bottom xAxisMin,xAxisMax
		GetAxis  left
		xrdYAxisMin = V_min
		xrdYAxisMax = V_max
	else
		//Need a way to preserve the values that I already have
		SetAxis /A //clears any previous autoscaling
		SetAxis left xrdYAxisMin, xrdYAxisMax
		SetAxis bottom xAxisMin,xAxisMax
	endif
	
		
	SetActiveSubwindow PeakPanel
		
end

//---------------------------------------------------------------------------

The problem probably is that you call
GetAxis
before the update happens (which is after the function ends). You need to force the graph (and with it the axis range) to update before fetching the new values with
GetAxis
(or else you will get the old ones). Squeeze a
DoUpdate
in before and you should be good to go. By the way, you don't use
GetAxis/Q
not litter the history window?
Gah!
DoUpdate
works a charm.

GetAxis/Q
not litter the history window?

Yes it does litter, but I was trying to debug, so I wanted the rubbish.
/Q
is now inserted.