Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Moving expression into group via macro

Hi everyone,

I want to create an expression and move it into a group via vb script. The only way of creating an expression is in my opinion:

set chart = ActiveDocument.GetSheetObject("TestChart")

chart.AddExpression "definition"

And I can get this expression by

set expressions = chart.GetProperties.Expressions

set newExpression =expressions.Item(expressions.count-1).Item(0)

Now I need to put this expression somehow into my group

set group expressions.Item(0)

But how? I would appreciate any help! Thanks

Adam

2 Replies
Not applicable
Author

Hey,

I found the Property "CycleGroup" in the Class "IExpressionData". Unfortunately the documentation is pretty poor, but after a while I discovered that all expressions in the first group have this parameter set to 0, second group has 1, ..., and all non-grouped expressions are set to -1.

So my next idea was to set this parameter for my additional expression to 0 (in order to put the expression in the first group). But invoking

ActiveDocument.GetSheetObject("TestChart").GetProperties.Expressions.Item(1).Item(0).Data.ExpressionData.CycleGroup = 0

does nothing, although the API guide says that I am allowed to write this parameter.

Any help??

Thanks,

Adam

Not applicable
Author

Turns out that QV Version 11 has an example in the API guide:

set chart = ActiveDocument.Sheets("Main").CreateBarChart
chart.AddDimension "ProductType"
chart.AddExpression "sum(Amount)"
chart.AddExpression "avg(Amount)"
set p = chart.GetProperties
p.Expressions.Item(0).Item(0).Data.ExpressionData.CycleGroup = 1
p.Expressions.Item(1).Item(0).Data.ExpressionData.CycleGroup = 1
p.ChartProperties.CycleExpressionDockedPos = 4   'undocked
p.ChartProperties.CycleExpressionRects.Add
p.ChartProperties.CycleExpressionRects(0).Left = 150
p.ChartProperties.CycleExpressionRects(0).Top = 150
p.ChartProperties.CycleExpressionRects(0).Width = 60
p.ChartProperties.CycleExpressionRects(0).Height = 60
chart.SetProperties p

FYI: Does not work with QV 10 or QV 11.