- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
RevolveFeature API Does Not Work, But Works in UI
Hi,
the following API using C++ Does Not Work.
But it works fine in UI with pull down Menu.
How can I make it work?
Thurai
//////////////////////////////////////////////////////////////
#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>
#include <time.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;
Ptr<Sketches> sketches = rootComp->sketches();
if (!sketches)
return false;
Ptr<ConstructionPlane> xyPlane;
xyPlane = rootComp->xYConstructionPlane();
if (!xyPlane)
return false;
Ptr<Sketch> sketch = sketches->add(xyPlane);
if (!sketch)
return false;
Ptr<SketchCurves> sketchCurves;
sketchCurves = sketch->sketchCurves();
if (!sketchCurves)
return false;
Ptr<SketchLines> sketchLines = sketchCurves->sketchLines();
if (!sketchLines)
return false;
char dStr[16];
string msg;
ui->messageBox(" After sketchLines ");
Ptr<Point3D> Pts[2][2];
// Add Lines
Ptr<SketchLine> SkinLines[4];
Pts[0][0] = Point3D::create(0.0, 48, 0);
Pts[0][1] = Point3D::create(0.0, 50, 0);
Pts[1][0] = Point3D::create(0.0, 48, 10);
Pts[1][1] = Point3D::create(0.0, 50, 10);
SkinLines[0] = sketchLines->addByTwoPoints(Pts[0][0], Pts[0][1]);
SkinLines[1] = sketchLines->addByTwoPoints(Pts[0][1], Pts[1][1]);
SkinLines[2] = sketchLines->addByTwoPoints(Pts[1][1], Pts[1][0]);
SkinLines[3] = sketchLines->addByTwoPoints(Pts[1][0], Pts[0][0]);
ui->messageBox(" After SkinLines ");
Ptr<Features> features = rootComp->features();
if (!features)
return false;
Ptr<RevolveFeatures> revolveFeatures = features ->revolveFeatures();
if (!revolveFeatures)
return false;
Ptr<Profiles> profiles;
Ptr<Profile> profile[3];
profiles = sketch->profiles();
if (!profiles)
return false;
profile[0] = profiles->item(0);
if (!profile[0])
return false;
ui->messageBox(" profile[0] Created ");
double Pi = 4.0 * atan(1.0);
double Angle = 0.25 * Pi;
Ptr<ValueInput> RevolveAngle = ValueInput::createByReal(Angle);
/* RevolveFeature */
Ptr< RevolveFeature> revolveFeature[3];
ui->messageBox("AfterrevolveFeatures ");
Ptr<Point3D> RevolveAxisPts[2];
RevolveAxisPts[0] = Point3D::create(0.0, 0.0, 0.0);
RevolveAxisPts[1] = Point3D::create(0.0, 0.0, 10.0);
Ptr<SketchLine> RevolveAxis = sketchLines->addByTwoPoints(RevolveAxisPts[0], RevolveAxisPts[1]);
if (!RevolveAxis)
return false;
ui->messageBox(" After RevolveAxis ");
// 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);
Ptr<RevolveFeatureInput> revolveFeatureInput[3];
revolveFeatureInput[0] = revolveFeatures->createInput(profile[0], RevolveAxis, adsk::fusion::FeatureOperations::NewBodyFeatureOperation);
if (!revolveFeatureInput[0])
return false;
ui->messageBox("After Create revolveFeatureInput[0] ");
revolveFeatureInput[0]->isSolid(true);
bool RetValue = revolveFeatureInput[0]->setAngleExtent(true, RevolveAngle);
if (!RetValue)
return false;
ui->messageBox(" After revolveFeatureInput[0] setAngleExtent ");
revolveFeature[0] = revolveFeatures->add(revolveFeatureInput[0]);
if (!revolveFeature[0])
return false;
ui->messageBox(" After revolveFeature[0] ");
//Debug Revolve
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
Solved! Go to Solution.