How to get the values of points that are made by intersection between lines and a surface

I wanna use VC to do it,and I have created two lines in space .The problem is that I have no idea how to get the values of the intersected points.

I have looked to  an example using a vector to get points‘ value ,which I find it don't take action here.One more,I have to get the values of points

intersected by the below surface in blue.

I hope you could help me.Thanks in advance.

Wilson

SolidworksApi macros
Answers 23
DY
DY 2012-04-17 Best Answer

Hi

when you touch the point.

you have the values of the point on the left side.

X,Y,Z parameters,

the other option is after creating the point.

add another sketch with all the dimension.

comment imagecomment image
SF
SF 2012-04-17

Dor,thanks for your reply.I got your method,however,I wanna make it in API because there will be so many points and I am going to store them.And most important,the points in the upper image are made manually.Do you have any other method?

Wilson

KR
KR 2012-04-17

Wilson,

What I described here is similar to what you will need to do.  You need to programmatically add relations between the point and the surface, and then the point and that line, and then use ISketchPoint::X, Y, and Z to get the coords.

Keith

Video Tutorials for the SolidWorks API

SF
SF 2012-04-18

Hi,Keith,thanks for your reply again,you are so helpful.

Do you know how programmaticly to add relations of constraints between points and surfaces, and points and lines?could you tell me the function names?

Wilson

KR
KR 2012-04-18

First, I realized I hadn't linked to the other thread in my last comment, just above.  I added the link now.

You need to use IModelDoc2::SketchAddConstraints to add constraints.

Looking up API call is pretty easy, you just need a little training.  I recommend you watch my 1 hour video called "Taking Macros to the People: Hands-On For Beginners", which will show you everything you need to know.  Also, in my course, lesson 2.2 is free and covers similarly helpful material on using the API Help.  Both are listed here.

Keith

Video Tutorials for the SolidWorks API

RJ
RJ 2012-04-18

Wilson,

The following steps might help you: -

  • Get Surface object for your Curved Surface. You can use SelectByID2() or some other method to get it.
  • Use ModelDoc2::CreateLine() to get the underlying Curve Object for your line.
  • Use Surface::IntersectCurve2() to get whether the curve intersects the surface or not. This API also returns the intersection point on Surface and on Curve.

Hope it helps!!!

Rajat Jain

DY
DY 2012-04-18

Hi wilson.

i found that there is a threded in the furom, they may have the answers

Exporting xyz point coordinates from a 3D sketch.

https://forum.solidworks.com/message/135755

SF
SF 2012-04-18

Rajat,

Thank you for your advice,and I will give it a try.now,there I have thought another method to do it in a different direction.I use Isurface::GetProjectedPointOn to retrieve the values of points.Below it's my C++ codes,however it doesn't work at all,can you help me?Thanks in advance.

Wilson

STDMETHODIMP CcreLin::projectedpoints()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())

  CComPtr mathUtils;
  m_iSldWorks->IGetMathUtility(&mathUtils);
CComPtrmySelMgr;
CComPtrm_iModelDoc;
m_iSldWorks->get_IActiveDoc2(&m_iModelDoc);
m_iModelDoc->get_ISelectionManager(&mySelMgr);
CComPtriDisp;
long type=-1;
mySelMgr->GetSelectedObjectType2(1,&type);
mySelMgr->IGetSelectedObject4(1,&iDisp);
HRESULT hr=S_FALSE;
if (type==swSelFACES)
{
        CComQIPtrswface(iDisp);
  iDisp=NULL;
  CComQIPtriSurf;
  hr=swface->IGetSurface(&iSurf);
 
  double xPt,yPt,zPt;
  double basePoint[3];
  double rayDir[3];
  CComPtr rayPoint;
  CComPtr rayVector;
        CComPtr intersectPt;
        double vPoint[3];
        if (hr==S_OK)
        {
   basePoint[0]=0.05;
   basePoint[1]=0.04;
            basePoint[2]=0;
      mathUtils->ICreatePoint(basePoint,&rayPoint);
            rayDir[0]=0;
   rayDir[1]=0;
            rayDir[2]=1;
   mathUtils->ICreateVector(rayDir,&rayVector);
            hr=iSurf->GetProjectedPointOn(rayPoint,rayVector,&intersectPt);
            if (hr==S_OK)
            {
    intersectPt->get_IArrayData(vPoint);
    xPt=vPoint[0];
    yPt=vPoint[1];
    zPt=vPoint[2];
    CString str1;
    str1.Format("%f,%f,%f",xPt,yPt,zPt);
    AfxMessageBox("str1");
            }
           
        }
}
return S_OK;
}

RJ
RJ 2012-04-18

Wilson,

The only issue I see is that your projection vector should be -Z direction and hence rayDir[2]=-1.

Hope it helps!!!

Rajat Jain

SF
SF 2012-04-18

Rajat,

I have tried to make  rayDir[2]=-1,but it doesn't work.

Wilson

RJ
RJ 2012-04-18

Wilson,

I believe that the basepoint co-ordinates should be in Model Co-ordinate System and they are in meter units.

I hope your model is so oriented so that this ray intersects the surface.

Hope it helps!!!

Rajat Jain

SF
SF 2012-04-18

Hi,Rajat.

I have debugged the codes as you told me to do.However I still can't solve it.And I create a seal model with the basepoint inside in origin ,but it just return nothing!

Wilson

comment imagecomment image
SF
SF 2012-04-19

hi,Rajat

Do you believe that the Isurface::GetProjectedPointOn function doesn't take work in C++? I found it may be the only reason for the phenomenon.Can someone give me any suggestion?

Wilson

RJ
RJ 2012-04-19

Wilson,

I created a small part and a test macro to test for the function. The part and macro are attached herewith.

Just open the part and select the top face and run the macro. It shall show you the intersection point.

If this function works in VBA then it should work in C++.

Kindly check if your inputs are still correct as per SolidWorks co-ordinate system. Alternately, if you can attach your part then I shall tell you the base point values and the vector values.

Hope it helps!!!

Rajat Jain

SF
SF 2012-04-19

Rajat,

Thanks for your work.The Intersection_check.SLDPRT can not be opened for me,because my solidworks is 2010,could you save it as 2010?  And the part is simple and is attached below .Sometime before I have added some codes in the upper procedure that create the basepoint in model and I feel the input points is right,as for the vector I'm confused.Thanks again.

Wilson

RJ
RJ 2012-04-19

Wilson,

This is the issue..

Please make your extrude in both directions so that you have material crossing 0,0,0. Make your base point 0,0,0 and make your direction as 0,1,0 i.e. the +Y Axis.

This shall give you the intersection point.

Hope it helps!!!

Rajat Jain

SF
SF 2012-04-19

Rajat,

It's a pity that it is not the issue,which I have just tried and found. Could you let me to verify your part with your marco? 2010solidworks

Wilson

RJ
RJ 2012-04-19

Wilson,

Please find attached the updated macro as per your part. I have selected the inner curve surface as follows: -

I get the following msg: -

Kindly check it again at your end.

Hope it helps!!!

Rajat Jain

comment imagecomment imagecomment imagecomment image
SF
SF 2012-04-19

Rajat,

I'm so glad to receive your reply again,and so appreciate your help! But why I can not get your result showing in the upper imgage,I just run your intersectionCheck.swp after I have selected the inner curve surface.Is it caused by my lower solidworks2010? Sorry to disturb you so much

Wilson

comment imagecomment image
RJ
RJ 2012-04-19

Wilson,

Did you try to change the references of SW2012 with SW2010 in the macro. This can be an issue.

In your VB editor, click tools->References. It shall show you some missing references. Remove them and check the reference files of SW2010.

Hope it helps!!!

Rajat Jain

SF
SF 2012-04-19

Hi,Rajat

That is the issue,and I have just retrieved the very result using your macro after I removed SW2012 and checked on SW2010.You offer me a so big hand,you are so kind.But what's wrong with my codes? I have verified that only hr=iSurf->GetProjectedPointOn(rayPoint,rayVector,&intersectPt) doesn't work.And I found that the basepoint and the vector in C++ are the same in VBA.Can you figure it out?

Wilson 

RJ
RJ 2012-04-20

Wilson,

Please re-check whether your base point is set to 0,0,0 and your direction vector is 0,1,0.

I shall have to create a fully functionaly C++ Addin project to check this and that shall take up some time. I am afraid I shall not be able to do it immediately.

I am sure there is some issue with these values only.

Hope it helps!!!

Rajat Jain

SF
SF 2012-04-20

Hi,Rajat

Thanks in advance whatever a result may be,and please do it in your spare time.Unfortunately I have to tell that the basepoint is definitely set to 0,0,0 and the direction vector is also 0,1,0.

Best regards

Wilson