Property DisplayName in object ScChartObj

A macro (basic) associated to a database needs to identify a chart from a calc document. This calc document may contain several charts, each having a specific name, as defined in the outermost layer of the chart.
Previously in OpenOffice this could be found by “DisplayName” in oChart object of type ScChartObj (as seen in the debugger) :

Function getChartByName (sheet As Object, chartName as String)
	dim oCharts, oChart
	dim i as integer
	oCharts = sheet.getCharts()
 	for i = 0 to oCharts.count-1
  		oChart = oCharts(i)
		if oChart.DisplayName=chartName then
  			getChartByName = oChart
  			Exit Function
  		end if
   	next i
	getChartByName = 0
End Function

When I migrated to LibreOffice the property DisplayName disappeared and I could not find a way to identify the chart. oChart still has a property Name containing (example) “OBJECT 2” over which I have no control in the calc document.

How to proceed ?

advTHANKSance

This seems to be a new feature in AOO 4.0 - the property didn’t exist in AOO 3.4. So - you could file an enhancement request to our bug tracker, mentioning the AOO support for the property.

Anyway, you may iterate over DrawPage, and check the objects’ Name property, if it has an embedded object, and if its component implements chart.

Function getChartByName2 (sheet As Object, chartName as String)
	dim oDrawPage, oObj
	oDrawPage = sheet.getDrawPage()
	for each oObj in oDrawPage
		if oObj.Name = chartName and oObj.supportsService("com.sun.star.drawing.OLE2Shape") then
			oObj = oObj.EmbeddedObject
			if not (oObj is Nothing) then
				oObj = oObj.Component
				if oObj.supportsService("com.sun.star.chart2.ChartDocument") then
					getChartByName2 = oObj
					Exit Function
				end if
			end if
		end if
	next oObj
	getChartByName2 = 0
End Function

This works somewhat.
Since the function returns a model, and I need a chart (ScChartObj) because the caller needs to change some ranges of the chart, I modified :

Function getChartByName (sheet As Object, chartName as String)
	dim oDrawPage, oObj
	oDrawPage = sheet.getDrawPage()
	for each oObj in oDrawPage
		if oObj.Name = chartName and oObj.supportsService("com.sun.star.drawing.OLE2Shape") then
		dim oEmbed
			oEmbed = oObj.EmbeddedObject
			if not (oEmbed is Nothing) then
			dim oCharts
				oCharts = sheet.getCharts()
				getChartByName = oCharts.getByName(oEmbed.EntryName)
				Exit Function
			
'				dim oComp
'				oComp = oEmbed.Component
'				if oComp.supportsService("com.sun.star.chart2.ChartDocument") then
'					getChartByName = oComp
'					Exit Function
'				end if
			end if
		end if
	next oObj
	getChartByName = 0
End Function