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

Points along a Curve

frank_weeksfrank_weeks Member, Developers Posts: 6 EDU
I am new to FeatureScript and am looking to create a (seemingly) simple script that places points along a curve, evenly spaced. Without getting into other spacing options, I would first like some guidance on how to do this given only a distance and a quantity, starting from the end.
I tried to dissect the very nice Curve Pattern FeatureScript but there were so many options, I couldn't figure out what part of the code actually does the measuring along the path.
I figure I would use evLength and opPoint (and some math) but that's about as far as I've gotten. Any suggestions to help me move forward would be greatly appreciated.

Comments

  • Options
    lougallolougallo Member, Moderator, Onshape Employees, Developers Posts: 2,001
    @frank_weeks you can look at the multi-plane tool to see how it is done.
    Lou Gallo / PD/UX - Support - Community / Onshape, Inc.
  • Options
    Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    Hi Frank,

    The code for this should be fairly simple.

    First, you want to get the total length of the curve with evLength.

    Once you have the length of the curve, you can calculate something like 'var parameterPerLength = 1.0/totalLength'.  Every curve in onshape is parameterized from 0.0 to 1.0, so this scaling factor lets you convert from distance into parameter space.  For example, if a curve is 10m long, and you want to find the point that is 5m along the curve, you would calculate that as 'desired parameter = 5m * (1 / 10m) = 0.5' (incidentally this is the same as just dividing by the total length, but I prefer to store my scale factors in separate variables).

    Now that you have a scale factor, you can fill an array with all the parameters along the curve that you want to find the point at.  Define a constant 'var spacing = <distance between points> * parameterPerLength'.  This is the around of parameterization between each point you want to create.  Then, use a for loop to fill an array with [1 * spacing, 2 * spacing, 3 * spacing, etc].  It will probably be best not to not exceed a parameter of 1.0 in this array.

    Call evEdgeTangentLines with your edge and your array of parameters, making sure to set 'arcLengthParameterization' to 'true'. This call will return you an array of Line objects such that 'returnFromEv[0].origin' and 'returnFromEv[1].origin' will give you the first and second points along the line at your specified distance apart.

    call opPoint with all of those Line origins.

    Let me know if you can work this out :) Happy to write you a quick FeatureScript to do it but it seemed like you wanted to do it yourself.
    Jake Rosenfeld - Modeling Team
  • Options
    frank_weeksfrank_weeks Member, Developers Posts: 6 EDU
    Thanks to both of you. You have filled in some of the missing elements which should definitely get me started.
Sign In or Register to comment.