main.cpp
#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>
#include "MainWindow.h"
using namespace adsk::core;
using namespace adsk::fusion;
using namespace adsk::cam;
Ptr<Application> app;
Ptr<UserInterface> ui;
Ptr<Sketch> sketch;
Ptr<Component> rootComp;
Ptr<Sketches> sketches;
static wxAppConsole *wxCreateApp()
{
wxAppConsole::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "my app");
return new Win(rootComp);
}
void RunApp()
{
wxApp::SetInitializerFunction(wxCreateApp);
wxEntry(0, NULL);
}
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();
rootComp = design->rootComponent();
sketches = rootComp->sketches();
sketch = sketches->add(rootComp->xYConstructionPlane());
RunApp();
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
MainWindow.h
#pragma once
#include <wx\wx.h>
#include <Fusion\FusionAll.h>
#include <Core\CoreAll.h>
using namespace adsk::fusion;
using namespace adsk::core;
class Win :public wxApp
{
wxFrame*window;
wxButton *button;
public:
Ptr<Component> rootComp;
Win(Ptr<Component> comp):rootComp(comp)
{
}
bool OnInit()
{
window = new wxFrame(nullptr, -1, "hi", wxPoint(100, 100), wxSize(840, 640));
window->Show();
button = new wxButton(window, -1, "create", wxPoint(100, 100), wxSize(100, 50));
button->Bind(wxEVT_BUTTON, &Win::func1, this);
return true;
}
void func1(wxCommandEvent&)
{
Ptr<Sketches> sketches = rootComp->sketches();
if (!sketches)
return ;
Ptr<ConstructionPlane> xyPlane = rootComp->xYConstructionPlane();
if (!xyPlane)
return ;
Ptr<Sketch> sketch = sketches->add(xyPlane);
if (!sketch)
return ;
// Draw a circle.
Ptr<SketchCurves> sketchCurves = sketch->sketchCurves();
if (!sketchCurves)
return ;
Ptr<SketchCircles> circles = sketchCurves->sketchCircles();
if (!circles)
return ;
Ptr<Point3D> centerPoint = Point3D::create(0, 0, 0);
if (!centerPoint)
return ;
Ptr<SketchCircle> circle1 = circles->addByCenterRadius(centerPoint, 2);
if (!circle1)
return ;
// Get the profile defined by the circle.
Ptr<Profiles> profs = sketch->profiles();
if (!profs)
return ;
Ptr<Profile> prof = profs->item(0);
if (!prof)
return ;
// Define that the extent is a distance extent of 5 cm.
Ptr<ValueInput> distance = ValueInput::createByReal(5);
if (!distance)
return ;
// Create the extrusion.
Ptr<Features> feats = rootComp->features();
if (!feats)
return ;
Ptr<ExtrudeFeatures> extrudes = feats->extrudeFeatures();
if (!extrudes)
return ;
Ptr<ExtrudeFeature> ext = extrudes->addSimple(prof, distance, FeatureOperations::NewComponentFeatureOperation);
if (!ext)
return ;
}
};
When I spin object sketch freezing