Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Loft with openprofile using C++ does not work

tperam
Advocate

Loft with openprofile using C++ does not work

tperam
Advocate
Advocate

Loft with openprofile using C++  with the following code does not work.

 

Please correct it, try it in your PC and let me know.

 

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;
 // Create profile 1
 Ptr<Sketches> sketches = rootComp->sketches();
 if (!sketches)
  return false;
 Ptr<Sketch> sketch0 = sketches->add(rootComp->yZConstructionPlane());
 if (!sketch0)
  return false;
 
 Ptr<SketchCurves> sketchCurves = sketch0->sketchCurves();
 if (!sketchCurves)
  return false;
 Ptr<SketchLines> sketchLines = sketchCurves->sketchLines();
 if (!sketchLines)
  return false;

 Ptr<Point3D> Point00 = adsk::core::Point3D::create(0, 0, 0);
 if (!Point00)
  return false;
 Ptr<Point3D> Point01 = adsk::core::Point3D::create(0, 0, 10);
 if (!Point01)
  return false;

 Ptr<Point3D> Point10 = adsk::core::Point3D::create(0, 10, 0);
 if (!Point10)
  return false;

 Ptr<Point3D> Point11 = adsk::core::Point3D::create(0, 10, 20);
 if (!Point11)
  return false;
 Ptr<SketchLine> Line0 = sketchLines->addByTwoPoints(Point00, Point01);
 Ptr<SketchLine> Line1 = sketchLines->addByTwoPoints(Point10, Point11);
 
 Ptr<Profiles> profiles = sketch0->profiles();
 if (!profiles)
  return false;

  Ptr<Profile> profile0 = rootComp->createOpenProfile(Line0);
  if (!profile0)
  return false;
    
  ui->messageBox("After profile0");
  Ptr<Profile> profile1 = rootComp->createOpenProfile(Line1);
  if (!profile1)
  return false;
    
  ui->messageBox("After profile1");
 
 // Create loft feature input
 Ptr<Features> feats = rootComp->features();
 if (!feats)
  return false;
 Ptr<LoftFeatures> loftFeats = feats->loftFeatures();
 if (!loftFeats)
  return false;
 Ptr<LoftFeatureInput> loftInput = loftFeats->createInput(adsk::fusion::FeatureOperations::NewBodyFeatureOperation);
 if (!loftInput)
  return false;
 Ptr<LoftSections> loftSectionsObj = loftInput->loftSections();
 if (!loftSectionsObj)
  return false;
 Ptr<LoftSection> loftSection0 = loftSectionsObj->add(profile0);
 if (!loftSection0)
  return false;
 Ptr<LoftSection> loftSection1 = loftSectionsObj->add(profile1);
 if (!loftSection1)
  return false;

 loftInput->isSolid(false);
 // Create loft feature
 Ptr<LoftFeature> loftFeature = loftFeats->add(loftInput);
 if (!loftFeature)
  return false;

 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
 

 

 

0 Likes
Reply
Accepted solutions (1)
433 Views
2 Replies
Replies (2)

tperam
Advocate
Advocate

Here is the C++ file as an attachment as a text file.

 

Regards,

Thurai

0 Likes

tperam
Advocate
Advocate
Accepted solution

Following Code Worked Okay:

 

#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;
 // 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<Point3D> Point00 = adsk::core::Point3D::create(0, 0, 0);
 if (!Point00)
  return false;
 Ptr<Point3D> Point01 = adsk::core::Point3D::create(0, 0, 10);
 if (!Point01)
  return false;

 Ptr<Point3D> Point10 = adsk::core::Point3D::create(0, 10, 5);
 if (!Point10)
  return false;

 Ptr<Point3D> Point11 = adsk::core::Point3D::create(0, 10, 20);
 if (!Point11)
  return false;

 Ptr<Point3D> Point02 = adsk::core::Point3D::create(0, 15, 5);
 if (!Point02)
  return false;
 Ptr<Point3D> Point12 = adsk::core::Point3D::create(0, 20, 15);
 if (!Point02)
  return false;
 
 Ptr<SketchLine> Line0 = sketchLines->addByTwoPoints(Point00, Point01);
 Ptr<SketchLine> Line1 = sketchLines->addByTwoPoints(Point10, Point11);

 // Create loft feature input
 Ptr<Features> feats = rootComp->features();
 if (!feats)
  return false;
 Ptr<LoftFeatures> loftFeats = feats->loftFeatures();
 if (!loftFeats)
  return false;

 Ptr <Path> OpenProfile0 = adsk::fusion::Path::create(Line0, noChainedCurves);
 Ptr <Path> OpenProfile1 = adsk::fusion::Path::create(Line1, noChainedCurves);

 Ptr<LoftFeatureInput> loftInput = loftFeats->createInput(adsk::fusion::FeatureOperations::NewBodyFeatureOperation);
 if (!loftInput)
  return false;
 Ptr<LoftSections> loftSectionsObj = loftInput->loftSections();
 if (!loftSectionsObj)
  return false;
 Ptr<LoftSection> loftSection0 = loftSectionsObj->add(OpenProfile0);
 if (!loftSection0)
  return false;
 ui->messageBox("After loftSection0");
 Ptr<LoftSection> loftSection1 = loftSectionsObj->add(OpenProfile1);
 if (!loftSection1)
  return false;
 ui->messageBox("After loftSection1");
 loftInput->isSolid(true);
 
 // Create loft feature
 Ptr<LoftFeature> loftFeature = loftFeats->add(loftInput);
 if (!loftFeature)
  return false;
  ui->messageBox("After Loft");
 return true;
}
0 Likes