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

New point every(x) distance on line

theodore_peterstheodore_peters Member Posts: 15
I'm looking for a way to add a point using featurescript every x distance on a line...the tricky part is that the line doesn't have to be aligned to any certain axis, it could be askew to any axis. I'm sure there is some vector math that I am unaware of. Please point(hah!) me in the right direction!

To clarify, lets assume I have a 4 sided polygon with all 4 sides different length, and no sides are parallel to any axis or plane(aside from the flat plane being drawn on). every inch, I want to add a point to each edge...

What I have so far:
I have the user select a sketch region or face.
then I grab all edges adjacent to the face.
then I evaluate the query into an array of edges I can loop through.
inside the loop, I grab the edge's start point and end point.
here is where i need a for loop to start "i" at the start point and end when "i == end point" and increment "i" by the distance I want between points......problem is that this only works when the other value of the vector is constant. how do I create a line reference that normalizes this so that start is always (0,start) and end is always (0,end) or something to that effect?

I am working on a method that uses the distance formula and slope but I'm sure there is a method already defined for this.

Comments

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,379
    When you use evTangentLine (to get a percentage distance along the curve) the line returned gives you an origin and a direction (a line). Is that what you are looking for?
    Senior Director, Technical Services, EMEAI
  • Options
    theodore_peterstheodore_peters Member Posts: 15
    I'm not sure...if you sketch a rhombus with sides measuring 5 inches in length and want to put a point on every inch one or more sides, how would you do it? im not using any 3d geometry at the moment or circles, so i dont know if tangent will help.
  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,379
    If you want all points an inch apart to span across all edges (i.e not start at 0 on every edge) then that is the same as curve driven pattern. Please take a look at that code - it also solves the problem of edge order (there is no guarantee of the order edges are returned by a query). However curve driven pattern measures number of instances rather than distance between points which would be easy if you knew they were all lines. 
    Senior Director, Technical Services, EMEAI
  • Options
    theodore_peterstheodore_peters Member Posts: 15
    i want it to reset at every corner, so order isn't important. i'm using FS to erect 2x4's every 16 inches off center for a given polygon. would the curve pattern code still be helpful here?
  • Options
    theodore_peterstheodore_peters Member Posts: 15
    edited February 2017
    Ok i have it how i need it, now i have a new question.

    In the following code:
    <br><div>for (var i = 0; i < 1/pointmultiplyer; i += 1)</div><br><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><br><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><br><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; skPoint(theSketch,"point"+ toString(i), {</div><br><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "position" : vector(curx, cury)&nbsp;</div><br><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</div><br><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curx+=pointxadder;</div><br><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cury+=pointyadder;</div><br><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div>
    It tells me "Can not add string and string"

    i need each Id to be unique or it will throw me an error saying each must be unique...what do i do here?
    let me know if i should start a new topic...i will post my answer to my previous question once i get this line fixed.
  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,379
    FeatureScript uses a tilde to concatenate strings. Use "" ~ i;
    Senior Director, Technical Services, EMEAI
Sign In or Register to comment.