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.

Loops in Precondition

Emily and I are trying to implement a variable amount of inputs in the precondition. 
We are trying to generate N amount of input boxes in the feature dialog that is based on the number N entered by the user in another dialog box. 
We have tried a for loop, and discovered that this is not possible. We get the error " nonconforming precondition: unexpected statement type (loop). 

Is there a way to have N boxes generated? Or a way for a user to input an array of values into one dialog box? 

Comments

  • dave_cowdendave_cowden Member, Developers Posts: 475 ✭✭✭
    Yeah, pretty sure you can't do that-- preconditions have to be predicates-- no loops are allowed.

    If you are writing a feature, you could try using the 'editing logic function', though, in which you can do arbitrary logic. You do that like this:

    annotation { "Feature Type Name" : "Your Feature" , "Editing Logic Function" : "yourEditLogicFunction" }

    Your function needs to be declared like this:

    export function yourEditLogicFunction(context is Context, id is Id, oldDefinition is map, definition is map,
                                  isCreating is boolean, specifiedParameters is map, hiddenBodies is Query) returns map { ... }

    It will be called whenever your feature inputs are edited, and there you can pretty much do whatever. 

    I used this approach as a work-around when I was needing to dynamically manipulate the inputs.

    HTH

  • john_f_carrjohn_f_carr Onshape Employees Posts: 74
    As far as the FeatureScript language is concerned preconditions can have loops, but preconditions with loops will not be recognized as feature specifications.
  • jacob_kingeryjacob_kingery Member Posts: 39 EDU
    I'm also curious about this. What's the best way to allow the user to input N lengths, for example?
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    There currently is no good way to do this.  You can't even condition visibility based on something other than an enum or a boolean.  You can imagine hacking hidden booleans set with editing logic, but that will not be a great user experience since round trips to the server will be required.  We intend to improve on this in the future.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • darren_13darren_13 Member, Developers Posts: 119 PRO
    I'm also interested this, I need to define like 4 identical parameters 'n' number of times. Might use the above-described method by @dave_cowden. David could I somehow have an enum from say 1-5 and edit the properties for each enum individually? so I change the parameters for '1' then move onto setting up the parameters for '2'? 

    Thanks in advance,
    Darren
Sign In or Register to comment.