hello all
my earlier problem of extracting point from cad model in a helical path can also be solved by using getrayintersection function in solidworks api help but because i cant record the macro for it and i am not too good in vb or api i cant figure out how to do it
if any body has any example of this function please reply me
if no then i would like you all to please give it a try, i guess this must be a simple command for you people.
what am i looking for
1: to generate an array of ray base point which is at a particular pitch interval on the axis of cylinder with some specified distance and the vector component should vary with the angle in any constant helical path(could be of high diameter magnitude)
result:
the required output should give me the x,y,z coordinate of every hit point on the body
please give it a try that function does not seem to complicated
i will give you conversation may be that could help it is in c++ api but please reply me in vb so that i could understand it
I am currently trying to use the IRayIntersections function to get a
list of bodies that are hit by a ray going from the origin out to the
point (20,0,0). I am working in C++ and am having some issues with
the function. Currently I am testing the function and have the base
points of the Ray at the center of the box shooting out of the box
( SolidBody of size 10x10x10 mm centered at origin). With this setup,
IRayIntersections is saying that the ray does not hit anything. The
code that I am using is:
Pre: Solidworks Assembly open containing a SolidWorks part file called
test.SLDPRT
Post: a print to a file of the line reached.
CComPtr swModel;
CComPtr swPart;
CComPtr swEnumBodies;
CComPtr swBody;
IBody2Ptr swBodyPtr;
CComBSTR partName (_T("test.SLDPRT"));
CComBSTR name, path;
long errors,celtFetched, hits;
double bpin = 1;
double *basePointsIn;
double *vectorsIn;
double *returnVector = NULL;
double radius;
char b[33];
celtFetched = 1;
basePointsIn = (double *)calloc(3,sizeof(double));
vectorsIn = (double *)calloc(3,sizeof(double));
basePointsIn[0] =0.0;
basePointsIn[1] =0.0;
basePointsIn[2] =0.0;
vectorsIn[0] = 20;
vectorsIn[1] = 0.0;
vectorsIn[2] = 0.0;
//Bring up the part document.
if( m_iSldWorks->IActivateDoc3( partName, TRUE /*silent*/, &errors,
&swModel ) == S_OK )
{
if(swModel->QueryInterface(IID_IPartDoc, (LPVOID*)&swPart) == S_OK)
{
if(swPart->EnumBodies3(swAllBodies ,VARIANT_FALSE, &swEnumBodies) ==
S_OK)
{
if(swEnumBodies->Next(1, &swBody,&celtFetched) == S_OK) {
swBodyPtr = swBody;
if(swModel->IRayIntersections( &swBodyPtr,celtFetched ,
basePointsIn , vectorsIn , 1 , swRayPtsOptsENTRY_EXIT , 1 , 1 ,
&hits) == S_OK)
{ if (hits == 0)
{
//print off line this line
return S_FALSE;
}
else
{
//print off line this line
return S_OK;
}
}
}
}
}
return S_FALSE;
}
this is some changes that need to be done
.........................................................................................................
See documentation: the first parameter of ModelDoc2->IRayIntersections()
method
have to be array of pointers to Body2 objects. But you pass just IBody2Ptr
object.
Try the following:
//----------------------------------------------------------------------
typedef IBody2 *LPBODY2;
...
if(swEnumBodies->Next(1, &swBody,&celtFetched) == S_OK)
{
LPBODY2* swBodyArr = new LPBODY2[1];
swBodyArr [0] = swBody;
//swBodyPtr = swBody;
HRESULT hres = swModel->IRayIntersections( swBodyArr, celtFetched ,
basePointsIn , vectorsIn , 1 ,
swRayPtsOptsENTRY_EXIT,
1 ,1 , &hits);
...
delete[] swBodyArr;//don't forget;
}
//----------------------------------------------------------------------
I succeeded, but got 13 hits if hitRadius = 1, several hit in point ( 0, 0,
0), others in point ( 5, 0, 0).
Also use this code to see intersection points:
//----------------------------------------------------------------------
if (hits == 0)
{
//print off line this line
return S_FALSE;
}
else
{
swModel->Insert3DSketch2( -1/*VARIANT_TRUE*/);
double* retPts = new double [ hits * 9 ];
swModel->IGetRayIntersectionsPoints ( retPts );
ISketchPoint* pt;
for ( int i = 0; i < hits; i++)
swModel->ICreatePoint2 ( retPts [ 9*i + 3 ]/*X*/,
retPts [ 9*i +
4 ]/*Y*/,
retPts [ 9*i +
5 ]/*Z*/,
&pt);
swModel->Insert3DSketch2( -1/*VARIANT_TRUE*/);
delete[] retPts;
//print off line this line
return S_OK;
}
thanks
vivek pal singhSolidworksApi macros
my earlier problem of extracting point from cad model in a helical path can also be solved by using getrayintersection function in solidworks api help but because i cant record the macro for it and i am not too good in vb or api i cant figure out how to do it
if any body has any example of this function please reply me
if no then i would like you all to please give it a try, i guess this must be a simple command for you people.
what am i looking for
1: to generate an array of ray base point which is at a particular pitch interval on the axis of cylinder with some specified distance and the vector component should vary with the angle in any constant helical path(could be of high diameter magnitude)
result:
the required output should give me the x,y,z coordinate of every hit point on the body
please give it a try that function does not seem to complicated
i will give you conversation may be that could help it is in c++ api but please reply me in vb so that i could understand it
I am currently trying to use the IRayIntersections function to get a
list of bodies that are hit by a ray going from the origin out to the
point (20,0,0). I am working in C++ and am having some issues with
the function. Currently I am testing the function and have the base
points of the Ray at the center of the box shooting out of the box
( SolidBody of size 10x10x10 mm centered at origin). With this setup,
IRayIntersections is saying that the ray does not hit anything. The
code that I am using is:
Pre: Solidworks Assembly open containing a SolidWorks part file called
test.SLDPRT
Post: a print to a file of the line reached.
CComPtr
CComPtr
CComPtr
CComPtr
IBody2Ptr swBodyPtr;
CComBSTR partName (_T("test.SLDPRT"));
CComBSTR name, path;
long errors,celtFetched, hits;
double bpin = 1;
double *basePointsIn;
double *vectorsIn;
double *returnVector = NULL;
double radius;
char b[33];
celtFetched = 1;
basePointsIn = (double *)calloc(3,sizeof(double));
vectorsIn = (double *)calloc(3,sizeof(double));
basePointsIn[0] =0.0;
basePointsIn[1] =0.0;
basePointsIn[2] =0.0;
vectorsIn[0] = 20;
vectorsIn[1] = 0.0;
vectorsIn[2] = 0.0;
//Bring up the part document.
if( m_iSldWorks->IActivateDoc3( partName, TRUE /*silent*/, &errors,
&swModel ) == S_OK )
{
if(swModel->QueryInterface(IID_IPartDoc, (LPVOID*)&swPart) == S_OK)
{
if(swPart->EnumBodies3(swAllBodies ,VARIANT_FALSE, &swEnumBodies) ==
S_OK)
{
if(swEnumBodies->Next(1, &swBody,&celtFetched) == S_OK) {
swBodyPtr = swBody;
if(swModel->IRayIntersections( &swBodyPtr,celtFetched ,
basePointsIn , vectorsIn , 1 , swRayPtsOptsENTRY_EXIT , 1 , 1 ,
&hits) == S_OK)
{ if (hits == 0)
{
//print off line this line
return S_FALSE;
}
else
{
//print off line this line
return S_OK;
}
}
}
}
}
return S_FALSE;
}
this is some changes that need to be done
.........................................................................................................
See documentation: the first parameter of ModelDoc2->IRayIntersections()
method
have to be array of pointers to Body2 objects. But you pass just IBody2Ptr
object.
Try the following:
//----------------------------------------------------------------------
typedef IBody2 *LPBODY2;
...
if(swEnumBodies->Next(1, &swBody,&celtFetched) == S_OK)
{
LPBODY2* swBodyArr = new LPBODY2[1];
swBodyArr [0] = swBody;
//swBodyPtr = swBody;
HRESULT hres = swModel->IRayIntersections( swBodyArr, celtFetched ,
basePointsIn , vectorsIn , 1 ,
swRayPtsOptsENTRY_EXIT,
1 ,1 , &hits);
...
delete[] swBodyArr;//don't forget;
}
//----------------------------------------------------------------------
I succeeded, but got 13 hits if hitRadius = 1, several hit in point ( 0, 0,
0), others in point ( 5, 0, 0).
Also use this code to see intersection points:
//----------------------------------------------------------------------
if (hits == 0)
{
//print off line this line
return S_FALSE;
}
else
{
swModel->Insert3DSketch2( -1/*VARIANT_TRUE*/);
double* retPts = new double [ hits * 9 ];
swModel->IGetRayIntersectionsPoints ( retPts );
ISketchPoint* pt;
for ( int i = 0; i < hits; i++)
swModel->ICreatePoint2 ( retPts [ 9*i + 3 ]/*X*/,
retPts [ 9*i +
4 ]/*Y*/,
retPts [ 9*i +
5 ]/*Z*/,
&pt);
swModel->Insert3DSketch2( -1/*VARIANT_TRUE*/);
delete[] retPts;
//print off line this line
return S_OK;
}
thanks
vivek pal singhSolidworksApi macros