If I correctly understood your needs, the following should do what you want:
\documentclass{article}
\usepackage{datatool}
\usepackage[strict]{changepage}
\usepackage{filecontents}
\usepackage{tcolorbox}
\usepackage[absolute,overlay]{textpos}
\usepackage{xcolor}
\usepackage{xparse}
\begin{filecontents*}{test1.csv}
Acol, Bcol,Ccol
Ax,Bx,1
Ay,By,3
A1,B22,1
A2,B44,2
A3,B11,3
\end{filecontents*}
% If you include a line such as 'A4,B55,4' without saying how \xLength and
% \yLength should be set in this case, you'll get the error message:
%
% Package lforti Error: Encountered value '4', but no case was written for it.
\DTLloaddb{mydata1}{test1.csv}
\newlength{\xlengthForOddPages}
\newlength{\xlengthForEvenPages}
\newlength{\ylengthForOddPages}
\newlength{\ylengthForEvenPages}
\setlength{\xlengthForOddPages}{2cm}
\setlength{\xlengthForEvenPages}{10cm}
\setlength{\ylengthForOddPages}{1.5cm}
\setlength{\ylengthForEvenPages}{5cm}
\newif\ifmyoddpage % always set globally, contrary to \ifoddpage
\newcommand*{\xpageDependent}{%
\ifmyoddpage
\expandafter
\xlengthForOddPages
\else
\expandafter
\xlengthForEvenPages
\fi
}
\newcommand*{\ypageDependent}{%
\ifmyoddpage
\expandafter
\ylengthForOddPages
\else
\expandafter
\ylengthForEvenPages
\fi
}
\newcommand*{\mycheckoddpage}{%
\checkoddpage
\global\let\ifmyoddpage=\ifoddpage
}
\ExplSyntaxOn
\msg_new:nnn { lforti } { unhandled-value }
{ Encountered~value~'\exp_not:n~{#1}',~but~no~case~was~written~for~it. }
\tl_new:N \l__lforti_cond_length_setup_conds_tl
\seq_new:N \l__lforti_cond_length_setup_tmpa_seq
\seq_new:N \l__lforti_cond_length_setup_tmpb_seq
% Flexible length setup that may depend on whether it is called on an odd page
% or on an even page.
%
% #1: a LaTeX length command (or a TeX \skipdef token) to set according to
% #2 and #3
% #2: the value to test against
% #3: a comma list describing the different cases:
%
% {
% {value_1, length-for-odd-pages, length-for-even-pages},
% {value_2, length-for-odd-pages, length-for-even-pages},
% ...
% {value_n, length-for-odd-pages, length-for-even-pages},
% }
%
% #2 is compared against value_1, value_2, ..., value_n to determine a
% matching “line”, then length command #1 is set to the length-for-odd-pages or
% length-for-even-pages of the matching line, depending on whether the label set
% by \checkoddpage (used at the beginning of the function) is located on an
% odd page or on an even page.
\cs_new_protected:Npn \lforti_cond_length_setup:Nnn #1#2#3
{
\checkoddpage % make sure it is used on the relevant page
\seq_set_from_clist:Nn \l__lforti_cond_length_setup_tmpa_seq {#3}
\tl_clear:N \l__lforti_cond_length_setup_conds_tl
\seq_map_inline:Nn \l__lforti_cond_length_setup_tmpa_seq
{
\seq_set_from_clist:Nn \l__lforti_cond_length_setup_tmpb_seq {##1}
\tl_put_right:Nx \l__lforti_cond_length_setup_conds_tl
{
% Value to check against
{ \seq_item:Nn \l__lforti_cond_length_setup_tmpb_seq { 1 } }
{ % Corresponding setup code for #1
\exp_not:n { \skip_set:Nn #1 }
{
\seq_item:Nn
\l__lforti_cond_length_setup_tmpb_seq
{ \ifoddpage 2 \else 3 \fi }
}
}
}
}
% Handle value #2 according to the cases described by
% \l__lforti_cond_length_setup_conds_tl, which was assembled from #3
\str_case:nVF {#2} \l__lforti_cond_length_setup_conds_tl
{ \msg_error:nnn { lforti } { unhandled-value } {#2} }
}
\cs_generate_variant:Nn \lforti_cond_length_setup:Nnn { Nx }
% Same as \lforti_cond_length_setup:Nnn (see above), except that the second
% argument will be fully expanded (\lforti_cond_length_setup:Nnn will only see
% the *result* of this expansion in its #2).
\NewDocumentCommand \lforticondlengthsetup { m m m }
{
\lforti_cond_length_setup:Nxn #1 {#2} {#3}
}
\ExplSyntaxOff
\newlength{\xLength}
\newlength{\yLength}
\begin{document}
\DTLforeach*{mydata1}{\A=Acol,\B=Bcol,\C=Ccol}%
{%
\lforticondlengthsetup{\xLength}{\C}{%
{1, 2cm, 4cm}, % When \C expands to 1, use 2cm on odd pages, 4cm on even pages
{2, 3cm, 5cm}, % When \C expands to 2, use 3cm on odd pages, 5cm on even pages
{3, 4cm, 4cm}, % When \C expands to 3, use 4cm on all pages
}%
\lforticondlengthsetup{\yLength}{\C}{% analogous setup for \yLength
{1, 1.5cm, 2cm},
{2, 2cm, 3cm},
{3, 3cm, 1.5cm},
}%
\begin{textblock*}{5cm}(\xLength,\yLength)
\color{blue!50!black}%
\noindent
\texttt{\string\xLength} = \the\xLength\\
\texttt{\string\yLength} = \the\yLength
\end{textblock*}
\begin{tcolorbox}[phantom={\mycheckoddpage},
width=\xpageDependent,height=\ypageDependent,
title={Title}]
\C
\end{tcolorbox}
\newpage
}
\end{document}
Here is the top of each page:





My code relies on a flexible length-setting command that I called \lforticondlengthsetup. This commands expects its first argument to be a LaTeX length command (or a TeX \skipdef token). It fully expands its second argument and compares the result against the first element of each sublist specified in the third argument. For instance, \xLength and \yLength are set this way to follow the specifications from your question:
\lforticondlengthsetup{\xLength}{\C}{%
{1, 2cm, 4cm}, % When \C expands to 1, use 2cm on odd pages, 4cm on even pages
{2, 3cm, 5cm}, % When \C expands to 2, use 3cm on odd pages, 5cm on even pages
{3, 4cm, 4cm}, % When \C expands to 3, use 4cm on all pages
}%
\lforticondlengthsetup{\yLength}{\C}{% analogous setup for \yLength
{1, 1.5cm, 2cm},
{2, 2cm, 3cm},
{3, 3cm, 1.5cm},
You have to ensure that such length setup commands are issued on the same page where \xLength and \yLength are used. This should be the case in the full document I gave above.
The length values (second and third element of each sublist present in the third argument of \lforticondlengthsetup) can be anything that is a valid LaTeX3 〈skip expression〉. For instance, the following code is valid as long as:
\xLength and \yLength have been declared with \newlength;
\someMacro recursively expands to either 1, or foo, or bar baz (in your example, this role is played by the \C macro that expands to values located in the third column of your .csv file).
\lforticondlengthsetup{\yLength}{\someMacro}{
{1, 0.7\xLength, 2cm plus 0.1cm minus 0.2cm},
{foo, 2cm plus 1fill, 0pt plus 3fill},
{bar baz, 3cm plus 1fil minus 0.2fill, 1.5cm},
}
Finally, since \checkoddpage uses a label/ref mechanism, don't forget that you need to compile several times—normally only twice—to get reliable results!
tcolorboxshould be the same as the horizontal offset of your text positioned withtextblock*(your example and text before the example use\xpageDependentfor both)? Same question for\ypageDependent, of course. (Also,\xpageDependentand\ypageDependentshould be used only we you can be sure that the most recent call to\mycheckoddpageplaced its internal label on the same page. I assume this is the case here for their second use, i.e., in the arguments of\begin{textblock*}. – frougon Jul 13 '19 at 12:37textblock*is on the same page as the correspondingtcolorbox.) Or maybe you want different lengths, but obtain these through a redefinition of\xpageDependentand\ypageDependentbetween thetcolorboxand when thetextblock*is set up? – frougon Jul 13 '19 at 12:48tcolorboxdoesn't seem to play a significant role here, I believe one might want to remove it from the question. Of course, the screenshots in my answer would then need to be redone (changing the code is quicker)... – frougon Jul 13 '19 at 18:51