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 to mirror an object without copying it?
blackslate
Member Posts: 16 ✭
I want to move an object into its position in a mirror defined by an arbitrary plane. I do not want to create a copy.
Below is how I can achieve this using opPattern, and then deleting the original. Is there a more elegant way?
On this page, from 2017, Jake_Rosenfeld suggested to try something like this...
mirror(context, id + "mirror1", { "patternType" : MirrorType.PART, "entities" : someQueryForEntities, "mirrorPlane" : someQueryForTheMirrorPlane });
... but this is no shorter* and also creates a copy, as you can see here.
(*Perhaps it is more efficient?)
You can see my working (but inelegant) version in action here.
FeatureScript 2066;
import(path : "onshape/std/common.fs", version : "2066.0");annotation { "Feature Type Name" : "Mirror Test" }
export const mirrorTest = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{}
{
const goldenRatio = (1 + sqrt(5)) / 2;
const goldenCorner = vector(1, goldenRatio) * inch;
// Draw some construction lines
const sketch1 = newSketch(context, id + "sketch1", {
"sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
});
skRectangle(sketch1, "rectangle1", {
"firstCorner" : vector(0, 0) * inch,
"secondCorner" : goldenCorner,
"construction": true
});
skLineSegment(sketch1, "line1", {
"start" : vector(0, 0) * inch,
"end" : goldenCorner,
"construction": true
});
// Create a rectangle to extrude
skRectangle(sketch1, "rectangle2", {
"firstCorner" : vector(1, 0) * inch,
"secondCorner" : vector(1.1, goldenRatio) * inch
});
skSolve(sketch1);
// Create a mirror transform
const x = normalize(vector(1, goldenRatio, 0));
const normal = cross(x, Z_DIRECTION);
const mirrorPlane = plane(WORLD_ORIGIN, normal, x);
const mirrorTransform = mirrorAcross(mirrorPlane);
debug(context, mirrorPlane, DebugColor.RED);
// Extrude a shape
opExtrude(context, id + "extrude1", {
"entities" : qSketchRegion(id + "sketch1"),
"direction" : Z_DIRECTION,
"endBound" : BoundingType.BLIND,
"endDepth" : 1 * inch
});
// Mirror it
opPattern(context, id + "pattern1", {
"entities" : qCreatedBy(id + "extrude1", EntityType.BODY),
"transforms" : [mirrorTransform],
"instanceNames" : ["mirror"]
});
// Delete the original
opDeleteBodies(context, id + "deleteBodies1", {
"entities" : qCreatedBy(id + "extrude1", EntityType.BODY)
});
});
0
Best Answer
-
MichaelPascoe Member Posts: 1,970 PRO
Try something like this:
https://cad.onshape.com/documents/afedfd6fe11ea21e5eec3375/w/72b...annotation { "Feature Type Name" : "Mirror transform" } export const mirrorTransform = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Entities", "Filter" : EntityType.BODY } definition.entities is Query; annotation { "Name" : "Mirror plane", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 } definition.plane is Query; } { const mirrorPlane = evFaceTangentPlane(context, { "face" : definition.plane, "parameter" : vector(0.5, 0.5) }); opTransform(context, id + "transform1", { "bodies" : definition.entities, "transform" : mirrorAcross(mirrorPlane) }); });
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! cadsharp.com/featurescripts 💎0
Answers
Try something like this:
https://cad.onshape.com/documents/afedfd6fe11ea21e5eec3375/w/72b...
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! cadsharp.com/featurescripts 💎