Hi Kris,
as you suspected the violation is occuring at the following line with M Ranging from 0 to 2.
if(!(y = IntersectionPts[M]->y()) )
{//if(!y)
Some code here
}//if(!y)
The relevant code routine is given below.
Thanks Kris.
/////////////////////////////////////////////////////
// Arc3PtsByIntersectWithSurfaceCurve() //////////////////////////////////////////////////////////////////////////////////////////
bool Arc3PtsByIntersectWithSurfaceCurve(Common &Com, VTOLMIDBODY &vtolmidbody, BULKHEAD &bulkhead, VTOLBODY &VTOLBody, unsigned int JPhi, unsigned int Ifr, unsigned int J, unsigned int K, unsigned int IzBulk)
// Create three sketch points
{//
bulkhead.msg = " In Arc3PtsByIntersectWithSurfaceCurve( ";
if(Com.IDebug == 10) ui->messageBox(bulkhead.msg);
unsigned int If;
if(Ifr == 0) {If = 0;} /* The Front Junction Arc */
else if (Ifr == 1) {If = 1;} /* The Rear Junction Arc */
else if (Ifr == 2 && abs(VTOLBody.zValueOfPlaneBulk[Ifr][0][0]) < 500.0 ) {If = 0;} /* The Front Junction Arc */
else {If = 1;} /* VTOLBody.IRivetSubRegion[Ifr] = 2, The Front Junction Arc */
unsigned int M, Item;
/////////////////////////////////////////////////////////////////
Ptr<Vector3D> NormalPhi;
double NormPhiy = - sin(vtolmidbody.Phi[JPhi]);
TryPlusNormPhi:
Item = 0;
NormalPhi = adsk::core::Vector3D::create(cos(vtolmidbody.Phi[JPhi]), NormPhiy, 0);
if(!NormalPhi)
return false;
Ptr<Plane> IntersectPlanePhi;
IntersectPlanePhi = adsk::core::Plane::create(adsk::core::Point3D::create(1.0e-3, 0, 0), NormalPhi);
if (!IntersectPlanePhi)
return false;
Ptr<ObjectCollection> IntersectionObjColl = adsk::core::ObjectCollection::create();
if(!IntersectionObjColl)
return false;
if(Com.IDebug == 10) ui->messageBox(" After IntersectionPtsObjColl ");
Ptr<BRepFaces> faces = VTOLBody.Body->faces();
if(Com.IDebug == 10) ui->messageBox(" After faces ");
unsigned int faceCount = faces->count();
bulkhead.msg = " faceCount ";
sprintf_s (bulkhead.dStr, "%d", faceCount); // %d makes the result be a decimal integer
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 10) ui->messageBox(bulkhead.msg);
//Debug
fprintf(Com.out," \n\n faceCount = %4d \n",
faceCount);
// 2 Faces: Outer Curved, Inner
Ptr<BRepFace> face[2];
/* Get the Inner and Outer faces */
face[0] = faces->item(0);
if(!face[0])
return false;
if(Com.IDebug == 10) ui->messageBox(" After face[0] ");
// Get the value of the property.
Ptr<Surface> surface[4];
surface[0] = face[0]->geometry();
if(!surface[0])
return false;
if(Com.IDebug == 10) ui->messageBox(" After surface[0] ");
IntersectionObjColl = IntersectPlanePhi->intersectWithSurface(surface[0]);
if (!IntersectionObjColl)
return false;
if(Com.IDebug == 11) ui->messageBox(" After intersectWithSurface() face 0 ");
unsigned int CountObjectsColl = IntersectionObjColl->count();
bulkhead.msg = " CountObjectsColl = ";
bulkhead.msg += " ";
sprintf_s (bulkhead.dStr, "%d", CountObjectsColl ); // %d makes the result be a decimal integer
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 12) ui->messageBox(bulkhead.msg);
fprintf(Com.out," \n\n CountObjectsColl = %4d \n\n", CountObjectsColl);
Ptr<Base> base = IntersectionObjColl->item(0);
bulkhead.msg = " base = ";
bulkhead.msg += " ";
sprintf_s (bulkhead.dStr, "%d", base );
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 10) ui->messageBox(bulkhead.msg);
string objectType = IntersectionObjColl->objectType();
bulkhead.msg = " objectType = ";
bulkhead.msg += " ";
sprintf_s (bulkhead.dStr, "%s", objectType );
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 10) ui->messageBox(bulkhead.msg);
Ptr<Curve3D> curve3D;
TryNextItemNumber:
curve3D = IntersectionObjColl->item(Item);
if(!curve3D)
{//if(!curve3D)
// get error message
std::string errorMessage;
int errorCode = app->getLastError(&errorMessage);
if (GenericErrors::Ok != errorCode)
{//
ui->messageBox(errorMessage);
fprintf(Com.out," \n\n errorCode = %4d, errorMessage = %20s \n\n", errorCode, errorMessage);
}//
if(Item < CountObjectsColl - 1)
{//if(Item < CountObjectsColl - 1)
Item++;
bulkhead.msg = " Item = ";
bulkhead.msg += " ";
sprintf_s (bulkhead.dStr, "%d", Item);
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 12) ui->messageBox(bulkhead.msg);
fprintf(Com.out," \n\n Item = %4d \n\n", Item);
goto TryNextItemNumber;
}//if(Item < CountObjectsColl - 1)
else {goto Continue;}
}//if(!curve3D)
Continue:
bulkhead.msg = " Item = ";
bulkhead.msg += " ";
sprintf_s (bulkhead.dStr, "%d", Item);
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 12) ui->messageBox(bulkhead.msg);
fprintf(Com.out," \n\n Item = %4d \n\n", Item);
if(Com.IDebug == 12) ui->messageBox(" After IntersectionObjColl->item(); ");
// Get the value of the property.
string CurveType = curve3D->objectType();
//ui->messageBox(" After CurveType = sketchCurve->objectType(); ");
bulkhead.msg = " CurveType = ";
bulkhead.msg += " ";
sprintf_s (bulkhead.dStr, "%s", CurveType );
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 10) ui->messageBox(bulkhead.msg);
/* Create an xz Plane with y Offset */
Ptr<Vector3D> normalxy = adsk::core::Vector3D::create(0, 0, 1);
if(!normalxy)
return false;
Ptr<ObjectCollection> IntersectionPtsObjColl = adsk::core::ObjectCollection::create();
if(!IntersectionPtsObjColl)
return false;
Ptr<Point3D> IntersectionPts[3];
for(M = 0; M <= 2; M++)
{//M
zValueOfPlaneBulk(Com, vtolmidbody, VTOLBody, JPhi, Ifr, IzBulk, M);
bulkhead.zC[J][M] = VTOLBody.zValueOfPlaneBulk[Ifr][IzBulk][M];
//Debug
fprintf(Com.out," \n\n M = %4d, zC[J][M] = %10.3e \n",
M, bulkhead.zC[J][M]);
bulkhead.msg = " M = ";
bulkhead.msg += " ";
sprintf_s (bulkhead.dStr, "%d", M);
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 11) ui->messageBox(bulkhead.msg);
bulkhead.msg = " zC[J][M] = ";
bulkhead.msg += " ";
sprintf_s (bulkhead.dStr, "%f", bulkhead.zC[J][M] );
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 11) ui->messageBox(bulkhead.msg);
Ptr<Plane> xzPlane = adsk::core::Plane::create(adsk::core::Point3D::create(0, 0, bulkhead.zC[J][M]), normalxy);
if (!xzPlane)
return false;
/* Dummy Initialize */
IntersectionPts[M] = adsk::core::Point3D::create(0, 0, 0);
IntersectionPtsObjColl = xzPlane->intersectWithCurve(curve3D);
if (!IntersectionPtsObjColl)
return false;
IntersectionPts[M] = IntersectionPtsObjColl->item(0);
if(Com.IDebug == 12) ui->messageBox(" After IntersectionPts ");
double x, y, z;
fprintf(Com.out," \n\n After IntersectionPts \n\n");
if(!(y = IntersectionPts[M]->y()) )
{//if(!y)
// get error message
std::string errorMessage;
int errorCode = app->getLastError(&errorMessage);
if (GenericErrors::Ok != errorCode)
{//
ui->messageBox(errorMessage);
fprintf(Com.out," \n\n errorCode = %4d, errorMessage = %20s \n\n", errorCode, errorMessage);
}//
if(Item < CountObjectsColl - 1)
{//if
Item++;
goto TryNextItemNumber;
}//if
else
{//else
NormPhiy = - NormPhiy;
goto TryPlusNormPhi;
}//else
}//if(!y)
else if( (JPhi < 6 && y < 0.0) || (JPhi > 6 && y > 0.0) && (Item < CountObjectsColl - 1) )
{//else if
bulkhead.msg = " y = ";
bulkhead.msg += " ";
sprintf_s ( bulkhead.dStr, "%f", y ); // %d makes the result be a decimal integer
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 12) ui->messageBox(bulkhead.msg);
Item++;
goto TryNextItemNumber;
}//else if
if(Com.IDebug == 12)
{ bulkhead.msg = " Item = ";
bulkhead.msg += " ";
sprintf_s ( bulkhead.dStr, "%f", Item ); // %d makes the result be a decimal integer
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 12) ui->messageBox(bulkhead.msg);
}
fprintf(Com.out," \n\n Item = %4d \n\n", Item);
y = IntersectionPts[M]->y();
bulkhead.yC[J][M] = y;
z = bulkhead.zC[J][M];
bulkhead.xC[J][M] = x = IntersectionPts[M]->x();
if(bulkhead.xC[J][M] < 0.0) { bulkhead.xC[J][M] = x = -x;}
bulkhead.msg = " x = ";
bulkhead.msg += " ";
sprintf_s ( bulkhead.dStr, "%f", x ); // %d makes the result be a decimal integer
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 12) ui->messageBox(bulkhead.msg);
bulkhead.msg = " y = ";
bulkhead.msg += " ";
sprintf_s ( bulkhead.dStr, "%f", y ); // %d makes the result be a decimal integer
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 12) ui->messageBox(bulkhead.msg);
bulkhead.msg = " z = ";
bulkhead.msg += " ";
sprintf_s ( bulkhead.dStr, "%f", z ); // %d makes the result be a decimal integer
bulkhead.msg += bulkhead.dStr;
bulkhead.msg += " ";
if(Com.IDebug == 12) ui->messageBox(bulkhead.msg);
if(CurveType == "Line3D")
if(Com.IDebug == 11) ui->messageBox(" CurveType is SketchLine ");
else if(CurveType == "Arc3D")
if(Com.IDebug == 11) ui->messageBox(" CurveType is SketchArc ");
else
if(Com.IDebug == 11) ui->messageBox(" CurveType is None of the Above ");
fprintf(Com.out," \n\n In Construction Plane: J = %4d, M = %4d, CountObjectsColl = %4d, Item = %4d, x = %10.3e, y = %10.3e, z = %10.3e, xC[M] = %10.3e, yC[M] = %10.3e, zC[M] = %10.3e \n",
J, M, CountObjectsColl, Item, x, y, z, bulkhead.xC[J][M], bulkhead.yC[J][M], bulkhead.zC[J][M]);
}//M
bulkhead.Points[Ifr][IzBulk][0][0] = bulkhead.zC[0][1] + bulkhead.xC[0][1]; bulkhead.Points[Ifr][IzBulk][0][1] = bulkhead.yC[0][1]; bulkhead.Points[Ifr][IzBulk][0][2] = 0.0;
double dx1, dx11;
double dy1, dy11;
double dr1, dr11;
double Sign;
dx1 = bulkhead.xC[0][0] - bulkhead.xC[0][1];
dx11 = bulkhead.xC[0][2] - bulkhead.xC[0][1];
dy1 = bulkhead.yC[0][0] - bulkhead.yC[0][1];
dy11 = bulkhead.yC[0][2] - bulkhead.yC[0][1];
dr1 = sqrt(dx1 * dx1 + dy1 * dy1);
dr11 = sqrt(dx11 * dx11 + dy11 * dy11);
fprintf(Com.out,"\n dx1 = %10.3e , dy1 = %10.3e , dx11 = %10.3e , dy11 = %10.3e \n",
dx1, dy1, dx11, dy11);
if(JPhi <= 6) {Sign = 1.0;} else {Sign = - 1.0;}
bulkhead.Points[Ifr][IzBulk][1][0] = bulkhead.zC[0][0] + bulkhead.xC[0][1]; bulkhead.Points[Ifr][IzBulk][1][1] = bulkhead.yC[0][1] - Sign * dr1 * (cos(vtolmidbody.Phi[JPhi]) + sin(vtolmidbody.Phi[JPhi]) ); bulkhead.Points[Ifr][IzBulk][1][2] = 0.0;
bulkhead.Points[Ifr][IzBulk][11][0] = bulkhead.zC[0][2] + bulkhead.xC[0][1]; bulkhead.Points[Ifr][IzBulk][11][1] = bulkhead.yC[0][1] + Sign * dr11 * (cos(vtolmidbody.Phi[JPhi]) + sin(vtolmidbody.Phi[JPhi]) ) /* yC[0][2] - yC[0][1] */ ; bulkhead.Points[Ifr][IzBulk][1][2] = 0.0;
/* Avoid Almost a Straight Line and Hanging up in Drawing Arc3Pts */
if(abs(bulkhead.Points[Ifr][IzBulk][1][1] - bulkhead.Points[Ifr][IzBulk][0][1]) < 1.0e-3)
{//if
bulkhead.Points[Ifr][IzBulk][1][1] = bulkhead.Points[Ifr][IzBulk][1][1] - 1.0e-3;
bulkhead.Points[Ifr][IzBulk][11][1] = bulkhead.Points[Ifr][IzBulk][11][1] - 1.0e-3;
}//if
bulkhead.Points[Ifr][IzBulk][2][0] = bulkhead.Points[Ifr][IzBulk][1][0]; bulkhead.Points[Ifr][IzBulk][2][1] = bulkhead.Points[Ifr][IzBulk][1][1] - vtolmidbody.XSectnTh; bulkhead.Points[Ifr][IzBulk][2][2] = 0.0;
bulkhead.Points[Ifr][IzBulk][9][0] = bulkhead.Points[Ifr][IzBulk][0][0]; bulkhead.Points[Ifr][IzBulk][9][1] = bulkhead.Points[Ifr][IzBulk][0][1] - vtolmidbody.XSectnTh; bulkhead.Points[Ifr][IzBulk][9][2] = 0.0;
bulkhead.Points[Ifr][IzBulk][10][0] = bulkhead.Points[Ifr][IzBulk][11][0]; bulkhead.Points[Ifr][IzBulk][10][1] = bulkhead.Points[Ifr][IzBulk][11][1] - vtolmidbody.XSectnTh; bulkhead.Points[Ifr][IzBulk][2][2] = 0.0;
bulkhead.Points[Ifr][IzBulk][3][0] = bulkhead.Points[Ifr][IzBulk][9][0] - bulkhead.ISignX * vtolmidbody.XSectnTh; bulkhead.Points[Ifr][IzBulk][3][1] = bulkhead.Points[Ifr][IzBulk][9][1] /*- vtolmidbody.XSectnTh */; bulkhead.Points[Ifr][IzBulk][3][2] = 0.0;
bulkhead.Points[Ifr][IzBulk][12][0] = bulkhead.Points[Ifr][IzBulk][0][0]; bulkhead.Points[Ifr][IzBulk][12][1] = bulkhead.Points[Ifr][IzBulk][0][1] - vtolmidbody.XSectnTh; bulkhead.Points[Ifr][IzBulk][12][2] = 0.0;
/* if(JPhi == 6, the Three ArcPts are Almost in a Straight Line, and Fusion 360 is Either Hanging Up or Not Drwaing the Arc3Pts. So add a little Offset for the Mid Point of both Arcs */
if(JPhi == 6)
{//
bulkhead.Points[Ifr][IzBulk][0][0] = bulkhead.zC[0][1] + bulkhead.xC[0][1]; bulkhead.Points[Ifr][IzBulk][0][1] = bulkhead.yC[0][1] + 1.0e-4; bulkhead.Points[Ifr][IzBulk][0][2] = 0.0;
bulkhead.Points[Ifr][IzBulk][9][0] = bulkhead.Points[Ifr][IzBulk][0][0]; bulkhead.Points[Ifr][IzBulk][9][1] = bulkhead.Points[Ifr][IzBulk][0][1] - vtolmidbody.XSectnTh + 1.0e-4; bulkhead.Points[Ifr][IzBulk][9][2] = 0.0;
}//
if(Com.IDebug == 12) ui->messageBox(" After Points[Ifr][IzBulk][12][0] ");
//Debug
fprintf(Com.out," \n\n After Points[Ifr][IzBulk][12][0] \n");
return true;
}// end Arc3PtsByIntersectWithSurfaceCurve() ///
// End Arc3PtsByIntersectWithSurfaceCurve() //////////////////////////////////////////////////////////////////////////////////////////
I have attached the file.
Thanks Kris