Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi.
Can somebody provide me a sample code which combine solid bodies in Fusion 360?
Solved! Go to Solution.
Hi.
Can somebody provide me a sample code which combine solid bodies in Fusion 360?
Solved! Go to Solution.
Hi,
I wrote the C++ sample as below. Make sure there are at least two bodies under the root component before you run the script.
#include <Core/Application/Application.h> #include <Core/Application/ObjectCollection.h> #include <Fusion/Fusion/Design.h> #include <Fusion/Components/Component.h> #include <Fusion/BRep/BRepBodies.h> #include <Fusion/BRep/BRepBody.h> #include <Fusion/Features/Features.h> #include <Fusion/Features/CombineFeatures.h> #include <Fusion/Features/CombineFeatureInput.h> using namespace adsk::core; using namespace adsk::fusion; 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<Design> design = app->activeProduct(); if (!design) return false; // Get the root component of the active design Ptr<Component> root = design->rootComponent(); if (!root) return false; Ptr<BRepBodies> bodies = root->bRepBodies(); if (!bodies) return false; Ptr<BRepBody> targetBody = bodies->item(0); if (!targetBody) return false; Ptr<BRepBody> toolBody = bodies->item(1); if (!toolBody) return false; Ptr<ObjectCollection> toolBodies = ObjectCollection::create(); if (!toolBodies) return false; toolBodies->add(toolBody); Ptr<Features> feats = root->features(); if (!feats) return false; Ptr<CombineFeatures> combines = feats->combineFeatures(); if (!combines) return false; Ptr<CombineFeatureInput> combineInput = combines->createInput(targetBody, toolBodies); if (!combineInput) return false; Ptr<CombineFeature> combine = combines->add(combineInput); 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
Regards,
Jack
Does Fusion API provides feature to get all selected bodies and then make some operations with that objects (Something like SelectionSet in AutoCad .net api)? I mean, that I want combine more than two objects in one function.
Yes, it's able to get all selections through UserInterface.activeSelections. For example:
Ptr<Application> app = Application::get(); if (!app) return false; ui = app->userInterface(); if (!ui) return false; Ptr<Selections> sels = ui->activeSelections(); if (!sels) return false; for (Ptr<Selection> sel : sels) { Ptr<BRepBody> body = sel->entity(); if (body) { } }
Regards,
Jack