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.

feature script - extrude's entities queries

tonvistonvis Member Posts: 20

I am trying to create a script for springs. In partstudio it works ok with changing variables.

Now  working in feature script , I am not able to find the right  entity-query

I need three bodies for the later helix with a different pitch.
The extrude1,extrude2 and extrude3 should go on top of each other , but now they can only start  from sketch1

I have been studying all examples given in the Forum for weeks  but  still not solving the problem.
Also "Showcode" is not helping with this major question.

Can someone please help me out ?


Tagged:

Best Answers

Answers

  • tonvistonvis Member Posts: 20
    Many thanks Jake for your quick reply.
    It works now as I expected.

    The Feature "New -Spring" is the one which I am working on to automate.

    see

    If I go to Showcode in "New-spring " I get a good support as newcomer  when converting  numbers into strings

    Is it possible   that  in future Showcode translates  var TYBxWXmiEIHOwz_query;  in a human code. This would help anybody  working with Feature Script by  lack of examples.

                      TYBxWXmiEIHOwz_query=qCompressed(1.0,"%B5$QueryM6S12$disambiguationDataA1M2S12$disambiguationTypeS13$ORIGINAL_DEPENDENCYS9$originalsA1C0M5Sa$entityTypeBa$EntityTypeS4$EDGESb$historyTypeS8$CREATIONSb$operationIdB2$IdA1S11.6$FJT1fGBxE99GR2X_0wireOpS9$queryTypeSd$SKETCH_ENTITYSe$sketchEntityIdSc$U8ZJsa67bK1BR4C6S4$FACER6R7S7$isStartFR8CbA1S11.9$FCoRMGdkVgYr0oS_0opExtrudeRbS8$CAP_FACE",id);
                        annotation { "Feature Name" : "Extrude 2" }

    Regards
    Ton




  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,200
    Hi @tonvis

    Unfortunately, even if they were not compressed, the queries that you get when you interact with the Onshape ui are nothing like the ones that you use when programming in FeatureScript.  We use a number of different tricks to make downstream feature robust to upstream changes, and this ends up making ui queries pretty complicated.  The `show code` panel is pretty good for seeing what the inputs to a feature look like in FeatureScript code, but for some good examples of human-readable code you could take a look through any of these public custom features:
    https://www.onshape.com/features/custom-features

    Or even take a look through all of the code for the built-in features in the toolbar:
    https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/1609b2014b90745ff149a187
    Jake Rosenfeld - Modeling Team
  • tonvistonvis Member Posts: 20
    Hi Jake,
    Thanks for your answer.

    *    In  PartStudio  my " NewSpring"  is functioning OK with variable inputs

    *    see:https://cad.onshape.com/documents/aaf33b36515d458f14979723/w/38ba0931c4383130ad547336/e/92d15b1c456833375df278f5

       Now I am trying to get this working as a full Featurescript Function which is not so simple! by lack of examples.
    *   The problem is that none of  custom-features is giving an answer for my questions.
    *    With some help help from Onshape Forum and study Showcode in "NewSpring" , I hope that it is going to work.
    *    Supprisingly - using reverse engineering queries from Showcode are not giving errors , but also not solving the answer.

    *   I learned now that this is not the way to go.

    *   Will you please give me another push in the right direction with the following :
         Questions ? sweptface1_query , plane_query, centersnap_query, pierce_query, edge_query?

    *    All by all this could be a good example helping other people who are struggling  with FeatureScript

    tonvis







  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,200
    Hi @tonvis

    Here are a couple extra resources to help you:

    https://cad.onshape.com/FsDoc/library.html#qNothing - standard library documentation of all the types of queries you can use

    https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/9fde5dffaf8d4e4c99aaa22c - source code of the file where all the queries are defined

    For sweptface1_query, try using qNonCapEntity:
    https://cad.onshape.com/FsDoc/library.html#qNonCapEntity-Id-EntityType

    If you go and take a look at the precondition of helix, you can see which variables are required in the map and which aren't:
    https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/a80a05e9b600481ba245f9b3

    In this case, it looks like you want to be using TURNS rather than TURNS_PITCH as TURNS takes the "entities" parameter and TURNS_PITCH takes the "edges" parameter.  It is worth noting that the "show code" panel will fill in every possible input to the feature, even if those inputs aren't necessarily required.  By reading the source code or documentation of a FeatureScript function, you can see which inputs are required and which can be left out completely.

    Feel free to continue along the current path you are going down, but if I might make a suggestion: you can skip the three initial extrudes if you use "opHelix" rather than "helix":
    https://cad.onshape.com/FsDoc/library.html#opHelix-Context-Id-map

    In general, we recommend that FeatureScript users use "op" functions when possible, as they generally take simple mathematical inputs rather than geometric ones.  Onshape toolbar features (such as "helix") are somewhat more unwieldily to call because they are meant to take geometric selections from the user which are somewhat harder to manage from inside FeatureScript.  In general, Onshape features (extrude(...), revolve(...), draft(...)) have corresponding, easier to use, documented internal operations (opExtrude(...), opRevolve(...), opDraft(...)).

    By using opHelix directly you can skip the creation of any reference geometry, and define exactly the three helices you want to create.

    As far as the rest of those queries go, I would avoid writing sketch code in the way that you have written it.  When you are writing sketch code in FS, you do not need to use constrains or initial guesses.  All the sketching calls will allow you to create your desired geometry directly:
    https://cad.onshape.com/FsDoc/library.html#skPoint-Sketch-string-map

    One additional suggestion, it seems like you're following the pattern:
    var query = qCreatedBy(...);
    
    someFeature(context, id + "foo", { "parameter" : qUnion([query]) });
    qUnion is meant to combine an array of queries into a single query.  Since `query` already is a single query, you could just provide it directly:
    someFeature(context, id + "foo", { "parameter" : query });
    In a related vein, "qUnion([])" is functionally equivalent to "qNothing()", and in most cases where you provide qNothing, you can probably get away with not passing that parameter at all.

    Sorry if this answer was less helpful than I intended.  Feel free to respond with what you are still confused about, or with any further questions.

    Jake Rosenfeld - Modeling Team
  • tonvistonvis Member Posts: 20
    Hi Jake,
    Thanks for your help, I will try out your suggestions

    tonvis
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,200
    @tonvis

    Another resource for you.  Here is our FeatureScript tutorial:
    https://cad.onshape.com/FsDoc/tutorials/create-a-slot-feature.html
    Jake Rosenfeld - Modeling Team
  • tonvistonvis Member Posts: 20
    Hi Jake

    Taken your suggestions , I finally got a working FeatureScript for Springs.


    My question is howto display informativ data as Total length, Outside diameter etc produced by the feature in UI form

    I tried everything but only option is using UIHint which solves only one item.
    May be you can give me a hint.

    Best Regards
    tonvis



  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,200
    edited June 2018
    Hi @tonvis

    read-only fillable UI parameters are something we've been thinking about internally, but don't really exist right now.  I'm not sure if this is sufficient for you but you could do either of the following:

    • Print out the relevant information using println().  This information will be displayed in the FS console, which is available by hitting the "{✓}" button in the top right corner of your document.
    • Change the name of the part you create with setProperty().  You can change the name to anything you want, such as "14mm long 3mm wide spring" or something descriptive like that.
    If you really want to, you can create editing logic that backfills parameters to whatever value you want, but its pretty complicated, and the user will be able to edit those fields.  I can give an example of a feature that does this if you're interested in going down that path.

    See next post!
    Jake Rosenfeld - Modeling Team
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,200
    Jake Rosenfeld - Modeling Team
  • tonvistonvis Member Posts: 20
    Hi Jake

    Thanks for your helpfull answer,
    So " read-only fillable UI parametersis " are not yet  possible, but I will give your options  a  try and will see what is best alternativ.

    Regards
    tonvis

  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,200
    Hey @tonvis !

    Sorry for the confusion.  I did a strikethrough of my first post because read-only fillable UI parameters are totally possible! I just didn't realize we had already pushed that functionality.  My second post is an example of how to make one!
    Jake Rosenfeld - Modeling Team
  • tonvistonvis Member Posts: 20
    Hey Jake,
    Thanks for your help. 

    The example "editing logic" works and could be the answer  , also found a good  example in "Spurgear" .
    I do't  see any mistake in my source code but get a failure message  see:

    I can't figure out what Onshape means with that, do you ?

    I feel really good with Onshape !
    Best regards
    tonvisch




  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,200
    @tonvis

    I made a copy of your doc and tried out your feature, it looks like it's working fine now!  Are you still experiencing this issue?
    Jake Rosenfeld - Modeling Team
  • tonvistonvis Member Posts: 20
    Hey Jake,

    I found the mistake viz  typing error in:


     export function SpringEditing(context is Context, id is Id, oldDefinition is map, definition is map, isCreating is boolean) returns map
    {     // isCreating is required in the function definition for edit logic to work when editing an existing feature
        if (oldDefinition.effectiv_windings != definition.effectiv_windings )
        { 
           
            definition.l_Tot = definition.effectiv_windings *  definition.pitch + (2 * definition.pre_windings * definition.wire_dia);
                                                        ^ was a single f  ,   but no complains from compiler
          -
          -
          -
        }
    }
    Problem solved I feel sorry to bother you

    Best Regards
    tonvis
                                                        ^

  • tonvistonvis Member Posts: 20
    Hi Jake,

    The feature spring is working fine now.
    At the moment I am trying to construct a model airplane which I designed in 2004 on a Mac in Vellum 2D.
    Its difficult but a good learning fase. 6 August was my 80 year anniversery , still going strong !

    Best Regards
    tonvis
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,200
    Great stuff @tonvis !

    Glad to have you as part of the community.
    Jake Rosenfeld - Modeling Team
Sign In or Register to comment.