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.

Options

Is there a way to make a copy of a curve or sketch Id

dave_cowdendave_cowden Member, Developers Posts: 470 ✭✭✭
Suppose we start with a sketch, 'sketchA', which contains a sketched curve.

Is there a way to create a copy of an arc or spline in a new sketch, 'sketchB'?

If the curve I'm trying to copy is a line or arc, I can see it would be possible to manually re-create it using evCurveDefinition, combined with evTangentLines.

But if the provided curve is a spline, I don't know what to do, because evCurveDefinition returns 'unspecified contents'.

I also considered just using evTangentLines and then fitting a spline all the time, but If the original curve is an arc, i dont want to use a spline. 

So the best I can come up with is to use evCurveDefinition to create a line or arc, and then if evCurveDefinition returns undefined, fit a spline through points using evTangentLines.  But the problem is that this will produce an imperfect replica of the original. 

maybe i can use qDependency to get the original sketch.. but that doesnt help me recreate a copy...

Am I making this too hard?


Answers

  • Options
    kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    edited June 2016
    Yes, we don't have great tools for manually reproducing sketch entities on another sketch. But often there are useful workarounds.

    For instance, you can use opPattern to create a copy of any body or set of bodies. Does that accomplish what you want? If not, what's your ultimate goal with this feature?
  • Options
    dave_cowdendave_cowden Member, Developers Posts: 470 ✭✭✭
    Ooh I didn't think about op pattern. Sadly, I don't think it will help me.

     I need to   programmatically create a sketch, and then create sketch entities in that sketch, which have constraints based upon geometry that was creates by the user earlier ( IE, a curve).

    Op pattern will not work because I need to create sketch entities based on the geometry, not a copy of the entity itself. I need sketch entities because I need to add constraints.

    For example, if I have an arc, I don't need a copy of the edge, I need to call skArc.

    If it is possible to create constraints in a sketch that reference geometry defined elsewhere, that would be perfect, but I don't know how to do that



  • Options
    kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    I'll give you the standard warning when dealing with sketch constraints in FeatureScript: It's pretty hard right now. There's big parts of it that we know should be way easier, and there's some unseen and undocumented magic hiding in the initial guess constant. If you can build your feature without using the sketch solver, you're going to have an easier time. If you can build it using the sketch solver for the only a small part of it, you'll also have an easier time.

    Now, if you do want add such a thing to a sketch, I'd take a look at what's done when you project a spline into another sketch in Onshape with the "use" command. In FeatureScript, if you can create the correct entity type in your new sketch (e.g. an arc), and add a projection constraint, that will get you going in the right direction.

  • Options
    dave_cowdendave_cowden Member, Developers Posts: 470 ✭✭✭
    I'm trying to create text, so i'm stuck with the sketch solver, unless there is another way to create text.  I'm trying to create text that follows a user-defined curve.  Doing so requires constraining the sketch baseline start and end to the user-provided curve.


  • Options
    kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Aha. You'll probably have an easier time creating the sketch text and then using opTransform() to move it.

    skText will initially place text on the sketch origin with a line height of one meter, so you can do the math to move it after the fact to the desired position. As suggested on the opTransform doc, you can scale down using transform(identityMatrix(3) * scale, vector(0, 0, 0) * inch), and you can move to another cSys with toWorld(cSys). Using this method you can create a new sketch for every letter and transform them.

    Keep posting if you run into further obstacles!

  • Options
    dave_cowdendave_cowden Member, Developers Posts: 470 ✭✭✭
    Hi, Kevin:

    yes, i've gotten some examples working by transforming the letters, roughly as you suggested. When i can pre-compute the points I want , your recommended strategy works.

    But in many cases, I cannot pre-compute the coordinates to transform to. Consider I have two letters next to each other. I have no way to know their width-- which is variable.  The sketch solver is the best solution-- I can simply constrain the lower right corner of letter 1 to be co-incident with the lower-left corner of letter two.  Now the letters stay together, and then I can fix that to any location I want.  But where in 3d space? I cannot calculate the point-- because i dont know the width of the letters, and i dont have a way to find it.  

    If I am placing text on a curve from left to right, i can create text as above, and then fix the lower left corner of the sketch text to be at the start point of the curve. But then, how do i compute coordinates on which to fix the other letter corners? This is impossible because i dont know the letter width.

    Thus the need to use the sketch solver....






  • Options
    dave_cowdendave_cowden Member, Developers Posts: 470 ✭✭✭
    Im thinking my best strategy is to project the selected guy onto  the sketch plane.  what's the best way to know what type of entity to create? what will evCurveDefinition return if the underlying curve is not a line, ellipse, or circle ?
  • Options
    kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    edited June 2016
    Unfortunately evCurveDefinition won't return the right thing for anything but those primitives you listed.

    You can, however, easily determine the bounding box of a letter using evBox3d. For an example of this, here's a public document I made which positions sketch text on a line:
    https://cad.onshape.com/documents/cdbad61ec176b39049f8d4c1/w/0cb06ca7cb2788345cc7a448/e/e11a12cb6c7c926bdab162a0

    It's only for one letter, but you can imagine doing it for multiple.

    Figuring out the final position is also tricky, but: To evaluate the position along a line based on the letter length, you can divide the desired distance by the curve length (evLength), and use that as the parameter for evTangentLine().

  • Options
    dave_cowdendave_cowden Member, Developers Posts: 470 ✭✭✭
    Alright thanks, I will see what I can come up with.  You are right this is quite a bit harder than it should be I think.
  • Options
    jason_bennett190jason_bennett190 Member, Developers Posts: 17
    These posts were useful in solving my own issues with creating text in script. I look forward to better sketch constraints!
Sign In or Register to comment.