From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Horizontally Centering Report Objects via Script

Solved!
Go to solution

Hello

 

I wanted to be able to programmatically center report objects, such as a text box and a 2D curve plots, with each other.

 

Thanks

 

DIAdem 2015 SP2 32 bit

 

 

Tim
0 Kudos
Message 1 of 2
(2,414 Views)
Solution
Accepted by smoothdurban

Center objects in Sheet center:

Dim oCtrl, PageWidth, ObjWidth
PageWidth = Report.ActiveSheet.Dimensions.Width
for each oCtrl in Report.ActiveSheet.Objects
	ObjWidth  = oCtrl.Position.ByCoordinate.Width
	oCtrl.Position.ByCoordinate.X1 = PageWidth / 2 - ObjWidth / 2
	oCtrl.Position.ByCoordinate.X2 = PageWidth / 2 + ObjWidth / 2
next
call Report.Refresh()

 Center objects at center of another object:

Dim oCtrl, CenterPos, ObjWidth, RefObject
set RefObject = Report.ActiveSheet.Objects("TextObject1")
CenterPos = RefObject.Position.ByCoordinate.X1 + RefObject.Position.ByCoordinate.Width / 2
for each oCtrl in Report.ActiveSheet.Objects
	if not oCtrl is RefObject then
		ObjWidth  = oCtrl.Position.ByCoordinate.Width
		oCtrl.Position.ByCoordinate.X1 = CenterPos - ObjWidth / 2
		oCtrl.Position.ByCoordinate.X2 = CenterPos + ObjWidth / 2
	end if
next
call Report.Refresh()
Christian
CLA, CTA, CLED
Message 2 of 2
(2,384 Views)