hexagon logo

Writting of the '%' symbol with STR_SPRINTF command

Hello,
 
I am trying to write the results in the txt file with STR_SPRINTF command:
 
file text write file=(eval($_self.file_out)) newline=yes format=(eval(STR_SPRINTF("COG_height = %.2f ; %% %s", {$_self.GIRO_RIDE_Height, '[mm] COG height above road'})))
 
I have a problem with % symbol.
 
When I try to evaluate the function:
STR_SPRINTF("COG_height = %.2f ; %% %s", {$_self.GIRO_RIDE_Height, '[mm] COG height above road'})
in the function builder or in string variable then everything is working:
COG_height = 559.01 ; % [mm] COG height above road
 
When I use same expression in the macro, then I am getting an error message:
! ERROR: You have not supplied enough arguments for the given format writing to file "XYZ_Model_Report.txt" .
 
Does anybody has an idea what could be the reason for this behavior?
 
Thanks and best regards,
Ondrej
 
Parents
  • My usual approach when faced with such things is to introduce a backslash character to "escape" the problem character. So, for example try swapping %% with \% or \%\% or %\% - hack rapidly and then if it works, try to understand why afterwards.
     
    This approach comes from many years of working between the unix command line interpreter and shell scripts, which were infuriatingly similar but different. I suspect there is something about the way the function evaluator parses things (presumably interactively in A/View) and the way the macro command reader parses things non-interactively.
     
    You might also try examining the command window immediately after successfully evaluating the function; many times I have found the differences between what's in the function builder and what needs to go into a command file (usually quotes, escape characters, and so on) in this way.
     
    Let us know what you find.
     
    Damian
Reply
  • My usual approach when faced with such things is to introduce a backslash character to "escape" the problem character. So, for example try swapping %% with \% or \%\% or %\% - hack rapidly and then if it works, try to understand why afterwards.
     
    This approach comes from many years of working between the unix command line interpreter and shell scripts, which were infuriatingly similar but different. I suspect there is something about the way the function evaluator parses things (presumably interactively in A/View) and the way the macro command reader parses things non-interactively.
     
    You might also try examining the command window immediately after successfully evaluating the function; many times I have found the differences between what's in the function builder and what needs to go into a command file (usually quotes, escape characters, and so on) in this way.
     
    Let us know what you find.
     
    Damian
Children
No Data