[OpenSCAD] taking customizer input and using it in a pair of nested loops

Parkinbot rudolf at parkinbot.com
Fri Apr 27 19:16:57 EDT 2018


I understand your problem that you want "parse" a string containing a
comma-separated list of numbers into a vector. In short  "2,4,11,8" ->
[2,4,11,8]. 
This is not so trivial. See the following code. 

a = "2,4,116,8";   // input
nums = "0123456789";  // helper

echo(parse(a)); 

function parse() = let(comma = [-1, each search(",", a, 0)[0], len(a)]) 
 [for(i=[0:len(comma)-2]) vec2num(digitvector(comma, i))]; 

function digitvector(comma, n) = [for(i=[comma[n]+1:comma[n+1]-1]) a[i]];
 
function vec2num(l, I=undef) = let(i=I==undef?len(l)-1:I)
  let(digit = search(l[i], nums, 0)[0][0])
   i>0 ? 10*vec2num(l, i-1)+digit: digit; 



--
Sent from: http://forum.openscad.org/



More information about the Discuss mailing list