I didn't know how familiar you already were with using transformation matrices. They're a general method of defining a transform and certainly not unique to Fusion 360 or Autodesk. Admittedly though if you haven't encountered them in the past they do take quite a bit to get a grasp of. Here's a simpler program that demonstrates moving an occurrence. It has two modes depending on if the "if" statement is set to true or false. In the first case, it moves the occurrence to a specific location and in the second it applies a delta move from the current location of the occurrence. I didn't need a doEvents to see the result. I suspect that's because your program is still doing something and has the main thread occupied so Fusion doesn't have a chance to update the screen.
#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>
using namespace adsk::core;
using namespace adsk::fusion;
using namespace adsk::cam;
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;
// Have an occurrence selected.
Ptr<Selection> occSel = ui->selectEntity("Select an occurrence.", "Occurrences");
Ptr<Occurrence> occ = occSel->entity();
Ptr<Matrix3D> trans = occ->transform();
if (true)
{
// Define the coordinate of the new position of the occurrence.
Ptr<Point3D> newPosition = adsk::core::Point3D::create(5, 10, 3);
trans->setCell(0, 3, newPosition->x());
trans->setCell(1, 3, newPosition->y());
trans->setCell(2, 3, newPosition->z());
}
else
{
// Define the delta coordinates to move the occurrence.
Ptr<Vector3D> delta = adsk::core::Vector3D::create(5, 1, 1);
trans->setCell(0, 3, trans->getCell(0, 3) + delta->x());
trans->setCell(1, 3, trans->getCell(1, 3) + delta->y());
trans->setCell(2, 3, trans->getCell(2, 3) + delta->z());
}
occ->transform(trans);
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
---------------------------------------------------------------
Brian EkinsInventor and Fusion 360 API Expert
Website/Blog:
https://EkinsSolutions.com