Hi Goyals,
Here is the complete C++ Code which takes IntersectWithSurface() to the next level of determining the Curve 3D as item(0) in the Object Colloection, then Use IntersectWithCurve() to find the Intersection Points.
The following C++ code worked Okay.
Regards,
Thurai
///////////////////////////////////////////////////////////////////////////////////
#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>
using namespace adsk::core;
using namespace adsk::fusion;
using namespace adsk::cam;
using namespace std;
Ptr<Application> app;
Ptr<UserInterface> ui;
extern "C" XI_EXPORT bool run(const char* context)
{
Ptr<Application> app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
Ptr<Documents> docs = app->documents();
if (!docs)
return false;
// Create a document.
Ptr<Document> doc = docs->add(DocumentTypes::FusionDesignDocumentType);
if (!doc)
return false;
Ptr<Design> design = app->activeProduct();
if (!design)
return false;
Ptr<Component> rootComp = design->rootComponent();
if (!rootComp)
return false;
char dStr[16];
string msg;
// Create profile 1
Ptr<Sketches> sketches = rootComp->sketches();
if (!sketches)
return false;
Ptr<Sketch> sketch0 = sketches->add(rootComp->xYConstructionPlane());
if (!sketch0)
return false;
Ptr<SketchCurves> sketchCurves = sketch0->sketchCurves();
if (!sketchCurves)
return false;
Ptr<SketchLines> sketchLines = sketchCurves->sketchLines();
if (!sketchLines)
return false;
Ptr<SketchArcs> sketchArcs = sketchCurves->sketchArcs();
if (!sketchArcs)
return false;
Ptr<Point3D> Point00 = adsk::core::Point3D::create(5, -5, -10);
if (!Point00)
return false;
Ptr<Point3D> Point01 = adsk::core::Point3D::create(8, -5, 0);
if (!Point01)
return false;
Ptr<Point3D> Point02 = adsk::core::Point3D::create(5, -5, 10);
if (!Point02)
return false;
Ptr<SketchLine> Line00 = sketchLines->addByTwoPoints(Point00, Point01);
Ptr<SketchLine> Line01 = sketchLines->addByTwoPoints(Point01, Point02);
Ptr<SketchArc> arc0 = sketchArcs->addFillet(Line00, Line00->startSketchPoint()->geometry(), Line01, Line01->endSketchPoint()->geometry(), 5.0);
if (!arc0)
return false;
ui->messageBox("After Fillet arc0 ");
Ptr<Point3D> Point10 = adsk::core::Point3D::create(5, 5, -15);
if (!Point10)
return false;
Ptr<Point3D> Point11 = adsk::core::Point3D::create(10, 5, 0);
if (!Point11)
return false;
Ptr<Point3D> Point12 = adsk::core::Point3D::create(5, 5, 15);
if (!Point12)
return false;
Ptr<SketchLine> Line10 = sketchLines->addByTwoPoints(Point10, Point11);
Ptr<SketchLine> Line11 = sketchLines->addByTwoPoints(Point11, Point12);
Ptr<SketchArc> arc1 = sketchArcs->addFillet(Line10, Line10->startSketchPoint()->geometry(), Line11, Line11->endSketchPoint()->geometry(), 8.0);
if (!arc1)
return false;
ui->messageBox("After Fillet arc1 ");
// Create loft feature input
Ptr<Features> features = rootComp->features();
if (!features)
return false;
Ptr<LoftFeatures> loftFeatures = features->loftFeatures();
if (!loftFeatures)
return false;
ui->messageBox("After loftFeatures ");
Ptr <Path> OpenProfile0 = adsk::fusion::Path::create(Line00, connectedChainedCurves);
Ptr <Path> OpenProfile1 = adsk::fusion::Path::create(Line10, connectedChainedCurves);
ui->messageBox("After OpenProfile1 ");
Ptr<LoftFeatureInput> loftInput = loftFeatures->createInput(adsk::fusion::FeatureOperations::NewBodyFeatureOperation);
if (!loftInput)
return false;
Ptr<LoftSections> loftSections = loftInput->loftSections();
if (!loftSections)
return false;
Ptr<LoftSection> loftSection0 = loftSections->add(OpenProfile0);
if (!loftSection0)
return false;
ui->messageBox("After loftSection0");
Ptr<LoftSection> loftSection1 = loftSections->add(OpenProfile1);
if (!loftSection1)
return false;
ui->messageBox("After loftSection1");
loftInput->isSolid(true);
// Create loft feature
Ptr<LoftFeature> loftFeature = loftFeatures->add(loftInput);
if (!loftFeature)
return false;
ui->messageBox("After Loft");
// Fit to window
Ptr<Viewport> viewPort = app->activeViewport();
if(!viewPort)
return false;
Ptr<Camera> cam = viewPort->camera();
if(!cam)
return false;
cam->isFitView(true);
viewPort->camera(cam);
// Get the body created by the extrusion
Ptr<BRepBodies> bodies = loftFeature->bodies();
if (!bodies)
return false;
Ptr<BRepBody> body = bodies->item(0);
if (!body)
return false;
ui->messageBox("After body ");
Ptr<Vector3D> normal = adsk::core::Vector3D::create(0, 0, 1);
if(!normal)
return false;
Ptr<Plane> xyIntersectPlane = adsk::core::Plane::create(adsk::core::Point3D::create(0, 0, 2), normal);
if (!xyIntersectPlane)
return false;
Ptr<ObjectCollection> IntersectionObjColl = adsk::core::ObjectCollection::create();
if(!IntersectionObjColl)
return false;
ui->messageBox(" After IntersectionPtsObjColl ");
Ptr<BRepFaces> faces = body->faces();
ui->messageBox(" After faces ");
unsigned int faceCount = faces->count();
msg = " faceCount ";
sprintf_s (dStr, "%d", faceCount); // %d makes the result be a decimal integer
msg += dStr;
msg += " ";
ui->messageBox(msg);
// 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;
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;
ui->messageBox(" After surface[0] ");
IntersectionObjColl = xyIntersectPlane->intersectWithSurface(surface[0]);
if (!IntersectionObjColl)
// goto Face1;
return false;
ui->messageBox(" After intersectWithSurface() face 0 ");
unsigned int CountObjectsColl = IntersectionObjColl->count();
msg = " CountObjectsColl = ";
msg += " ";
sprintf_s (dStr, "%d", CountObjectsColl ); // %d makes the result be a decimal integer
msg += dStr;
msg += " ";
ui->messageBox(msg);
Ptr<Base> base = IntersectionObjColl->item(0);
msg = " base = ";
msg += " ";
sprintf_s (dStr, "%d", base );
msg += dStr;
msg += " ";
ui->messageBox(msg);
// Get the value of the property.
//string propertyValue = objectCollection_var->objectType();
string objectType = IntersectionObjColl->objectType();
msg = " objectType = ";
msg += " ";
sprintf_s (dStr, "%s", objectType );
msg += dStr;
msg += " ";
ui->messageBox(msg);
Ptr<Curve3D> curve3D = IntersectionObjColl->item(0);
if(!curve3D)
return false;
ui->messageBox(" After curve3D = IntersectionObjColl->item(0); ");
// Get the value of the property.
string CurveType = curve3D->objectType();
ui->messageBox(" After CurveType = sketchCurve->objectType(); ");
msg = " CurveType = ";
msg += " ";
sprintf_s (dStr, "%s", CurveType );
msg += dStr;
msg += " ";
ui->messageBox(msg);
/* Create an xz Plane with y Offset */
Ptr<Vector3D> normalxz = adsk::core::Vector3D::create(0, 1, 0);
if(!normalxz)
return false;
Ptr<Plane> xzPlane = adsk::core::Plane::create(adsk::core::Point3D::create(0, 2, 0), normalxz);
if (!xzPlane)
return false;
Ptr<Point3D> IntersectionPts[2];
/* Dummy Initialize */
IntersectionPts[0] = adsk::core::Point3D::create(0, 0, 0);
IntersectionPts[1] = adsk::core::Point3D::create(0, 0, 0);
Ptr<ObjectCollection> IntersectionPtsObjColl;
IntersectionPtsObjColl = adsk::core::ObjectCollection::create();
if(!IntersectionPtsObjColl)
return false;
IntersectionPtsObjColl = xzPlane->intersectWithCurve(curve3D);
if (!IntersectionPtsObjColl)
return false;
IntersectionPts[0] = IntersectionPtsObjColl->item(0);
ui->messageBox(" After IntersectionPts Line ");
double x, y, z;
x = IntersectionPts[0]->x();
y = IntersectionPts[0]->y();
z = IntersectionPts[0]->z();
msg = " x = ";
msg += " ";
sprintf_s ( dStr, "%f", x ); // %d makes the result be a decimal integer
msg += dStr;
msg += " ";
ui->messageBox(msg);
msg = " y = ";
msg += " ";
sprintf_s ( dStr, "%f", y ); // %d makes the result be a decimal integer
msg += dStr;
msg += " ";
ui->messageBox(msg);
msg = " z = ";
msg += " ";
sprintf_s ( dStr, "%f", z ); // %d makes the result be a decimal integer
msg += dStr;
msg += " ";
ui->messageBox(msg);
if(CurveType == "SketchLine")
ui->messageBox(" CurveType is SketchLine ");
else if(CurveType == "SketchArc")
ui->messageBox(" CurveType is SketchArc ");
if(CurveType == "Line3D")
ui->messageBox(" CurveType is SketchLine ");
else if(CurveType == "Arc3D")
ui->messageBox(" CurveType is SketchArc ");
else
ui->messageBox(" CurveType is None of the Above ");
return true;
}
#ifdef XI_WIN
#include <windows.h>
BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif // XI_WIN