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.
How do I find the distance between two planes?
Kira_Lee
Member, Developers Posts: 17 PRO
The user chooses a plane to draw on (it will be parallel to one of the three given planes - Front, Top or Right). From this, I want to be able to change the y- coordinate in a sketch based off of this length value. It isn't going through my if statements and it's just using "X" that I set above it. I have tried using boxDis in my if statement instead because I would think Vec is redundant, but this didn't work either. I am new to Feature Script, so any help would be greatly appreciated.
var realPlane = evPlane(context, {
"face" : definition.myPlane});
//should return a 3D vector where 2 values are 0var Vec = planeToWorld(realPlane, vector(0, 0) * inch);//Predefines the variable Xvar X is number = 0;if (Vec[0] != 0){var X is number = 0;}if (Vec[1] != 0){var X is number = 1;}else{var X is number = 2;}//sets the distance between our plane and the origin as a vector (we take the z coordinate)var boxDis = project(realPlane, vector(0, 0, 0) * inch);
//Create sketchvar champSketch = newSketch(context, id + "champSketch", {"sketchPlane" : qCreatedBy(makeId("Front"), EntityType.FACE)});skLineSegment(champSketch, "ChampLine1", {"start" : vector(definition.OuterDiameter / 2, boxDis[X]),"end" : vector(definition.OuterDiameter / 2 - (0.117 * inch), boxDis[X])});
0
Comments
//sets the distance between our plane and the origin as a vector (we take the z coordinate)
if (Vec[0] != 0)
For efficiency, learning how to use java script functions will help in cases similar to this.
One way to simplify your code would be to create your variables outside the if statements, then, define the variables inside the if statements. This will let you create the sketch once while letting the variable change depending on the statement.
Example:
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
oops, didn't see that those were the same.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴