Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape, CAD, maker project and design.

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.

For loop for annotation creation in FS

florianflorian Member, OS Professional, Release Management EVP Posts: 95 PRO
My plan: I just wanted to create quick new version of the "Part Number" property example FS.

When I looked at the code I was suprised by the extreme repetition in the code. I think it could be solved with a few small lists. But it seems that the limitation is annotation creation that does not accept for loops.

annotation { "Feature Type Name" : "Part Number" }
export const partNumber = defineFeature(function(context is Context, id is Id, definition is map)
        ...ORIGINAL CODE...
            for (var i = 1; i <= 3; i += 1)

The original: 
My start incl. error: https://cad.onshape.com/documents/6d98f6b9970b451ad1ea02d9/w/f2d80f916670b2e22b04c23d/e/19b6147f5e63fff7f36abbe5


  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers Posts: 339
    edited March 12
    Our approach to handling varying parameter multiplicity in feature dialogs is array parameters. Documentation is here. They do use a for loop, just with slightly different syntax  :)

    I believe Ilya didn't use array parameters in that example because right now, they can't be configured (If you want this functionality, please request it!) 
  • mahirmahir Member, Developers Posts: 663 ✭✭✭✭
    Not sure it's exactly the same thing as configurable array parameters, but  you can vote for my improvement request for conditional visibility of inputs in array parameters. Making them configurable would fix that, too.

  • florianflorian Member, OS Professional, Release Management EVP Posts: 95 PRO
    Thanks for the help! That worked well.
    See the result: https://cad.onshape.com/documents/6d98f6b9970b451ad1ea02d9/w/f2d80f916670b2e22b04c23d/e/be217d6c0f6b483e0594d33a

    Offtopic: However I'm confused with the toString parsing. An isAnything with the value "diameter in mm" will be parsed as "diameter *inch *millimeter" => See entered values in V1 of the doc. Expected "diameter in mm"

    Offtopic 2: Any way to insert whitespace in a partname as separator? I tried setting tefault to " " but it does not work.
  • florianflorian Member, OS Professional, Release Management EVP Posts: 95 PRO
    I added two nasty workarounds to get what I want from my two offtopics above. Any ideas for a cleaner implementation are appreciated.
Sign In or Register to comment.