Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
Pre selection logic?
MichaelPascoe
Member Posts: 2,012 PRO
I'm having trouble understanding how to export a function. Can someone give me some pointers?
Here is what I'm trying to do:
If you have pre selected a plane and a vertex, then click the feature, the feature will detect that you are wanting to use the "Up to vertex" method. I'm trying export these definitions so that the interface will show you what has been selected. When I'm not trying to export the definitions, the code works great, but I wan't the user to see which method is selected.
A summary of my attempt:
https://cad.onshape.com/documents/bdffe7bf48f3b4155e85d073/w/4aa864c3858500b61d8570f5/e/433e168b78be95d2d6e248ec
Here is what I'm trying to do:
If you have pre selected a plane and a vertex, then click the feature, the feature will detect that you are wanting to use the "Up to vertex" method. I'm trying export these definitions so that the interface will show you what has been selected. When I'm not trying to export the definitions, the code works great, but I wan't the user to see which method is selected.
A summary of my attempt:
https://cad.onshape.com/documents/bdffe7bf48f3b4155e85d073/w/4aa864c3858500b61d8570f5/e/433e168b78be95d2d6e248ec
annotation { "Feature Type Name" : "Section", "Auto Section Function" : "autoSection"} export const section = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Plane or face", "Filter" : GeometryType.PLANE || EntityType.VERTEX, "MaxNumberOfPicks" : 2 } definition.rootPlane is Query; //Required to create a drop down menu. annotation { "Name" : "Section method" } definition.sectionMethod is sectionMethod; if (definition.sectionMethod == sectionMethod.UPTOVERTEX) { annotation { "Name" : "Up to vertex", "Filter" : (EntityType.VERTEX), "MaxNumberOfPicks" : 1 } definition.limitEntity is Query; } } export function autoSection(context is Context, id is Id, oldDefinition is map, definition is map) returns map { if (oldDefinition != {}) // Only do anything on preselection return definition; //When I'm not trying to export, the following logic works great. if (size(evaluateQuery(context, definition.rootPlane)) == 2) { const autoVertex = qEntityFilter(definition.rootPlane, EntityType.VERTEX); const autoPlaneOrFace = qSubtraction(definition.rootPlane, autoVertex); if (size(evaluateQuery(context, autoVertex)) == 1 && size(evaluateQuery(context, autoPlaneOrFace)) == 1) { definition.sectionMethod = sectionMethod.UPTOVERTEX; definition.limitEntity = autoVertex; definition.rootPlane = autoPlaneOrFace; } } return definition; }
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Tagged:
0
Best Answer
-
Alex_Kempen Member Posts: 248 EDUWait, really? IIRC, there should be an option to mark a post as an answer if you've created the question. Maybe I'm wrong though?CS Student at UT DallasAlex.Kempen@utdallas.eduCheck out my FeatureScripts here:0
Answers
https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/577e2aaf45a542f98d9343c7
Onshape, Inc.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
It seems you've accidentally written "Auto Section Function" instead of "Editing Logic Function", so your editing logic function isn't actually running.
As a side note, one common technique I like to use when troubleshooting code is to insert print statements into sections of the code. I find this very helpful for troubleshooting since it can quickly tell you if a part of your code is actually running (but not behaving properly), which can help rule out possible issues. You can also print out values to see what information your FeatureScript is actually processing.
Edit: I had a brainfart and forgot how isCreating works. If you don't include it, the editing logic function only runs when a feature is created (i.e. before you click the checkmark once). Otherwise, the editing logic function will always run, regardless of whether the feature has been saved or not.
I can't go back and update "yes" this answered my question. If you post it again, I will click accept the answer, for the record.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴