05-18-2017 04:58 AM
Hello,
let's say I have a simple report sheet with one x-y-plot on it and the curves are referenced to a singe channel group. Now i Import/create a new channel group with exactly the same structure and I copy the report sheet. Is it possible to change all curve references to the new channel Group?
(I know, if I keep the report layout and load the data for each layout I would have the same report for each data, but that's not the way I Need)
Solved! Go to Solution.
05-18-2017 07:32 AM
Hi,
You can create a copy of a report sheet and then change all curve references like this:
dim oNewSheet, oCurve
set oNewSheet = Report.Sheets.Copy(1, "Copy", 2)
'iterate all curves in the axis system of the copied report sheet
for each oCurve in oNewSheet.Objects("2DAxis1").Curves2D
oCurve.Shape.XChannel.Reference = 'add new x channnel ref. here as text
oCurve.Shape.YChannel.Reference = 'add new y channnel ref. here as text
next
You need to write the new channel reference as a text like this: "[2]/xChannel", "[2]/yChannel"
05-18-2017 07:48 AM
Hi,
i know it's possible to change the reference in general by using ".Reference" - that's like you select the channel in the Editor:
And your code is exactly the way I have implemented this already, but you have to scan each Object and rename the reference.
One hint: XChannel.Reference and YChannel.Reference is not available for Shapes of e2DShapeConstant and e2DShapeCoordinate!
But I was searching for a faster way to rerefence all objects on the sheet?
05-18-2017 08:33 AM - edited 05-18-2017 08:38 AM
I think there is nothing like a one line solution for that as the channel references are saved as strings.
Probably the easiest solution would be to scan the references for a group index and to replace it using string operations like this (just an example for one curve):
Dim o2DCurve
Set o2DCurve = Report.ActiveSheet.Objects("2DAxis1").Curves2D("2DAxis1_Curve1")
call ChangeIndex(o2DCurve,2)
sub ChangeIndex(oCurve, newIdx)
dim ChnRefTxt : ChnRefTxt = oCurve.Shape.XChannel.Reference
oCurve.Shape.XChannel.Reference = "[" & newIdx & "]" & Mid(ChnRefTxt, InStr(1,ChnRefTxt,"]")+1)
end sub
But this only works if you have name oriented references activated in your report sheet (not number oriented).
And only if there is a group index based reference syntax used in all report objects (if group names are used you have to search for the "/" character instead of "]").
Another approach is to determine the channel object for each curve reference like this:
set oXChn = Data.GetChannel(oCurve.Shape.XChannel.Reference)
and then extract channel name / index and group name / index using the Properties of the channel object and concatenate it with new index / name.
But this only works if your channels really exist in the data portal.
If they do not exist in the data portal I do only see string operations as a possible solution.
Regards
05-29-2017 01:30 AM
Dear Christian,
your idea (1) is probably the best, but i won't use "&Mid(..)" here because if there is no index based reference at all, the new reference will be "[newIdx]" and the old Information will get lost.
So my approach for rereferencing a new channel group to sheet/report file looks like this:
- assumption is that a layout only references to channel group [1]
- there is a new channel group that sould be shown on the same layout
- copy the layout (optional)
- rename the sheet(s) and object references
'Report.LoadLayout(myReportLayout) 'needed if you don't load manually
'get index of new group (here: default group)
set ActiveChnGrp = Data.Root.ActiveChannelGroup
iNewGrpIdx = ActiveChnGrp.Properties("Index").Value
sNewGrpName = ActiveChnGrp.Properties("Name").Value
'copy layout
orgSheetsCnt = Report.Sheets.Count
Report.AppendLayout(myReportLayout)
newSheetsCnt = Report.Sheets.Count
'get sheets and references and set to new group (sNewGrpName)
for cnt = (orgSheetsCnt + 1) to newSheetsCnt
set rSheet = Report.Sheets.Item(cnt)
rSheet.Name = Replace(sHlp, " (2)", "-"&sNewGrpName)
set rObjects = rSheet.Objects
'get objects and replace references
for each rObject in rObjects
'search for 2d-axis-systems on the sheet
if (rObject.ObjectType = eReportObject2DAxisSystem) then
set rCurves = rObject.Curves2D
for each rCurve in rCurves 'search for curves on the 2d-axis-system
if not (rCurve.ShapeType = e2DShapeConstant) and not (rCurve.ShapeType = e2DShapeCoordinate) then 'reference is not available for constants and coordinates
rCurve.Shape.XChannel.Reference = Replace(rCurve.Shape.XChannel.Reference, "[1]", "["&iNewGrpIdx&"]")
rCurve.Shape.YChannel.Reference = Replace(rCurve.Shape.YChannel.Reference, "[1]", "["&iNewGrpIdx&"]")
end if
next
end if
'search for text on the sheet
if (rObject.ObjectType = eReportObjectText) then
rObject.Text = Replace(rObject.Text, "[1]", "["&iNewGrpIdx&"]")
end if
'...search for other object containing references to group index '[1]'
next
next