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.

# featurescript: How to get a midpoint

alan_1
Member Posts:

**14**EDU
I am trying to get a midpoint of a line

Here's the parameter:

And here's some code that I wrote.

I want to get the midpoint of each line and use it to do an extrude. Any idea how I might do this? The code above is just a starting point (no pun intended). The line with worldToPlane() is failing for me.

Disclaimer: I am a featurescript noob.

Here's the parameter:

annotation { "Name" : "Lines", "Filter" : EntityType.EDGE && SketchObject.YES && GeometryType.LINE }

definition.lines is Query;

And here's some code that I wrote.

const lines = evaluateQuery(context, definition.lines);

for (var line in lines) {

var endpoints = qVertexAdjacent(line, EntityType.VERTEX);

for (var epoint in endpoints ) {

var point is Vector = worldToPlane(topPlane, evVertexPoint(context, { "vertex" : epoint }));

var pvec = vector(point[0], point[1]);

// Will use the point for various operations.

}

}

// Will use the point for various operations.

}

}

Disclaimer: I am a featurescript noob.

Tagged:

0

## Comments

45914EDUThanks!

I also found that this works:

95514EDUHere's the value of normal:

Note the '"meter" : -1'

955In terms of the units mismatch, here's how to think about it to understand what's going on:

A and B are vectors with length units. B - A is therefore also a vector with length units.

perpendicularVector(A - B ) is a vector with no units and of length 1. (I'm clarifying the documentation to state that explicitly)

norm(B - A) has length units (it is the distance between A and B )

If you divide a unitless vector by a length, you get a vector with units 1/length, hence the meters^-1 in your output.

Perhaps you wanted to multiply by norm(A - B ) instead? Also, perhaps you want to do evOwnerSketchPlane(context, { entity : line }).normal

to get the normal of the line's sketch plane (rather than an arbitrary perpendicularVector).

14EDUBTW, the documentation for skConstraint doesn't even mention "localFirst". Doh! I got lucky and found a reference to it in an example. Who knows what other mystery parameters it might accept!?

There's probably a way to project the perpendicular line onto the sketch plane I suppose. skConstraint() seems to have something like this.

95514EDU