Message 1 of 9

Not applicable
03-30-2020
12:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi There,
I have successfully drawn a few points using custom graphics in the Fusion API. I would like to draw a point cloud from a .xyz file. Please see my coordinates file and code below.
The process gets hung up on line:
Ptr<CustomGraphicsPointSet> points = graphicGroup->addPointSet(ChairPointCloud, indexList, PointCloudCustomGraphicsPointType, "hello");
Please let me know what I am doing wrong here.
Sincerely,
Sam
1.973145 1.959534 0.909668
1.973346 1.964355 0.909668
1.973145 1.964355 0.909034
1.973145 1.944539 0.918457
1.975196 1.946777 0.918457
1.973145 1.946777 0.914897
1.976019 1.955566 0.918457
1.973145 1.955566 0.910203
2.474121 1.964355 0.916655
// Drawing Custom Graphics Points
// Reading point from a file
// Samuel Melamed, 27.03.2020
#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
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)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
ui->messageBox("Drawing Custom Graphics Points");
// Create a document, activate design space, and set root component
Ptr<Documents> docs = app->documents(); // ...
if (!docs)
return false;
ui->messageBox("added docs");
Ptr<Document> doc = docs->add(DocumentTypes::FusionDesignDocumentType); // ...
if (!doc)
return false;
ui->messageBox("added doc");
Ptr<Design> design = app->activeProduct(); // ...
if (!design)
return false;
ui->messageBox("added design");
Ptr<Component> rootComp = design->rootComponent(); // ...
if (!rootComp)
return false;
ui->messageBox("added root component");
Ptr<CustomGraphicsGroups> graphicGroups = rootComp->customGraphicsGroups();
if (!graphicGroups)
return false;
ui->messageBox("added graphicsGroups");
Ptr<CustomGraphicsGroup> graphicGroup = graphicGroups->add();
if (!graphicGroup)
return false;
ui->messageBox("added graphicsGroup");
// Reading from a file and storing in coordinate vector
// Begin
std::ifstream myFile ("06976.xyz");
ui->messageBox("read file ok");
std::string CoordinatesString; //
std::vector <double> CoordinateList; //
ui->messageBox("string and vector ok!");
while (std::getline(myFile, CoordinatesString))
{
//std::cout << CoordinatesString << std::endl;
int step = 0;
// extract coordinate numbers from string
for (int c = 0; c < 2; c++)
{
std::string TempString = CoordinatesString.substr(step, 8);
double TempNumber = std::stod(TempString);
CoordinateList.push_back(TempNumber);
step = step + 9;
}
}
myFile.close();
ui->messageBox("closed file ok!");
// End
//std::vector<double> myCoordinates = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
Ptr<CustomGraphicsCoordinates> ChairPointCloud = CustomGraphicsCoordinates::create(CoordinateList);
if (!ChairPointCloud)
return false;
ui->messageBox("added Coordinates");
std::vector<int> indexList;
// Displaying point cloud points
Ptr<CustomGraphicsPointSet> points = graphicGroup->addPointSet(ChairPointCloud, indexList, PointCloudCustomGraphicsPointType, "hello");
if (!points)
return false;
ui->messageBox("added pointset");
return true;
}
extern "C" XI_EXPORT bool stop(const char* context)
{
if (ui)
{
ui->messageBox("Stop addin");
ui = nullptr;
}
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.