Projecting SolidWorks points onto surfaces

Hello,

I have been trying to do something and I am not sure that SolidWorks is capable of doing it.

I have a text file with x y z coordinates of points. x and y have numerical values and z is always zero. (basiclly a 2D sketch on the xy plane) I have a macro that imports the points as a 2D or 3D sketch into a part.

Now what I need to do is keep the x and y coordinates and project the points onto a surface to find out what the z coordinate is. I found a macro that can add a coincident relation between the points and the surface, but that also changes the x and y coordinates so it will not work.

For example, lets say I have a point that has x=25 in, y= -45 in and z=0 in. If I project that point onto the surface, the new coordinates should be x=25 in, y=-45 in and z=30 in.

I have not been able to find a way to do this other than putting points on the surface and manually changing the x and y coordinates to find out what the z coordinate is.

I am really at a loss at this moment. We need to do this for hundreds, maybe thousands of points and manually it would be out of the question. I tried importing a curve from x y z coordinates, convert entities and then project that onto a surface but that did not retain the point coordinates so I was not able to export them out of SolidWorks and find out what the z coordinate is.

I've heard some AutoCAD ideas on maybe drawing lines from the points in the z direction and then using the surface to trim them and find the intersection points but I am not sure how that would work for SolidWorks as a macro.

Any help or suggestions would be greatly appreciated as this has completely halted my progress on this project.

Thank you again,

Vlad

Reply to
vmuntean
Loading thread data ...

To do it manually, you would use points in a 3DSketch that each have an AlongZ relation to the corresponding point in the 2d skecth created by your macro. To do hundreds or thousands, you will need some sort of macro. Such a maro should be fairly simple for a pro SW macro coder (not me), especially if the target surface is a single body. Perhaps the macro you already have could be altered to do the job.

I'm guessing that points on the surface is not your end goal. Is there a chance someone may be able to suggest another path to your goal that does not involve projecting points onto the surface?

Reply to
Dale Dunn

This is the macro that I found online that adds a coincident relationship between the point and the surface. Any suggestions on how I would go about modifying this would be appreciated.

Thank you again,

Vlad

Dim swApp As Object Sub main() Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc Set Sketch = Part.GetActiveSketch2 If Sketch Is Nothing Then MsgBox "The 3DSketch must be open", vbCritical, "Points on Face macro " End End If Set Sel = Part.SelectionManager If Sel.GetSelectedObjectCount 1 Or Sel.GetSelectedObjectType(1) 2 Then ' FACE MsgBox "You must select the face", vbCritical, "Points on Face macro " End End If Set Face = Sel.GetSelectedObject(1) points = Sketch.GetSketchPoints For Each i In points i.Select False Face.Select True Part.SketchAddConstraints "sgCOINCIDENT" Next i End Sub

Reply to
vmuntean

I just had a thought although I am not sure how well this would work. Could a macro that does this maybe work:

Import points with xy coordinates and z=0.

Create an axis for every point using the point and face/plane option. Each point will form an axis with the help of a plane that is an offset from the xy plane above the surface.

Next we import the points again in a new sketch with xy coordinates and z=0 (because of the order of features created if we try to edit the previous sketch, the axes will not be available - unless macros work differently)

We set an intersect relationship between each point, its corresponding axis just created and the surface. I know that the logistics of writing such a macro may be difficult but at least I have some hope that it may work.

Let me know what you guys think.

Thank you,

Vlad

Reply to
vmuntean

ModelDoc2::RayIntersections is the API you need. Do you have only 1 possible intersection for each points, or more ("folded" surface) ? If you have some $ to spend on this, I might help you more ;-)

Reply to
Philippe Guglielmetti

Just before this line:

Part.SketchAddConstraints "sgCOINCIDENT"

you would need to get the x,y coordinates of the point, and then reset the coordinates to those points after that line. I don't know enough about the API to tell you what functions you would need. If you have thousands of these to do and at least a little VBA experience, you can probably figure it out a lot faster than manually aliging the points.

If you don't get far with this, you should probably consult a macro pro. There are several around who specialize in SW macros.

Reply to
Dale Dunn

snipped-for-privacy@ball.com wrote in news:1182282255.671675.239460 @p77g2000hsh.googlegroups.com:

A macro could do that, but a macro can also accomplish the same thing with just the math, and not adding axes.

See Phillippe's reply. He's definitely a SW macro/API pro who's been around for a quite a while, and he has identified the function that can find all 3 coordinates based on just the x,y coordinates and surface body (or maybe face). Take his advice over mine on programming.

Reply to
Dale Dunn

You said that you'd tried importing your coordinates as a curve, and that had not worked. What about importing them as a series of line segments or a single polyline? That should force SW to retain your original XY coordinates.

Reply to
Brian

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.