Handling of Variants in CadnaA-Lua
Variants can be switched in CadnaA-Lua. In order to avoid confusion with active/inactive variants and variant numbering, the default access is realized with an iterator.
- i is variant number, starting from 1
- ´shortname´ is the short name of the variant (often V01, V02, ...)
- ´longname´ is the long name for the variant (or the short name if no long name is defined in CadnaA)
cna.variant.currentreturns the current variant. Write access is also implemented enabling to switch variants:cna.variant.current = 1orcna.variant.current = "V01"both select the first variant. Variants are numbered from 1 onwards, not zero.cna.variant.is_current_calculated()returns, whether the current variant is the one that has been calculated in the last calculation run.cna.variant.all()is an iterator returning up to 3 values for each active variant (i.e. skipping inactive ones). This is be the preferred way of selecting variants, since settingcna.variant.currentmanually can trigger errors (wrong variant number or name, variant not active, etc.).cna.variant.is_current_calculated()procedure which returns a boolean value (true or false) whether the current variant has been calculated or not.
Example: Calculating and saving grids for all active variants, but variant V03:
local i, shortname, longname
for i, shortname, longname in cna.variant.all() do
cna.print("V" .. i .. " with id: " .. shortname .. " and identifier " .. longname)
if shortname ~= "V03" then -- code here applies to all active variants but Variant 3
cna.calc_grid()
cna.save_grid("M:/grid_" .. shortname .. ".cnr");
end
end
The iterator cna.variant.all() iterates over all active variants. Within the for loop, they do not have to be assigned, yet as by example, they can provide useful information.