Arrays in Featurecript

wayne_jayes
wayne_jayes Member Posts: 13 ✭✭
In the php scripting language I can create a two dimensional array as follows:

$FlangePN10["15"] = array("OD" => 80,"THK" => 12, "NumHoles"=>4, "BHD"=>11,"PCD"=>55,"ID"=22);
$FlangePN10["20"] = array("OD" => 90,"THK" => 14, "NumHoles"=>4, "BHD"=>11,"PCD"=>65,"ID"=28);
$FlangePN10["25"] = array("OD" => 100,"THK" => 14, "NumHoles"=>4, "BHD"=>11,"PCD"=>75,"ID"=35);
.
.
$FlangePN10["250"] = array("OD" => 375,"THK" => 24, "NumHoles"=>12, "BHD"=>18,"PCD"=>335,"ID"=277);

and then be able to access the outside diameter of say, a DN20 flange as $FlangePN10["20"]["OD"] which would return the number 90. the flange thickness of a DN250 flange could be returned by $FlangePN10["250"]["THK"] and would be 24.

Could someone help with what the best syntax for this is in FeatureScript please?

Tagged:

Best Answers

  • kevin_o_toole_1
    kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565 image
    Answer ✓
    Better map documentation is here.

    For a nested map like you describe, you can do it all as a literal:

    var FlangePN10 = {
        "15" : { "OD" : 80,"THK" : 12, "NumHoles":4, "BHD":11,"PCD":55,"ID" : 22 },
        "20" : { "OD" : 90,"THK" : 14, "NumHoles":4, "BHD":11,"PCD":65,"ID" : 28 },
        "25" : { "OD" : 100,"THK" : 14, "NumHoles":4, "BHD":11,"PCD":75,"ID" : 35 }
    };
    

Answers

  • kevin_o_toole_1
    kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565 image
    Answer ✓
    Better map documentation is here.

    For a nested map like you describe, you can do it all as a literal:

    var FlangePN10 = {
        "15" : { "OD" : 80,"THK" : 12, "NumHoles":4, "BHD":11,"PCD":55,"ID" : 22 },
        "20" : { "OD" : 90,"THK" : 14, "NumHoles":4, "BHD":11,"PCD":65,"ID" : 28 },
        "25" : { "OD" : 100,"THK" : 14, "NumHoles":4, "BHD":11,"PCD":75,"ID" : 35 }
    };