Creating point on Surface at proper coordinates

Hi folks,

I found no solution to the following problem, maybe someone already solved it or can correct me.

Given a box with the top face selected.

'Edit sketch' is active.

IFace2 and ISurface objects of the top are available.

Given a point XYZ.

The goal is to project the point to the surface and get the proper values for CreatePoint2(x, y, z)

I got to the phase where the point is correcly projected onto the surface's plane. (x, y, z coordinates are correct)

I tried to give these values to CreatePoint2() No matter what the 'z' parameter was, the point was created on the surface's plane.

Then I tried to get 'u' and 'v' values for surface with ISurface.ReverseEvaluate() and tried CreatePoint2(u, v, 0). It was inconsistent.

For example on the top surface, x=-u, y=v, z=0 created the correct point, but this equation did not work on other sides.

I looked in the API help everywhere, and did not find info about the 'uv' vs. 'sketching plane' relations, not even a single transformation from one to another.

Finally I tried to turn off AutoSolve and AutoInference', same, no success.

In short:

If I have the x, y, z global coordinates for a point, which lays on the active sketching plane, how to create the point on that position?

I hope, something simple and elegant way exists to this problem.

Any help would be appreciated.

Thank you

SolidworksApi macros
Answers 2
JB
JB 2010-10-11 Best Answer

If I understand correctly what you're saying, it sounds like you need to get the coordinate transform for the sketch.

Sketches have their own coordinate system that relates back to the global coordinate system by a MathTransform object.  Check API help for that object and its methods, properties, and accessors.

SF
SF 2010-10-11

1. Get transformation matrix with ISketch.ModelToSketchTranspose()

2. Transform global point with result from (1)

3. Call CreatePoint with result from (2)

Your answer was correct, thank you.