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.
Collaboration Time!!!
Dylan_Stewart
Member, Developers Posts: 107 PRO
Okay Ladies and Gents,
I am wanting to create a dummy proof table, meaning that the user is only going to have certain options to choose from and BAM, they get a modeled table. I've got some of the code and some of the parts but really need the support of the community to finish this off. Yes, I admit, I am wanting to use this as a learning experience but I thought this would be a good idea to start using OnShape and FS to it's potential.
I have the table top already made and I have a separate feature to bring in the legs... While this is fine, it's not %100 what I am after.
Here is the link to the document
https://cad.onshape.com/documents/986d7839f605b08daf5b62c4/w/99657d4a66565336c6f8f2ed/e/37a9ad7c057bbfc7f7a76bb5
Here is the code to create the table top
The problem is that I want to eliminate all mouse clicks and be able to toggle between different legs.
Any and all help is appreciated.
Thank you
I am wanting to create a dummy proof table, meaning that the user is only going to have certain options to choose from and BAM, they get a modeled table. I've got some of the code and some of the parts but really need the support of the community to finish this off. Yes, I admit, I am wanting to use this as a learning experience but I thought this would be a good idea to start using OnShape and FS to it's potential.
I have the table top already made and I have a separate feature to bring in the legs... While this is fine, it's not %100 what I am after.
Here is the link to the document
https://cad.onshape.com/documents/986d7839f605b08daf5b62c4/w/99657d4a66565336c6f8f2ed/e/37a9ad7c057bbfc7f7a76bb5
Here is the code to create the table top
FeatureScript 392; import(path : "onshape/std/geometry.fs", version : "392.0"); export enum TableTopSize { annotation {"Name" : "24 inch"} ONE, annotation {"Name" : "30 inch"} TWO, annotation {"Name" : "36 inch"} THREE, annotation {"Name" : "42 inch"} FOUR, } export function evTableTopSize(value is TableTopSize) { return { "ONE" : 24*inch, "TWO" : 30*inch, "THREE" : 36*inch, "FOUR" : 42*inch }[value as string]; } annotation { "Feature Type Name" : "Table Creator" } export const myTableCreator = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Table Top Size" } definition.tableTopSize is TableTopSize; } { var tableTop = evTableTopSize(definition.tableTopSize); var legLoc1 = 4*inch; var legLoc2 = tableTop - 4*inch; var tableVerticies = [vector(0*inch, 0*inch), vector(0*inch, tableTop), vector(tableTop, tableTop), vector(tableTop, 0*inch)]; var legLocationVerticies = [vector(legLoc1, legLoc1), vector(legLoc1, legLoc2), vector(legLoc2, legLoc1), vector(legLoc2, legLoc2)]; var tableSketch = newSketch(context, id + "TableSketch", { "sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE) }); skLineSegment(tableSketch, "line1", { "start" : tableVerticies[0], "end" : tableVerticies[1] }); skLineSegment(tableSketch, "line2", { "start" : tableVerticies[1], "end" : tableVerticies[2] }); skLineSegment(tableSketch, "line3", { "start" : tableVerticies[2], "end" : tableVerticies[3] }); skLineSegment(tableSketch, "line4", { "start" : tableVerticies[3], "end" : tableVerticies[0] }); skCircle(tableSketch, "Leg1", { "center" : legLocationVerticies[0], "radius" : 1 * inch }); skCircle(tableSketch, "Leg2", { "center" : legLocationVerticies[1], "radius" : 1 * inch }); skCircle(tableSketch, "Leg3", { "center" : legLocationVerticies[2], "radius" : 1 * inch }); skCircle(tableSketch, "Leg4", { "center" : legLocationVerticies[3], "radius" : 1 * inch }); skSolve(tableSketch); var tableRegion = qSketchRegion(id + "TableSketch"); extrude(context, id + "extrude1", { "entities" : qSketchRegion(id + "TableSketch"), "endBound" : BoundingType.BLIND, "depth" : 1.5 * inch }); });And here is what I have to bring in the leg
FeatureScript 392; import(path : "onshape/std/geometry.fs", version : "392.0"); PART::import(path : "b0ce9ce1e52b3c3c2503487d", version : "2e1edf42723d4d88750dd977"); // PART::import(path : "1c26e00fc778219a6a385f3a", version : "f71775f0a10f7cfd8dbea65b"); // PART::import(path : "c79f1a234a9f7dcf3cd1da1e", version : "60326f3c3ce5854d658b085b"); // export enum LegOptions // { // annotation {"Name": "Round Leg 1"} // FpDkrwSQ3HtgoSB_1, // annotation {"Name": "Round Leg 2"} // FTDZgmKUHISz1PO_0, // annotation {"Name": "Round Leg 3"} // FhcUhDPPvmJadnm_0 // } annotation { "Feature Type Name" : "Import Leg" } export const myFeature = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Point", "Filter" : EntityType.VERTEX, /*"MaxNumberOfPicks" : 1*/ } definition.point is Query; // annotation { "Name" : "Leg Choice" } // definition.legChoice is LegOptions; } { var transforms = []; var point = definition.point; opMergeContexts(context, id + "mergeContexts1", { "contextFrom" : PART::build() }); var importedPart = qCreatedBy(id + "mergeContexts1", EntityType.BODY); var location = evVertexPoint(context, { "vertex" : point }); var origin = vector(0, 0, 0) * inch; opTransform(context, id + "transform1", { "bodies" : importedPart, "transform" : transform(location - origin) }); });
The problem is that I want to eliminate all mouse clicks and be able to toggle between different legs.
Any and all help is appreciated.
Thank you
Digital Engineering
0
Comments
A while back, I was thinking chest of drawers created completely with FS but it needs some serious coding to create slides etc. so I came up with idea to combine FS with parametric model
I admit, I need to brush up on my coding and maybe even take a few more classes so that I understand everything.
So I will have to apologize up front for the waves of questions I will have throughout this process.
What I lack in knowledge I more than make up for in enthusiasm.
But I'm very interested in use cases, so I would also like to see an example of what I suggested (if it's possible).
This is only the beginning and I am looking forward to elaborating and collaborating on this project.
Here is the code to generate a table with only 2 options.
Please let me know what you all think!!
@lougallo
thanks for this example, I suppose you 'modeled' table top with FS code? Is it possible to do the same so that you have table top in one part studio and you use variables to control the size?
I get the feeling that it is just around the corner.
can you explain why this will not work if I change the sketchPlane?
from:
to:
What if a user wanted to use the 'Front' plane?
Further more, if the user wanted to make a symmetric part and place legs on the bottom and plates on the top?
Edit: Also the orientation of the derived/imported part, for example I want the legs to come in rotated 45 degrees.
I don't want to change the derived part, rather just place it on an exact point and plane (whether its on the top or bottom) and if the base sketch, in this case the table top, if it's on the top, front or right plane and then rotate the legs.
The reason I would like to import parts rather than writing in code is to be able to import complicated parts that would require too much code to write (if it's even possible)
Forgive me if I am misunderstanding something.
I have a FS that creates a rectangle on the 'Front' plane and has circle cut outs that can be either on the right or left.
I have a PS that is not ambidextrous (there for would have to be rotated 180 degrees depending on the side.
Also, my rectangle is extruded symmetrically. So I would like to be able to imported part follow the desired face.
Since we can not control variables from PS through FS, I figured this might be a sort of work around (if at all possible to do the above mentioned)
I'm now wondering if the 'opTransform' can be simplified?