Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:

  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Arrays in Featurecript

wayne_jayeswayne_jayes Member Posts: 13 PRO
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_1kevin_o_toole_1 Posts: 455
    Accepted 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_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 455
    Accepted 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 }
    };
    

Sign In or Register to comment.